Skip to content

Commit

Permalink
bump version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
phn210 committed Oct 1, 2024
1 parent e69ee1d commit 3a7e545
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 31 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auxo-dev/auxo-libs",
"version": "0.6.3",
"version": "1.0.0",
"description": "",
"author": "",
"license": "Apache-2.0",
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ type ZkAppOptions = {

type UtilsOptions = {
cache?: Cache;
forceRecompile?: boolean;
proofsEnabled?: boolean;
profiler?: Profiler;
logger?: Logger;
};
38 changes: 22 additions & 16 deletions src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -163,16 +170,15 @@ async function prove<T>(
proofGeneration: () => Promise<T>,
options: UtilsOptions = {}
): Promise<T> {
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;
}

Expand Down
56 changes: 44 additions & 12 deletions src/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
State,
TokenId,
UInt64,
Void,
ZkProgram,
method,
state,
} from 'o1js';
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -122,25 +136,43 @@ 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(
new Set(accountNames).size
);
});

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(
[
{
Expand All @@ -154,7 +186,7 @@ describe('Network', () => {
);
});

it('should prove', async () => {
it('Should prove', async () => {
await prove(
TestContract.name,
'test',
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -209,20 +241,20 @@ describe('Network', () => {
);
});

it('should fetch actions', async () => {
it('Should fetch actions', async () => {
let actions = await fetchActions(
testZkApp1.key.publicKey,
Reducer.initialActionState
);
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);
});
Expand Down

0 comments on commit 3a7e545

Please sign in to comment.