diff --git a/package-lock.json b/package-lock.json index 86e8ea9..4963f33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@auxo-dev/auxo-libs", - "version": "0.6.3", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@auxo-dev/auxo-libs", - "version": "0.6.3", + "version": "1.0.0", "license": "Apache-2.0", "dependencies": { "o1js": "1.8.0" diff --git a/package.json b/package.json index a0d3f01..9e00c7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@auxo-dev/auxo-libs", - "version": "0.6.3", + "version": "1.0.0", "description": "", "author": "", "license": "Apache-2.0", diff --git a/src/utils/constants.ts b/src/utils/constants.ts index f3b773e..68ae1fb 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -140,6 +140,8 @@ type ZkAppOptions = { type UtilsOptions = { cache?: Cache; + forceRecompile?: boolean; + proofsEnabled?: boolean; profiler?: Profiler; logger?: Logger; }; diff --git a/src/utils/network.ts b/src/utils/network.ts index 601ab92..44fa6af 100644 --- a/src/utils/network.ts +++ b/src/utils/network.ts @@ -117,16 +117,23 @@ async function compile( verificationKey: { data: string; hash: Field }; }> { let result; - if (options.logger && options.logger.memoryUsage) + let { cache, forceRecompile, proofsEnabled, profiler, logger } = options; + if (logger && logger.memoryUsage) console.log('Current memory usage:', getMemoryUsage(), 'MB'); - if (options.logger && options.logger.info) - console.log(`Compiling ${program.name}...`); - if (options.profiler) options.profiler.start(`${program.name}.compile`); - if (options.cache) result = await program.compile({ cache: options.cache }); - else result = await program.compile(); - if (options.profiler) options.profiler.stop(); - if (options.logger && options.logger.info) console.log('Compiling done!'); - if (options.logger && options.logger.memoryUsage) + if (logger && logger.info) console.log(`Compiling ${program.name}...`); + if (profiler) profiler.start(`${program.name}.compile`); + if (proofsEnabled) + result = await program.compile({ + cache, + forceRecompile, + proofsEnabled, + }); + else { + result = await program.compile({ cache, forceRecompile }); + } + if (profiler) profiler.stop(); + if (logger && logger.info) console.log('Compiling done!'); + if (logger && logger.memoryUsage) console.log('Current memory usage:', getMemoryUsage(), 'MB'); return result; } @@ -163,16 +170,15 @@ async function prove( proofGeneration: () => Promise, options: UtilsOptions = {} ): Promise { - if (options.logger && options.logger.memoryUsage) + let { profiler, logger } = options; + if (logger && logger.memoryUsage) console.log('Current memory usage:', getMemoryUsage(), 'MB'); - if (options.logger && options.logger.info) + if (logger && logger.info) console.log(`Generating proof for ${programName}.${methodName}()...`); - if (options.profiler) - options.profiler.start(`${programName}.${methodName}`); + if (profiler) profiler.start(`${programName}.${methodName}`); let result = await proofGeneration(); - if (options.profiler) options.profiler.stop(); - if (options.logger && options.logger.info) - console.log('Generating proof done!'); + if (profiler) profiler.stop(); + if (logger && logger.info) console.log('Generating proof done!'); return result; } diff --git a/src/utils/utils.test.ts b/src/utils/utils.test.ts index f6f865c..585a56f 100644 --- a/src/utils/utils.test.ts +++ b/src/utils/utils.test.ts @@ -9,6 +9,8 @@ import { State, TokenId, UInt64, + Void, + ZkProgram, method, state, } from 'o1js'; @@ -67,6 +69,18 @@ describe('Network', () => { } } + const TestProgram = ZkProgram({ + name: 'TestProgram', + methods: { + dummy: { + privateInputs: [], + async method() { + return; + }, + }, + }, + }); + const doProofs = true; const cache = Cache.FileSystem('caches'); const logger = { @@ -122,7 +136,7 @@ describe('Network', () => { ); }); - it('should generate random accounts', async () => { + it('Should generate random accounts', async () => { const accountNames = ['test1', 'test2', 'test1']; const accounts = randomAccounts(accountNames); expect(Object.entries(accounts).length).toEqual( @@ -130,17 +144,35 @@ describe('Network', () => { ); }); - it('should compile contract', async () => { - if (doProofs) await compile(TestContract, { cache, profiler, logger }); + it('Should compile', async () => { + await compile(TestProgram, { + cache, + profiler, + logger, + proofsEnabled: false, + }); + if (doProofs) + await compile(TestContract, { + cache, + profiler, + logger, + proofsEnabled: undefined, + }); + await compile(TestProgram, { + cache, + profiler, + logger, + proofsEnabled: true, + }); }); - it('should deploy zkApp', async () => { + it('Should deploy zkApp', async () => { await deployZkApps([testZkApp1, testZkApp2], feePayer, true, { logger, }); }); - it('should deploy zkApp with token', async () => { + it('Should deploy zkApp with token', async () => { await deployZkAppsWithToken( [ { @@ -154,7 +186,7 @@ describe('Network', () => { ); }); - it('should prove', async () => { + it('Should prove', async () => { await prove( TestContract.name, 'test', @@ -164,7 +196,7 @@ describe('Network', () => { ); }); - it('should send tx', async () => { + it('Should send tx', async () => { let tx = await Mina.transaction( { sender: feePayer.sender.publicKey, @@ -179,7 +211,7 @@ describe('Network', () => { await sendTx(tx.sign([feePayer.sender.privateKey]), true, { logger }); }); - it('should fail to send tx', async () => { + it('Should fail to send tx', async () => { let tx = await Mina.transaction( { sender: feePayer.sender.publicKey, @@ -194,7 +226,7 @@ describe('Network', () => { expect(sendTx(tx, true)).rejects.toThrow(); }); - it('should prove and send tx', async () => { + it('Should prove and send tx', async () => { await proveAndSendTx( TestContract.name, 'test', @@ -209,7 +241,7 @@ describe('Network', () => { ); }); - it('should fetch actions', async () => { + it('Should fetch actions', async () => { let actions = await fetchActions( testZkApp1.key.publicKey, Reducer.initialActionState @@ -217,12 +249,12 @@ describe('Network', () => { expect(actions.length).toBeGreaterThan(0); }); - it('should fetch events', async () => { + it('Should fetch events', async () => { let events = await fetchEvents(testZkApp1.key.publicKey); expect(events.length).toBeGreaterThan(0); }); - it('should fetch state', async () => { + it('Should fetch state', async () => { let state = await fetchZkAppState(testZkApp1.key.publicKey); expect(state.length).toEqual(8); });