Skip to content

Commit

Permalink
fix: reversed events
Browse files Browse the repository at this point in the history
  • Loading branch information
phn210 committed Oct 11, 2024
1 parent 3c6b56a commit 0fe7ea6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 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": "1.0.3",
"version": "1.0.4",
"description": "",
"author": "",
"license": "Apache-2.0",
Expand Down
4 changes: 1 addition & 3 deletions src/IpfsHash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down
35 changes: 34 additions & 1 deletion src/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/zkApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 0fe7ea6

Please sign in to comment.