diff --git a/package-lock.json b/package-lock.json index 9933618..7403a5e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@auxo-dev/auxo-libs", - "version": "1.0.3", + "version": "1.0.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@auxo-dev/auxo-libs", - "version": "1.0.3", + "version": "1.0.4", "license": "Apache-2.0", "dependencies": { "o1js": "1.8.0" diff --git a/package.json b/package.json index 143cd58..8906c56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@auxo-dev/auxo-libs", - "version": "1.0.3", + "version": "1.0.4", "description": "", "author": "", "license": "Apache-2.0", diff --git a/src/IpfsHash.test.ts b/src/IpfsHash.test.ts index 0410b66..ec9e345 100644 --- a/src/IpfsHash.test.ts +++ b/src/IpfsHash.test.ts @@ -5,9 +5,7 @@ describe('IpfsHash', () => { it('Should be provable code', async () => { Provable.runAndCheck(() => { let ipfsHash = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'; - let encodedData = Provable.witness(IpfsHash, () => { - return IpfsHash.fromString(ipfsHash); - }); + return IpfsHash.fromString(ipfsHash); }); }); diff --git a/src/utils/utils.test.ts b/src/utils/utils.test.ts index 067245d..552f54a 100644 --- a/src/utils/utils.test.ts +++ b/src/utils/utils.test.ts @@ -31,7 +31,7 @@ import { import { FeePayer, TX_FEE, ZkApp } from './constants.js'; import { getProfiler } from './benchmark.js'; import { fromUInt64ToScalar } from './math.js'; -import { checkInvalidAction } from './zkApp.js'; +import { checkInvalidAction, updateActionState } from './zkApp.js'; describe('Math', () => { it('Should convert UInt64 to Scalar', async () => { @@ -79,6 +79,12 @@ describe('Network', () => { ); Provable.log(flag); } + + @method + async multipleActions(action1: Field, action2: Field) { + this.reducer.dispatch(action1); + this.reducer.dispatch(action2); + } } const TestProgram = ZkProgram({ @@ -271,6 +277,33 @@ describe('Network', () => { ); }); + it('Should calculate correct hash', async () => { + let currentActionState = testZkApp1.contract.account.actionState.get(); + let tx = await Mina.transaction( + { + sender: feePayer.sender.publicKey, + fee: feePayer.fee || TX_FEE, + memo: feePayer.memo, + nonce: feePayer.nonce, + }, + async () => + (testZkApp1.contract as TestContract).multipleActions( + Field(1), + Field(2) + ) + ); + await tx.prove(); + await sendTx(tx.sign([feePayer.sender.privateKey]), true, { logger }); + let newActionState = testZkApp1.contract.account.actionState.get(); + // let actionsHash = updateActionState(currentActionState, [[Field(1)]]); + // actionsHash = updateActionState(actionsHash, [[Field(2)]]); + let actionsHash = updateActionState(currentActionState, [ + [Field(1)], + [Field(2)], + ]); + expect(newActionState).toEqual(actionsHash); + }); + it('Should fetch actions', async () => { let actions = await fetchActions( testZkApp1.key.publicKey, diff --git a/src/utils/zkApp.ts b/src/utils/zkApp.ts index 0b6556f..f174589 100644 --- a/src/utils/zkApp.ts +++ b/src/utils/zkApp.ts @@ -21,7 +21,7 @@ export { }; function updateActionState(state: Field, action: Field[][]) { - let actionsHash = AccountUpdate.Actions.hash(action); + let actionsHash = AccountUpdate.Actions.hash(action.reverse()); return AccountUpdate.Actions.updateSequenceState(state, actionsHash); }