Skip to content

Commit

Permalink
fail the job if tests fail
Browse files Browse the repository at this point in the history
  • Loading branch information
45930 committed Nov 20, 2024
1 parent 86d9590 commit 0c4add3
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 180 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ jobs:
polling-interval-ms: 10000

- name: Run tests
run: |
npm run test
run: npm run test
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ npm run build
# find all unit tests in build and run them
for f in ./build/**/*test.js; do
echo "Running $f"
node --enable-source-maps --stack-trace-limit=1000 $f;
node --enable-source-maps --stack-trace-limit=1000 --test $f;
done
355 changes: 178 additions & 177 deletions tests/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,200 +141,201 @@ describe('Query Resolvers', async () => {
},
document: parse(`${eventsQuery}`),
});
assert.strictEqual(4, 5);
assert.strictEqual(results.data.events.length, 0);
});

test('Emitting an event with single field should return a single event with the correct data', async () => {
await emitSingleEvent(zkApp, senderKeypair);
const results = await executor({
variables: {
input: {
address: zkAppKeypair.publicKey.toBase58(),
},
},
document: parse(`${eventsQuery}`),
});
// test('Emitting an event with single field should return a single event with the correct data', async () => {
// await emitSingleEvent(zkApp, senderKeypair);
// const results = await executor({
// variables: {
// input: {
// address: zkAppKeypair.publicKey.toBase58(),
// },
// },
// document: parse(`${eventsQuery}`),
// });

const events = results.data.events;
const lastEvent = events[events.length - 1];
assert.strictEqual(lastEvent.eventData.length, 1);
});
// const events = results.data.events;
// const lastEvent = events[events.length - 1];
// assert.strictEqual(lastEvent.eventData.length, 1);
// });

test('Emitting multiple events with a single field should return multiple events with the correct data', async () => {
await emitSingleEvent(zkApp, senderKeypair, { numberOfEmits: 3 });
const results = await executor({
variables: {
input: {
address: zkAppKeypair.publicKey.toBase58(),
},
},
document: parse(`${eventsQuery}`),
});
const events = results.data.events;
const lastEvent = events[events.length - 1];
assert.strictEqual(lastEvent.eventData.length, 3);
});
// test('Emitting multiple events with a single field should return multiple events with the correct data', async () => {
// await emitSingleEvent(zkApp, senderKeypair, { numberOfEmits: 3 });
// const results = await executor({
// variables: {
// input: {
// address: zkAppKeypair.publicKey.toBase58(),
// },
// },
// document: parse(`${eventsQuery}`),
// });
// const events = results.data.events;
// const lastEvent = events[events.length - 1];
// assert.strictEqual(lastEvent.eventData.length, 3);
// });

test('Emitting an event with multiple fields should return an event with multiple values', async () => {
await emitMultipleFieldsEvent(zkApp, senderKeypair);
const results = await executor({
variables: {
input: {
address: zkAppKeypair.publicKey.toBase58(),
},
},
document: parse(`${eventsQuery}`),
});
const events = results.data.events;
const lastEvent = events[events.length - 1];
assert.strictEqual(lastEvent.eventData.length, 1);
});
// test('Emitting an event with multiple fields should return an event with multiple values', async () => {
// await emitMultipleFieldsEvent(zkApp, senderKeypair);
// const results = await executor({
// variables: {
// input: {
// address: zkAppKeypair.publicKey.toBase58(),
// },
// },
// document: parse(`${eventsQuery}`),
// });
// const events = results.data.events;
// const lastEvent = events[events.length - 1];
// assert.strictEqual(lastEvent.eventData.length, 1);
// });

test('Emitting multiple events with multiple fields should return multiple events with the correct data', async () => {
await emitMultipleFieldsEvent(zkApp, senderKeypair, { numberOfEmits: 3 });
const results = await executor({
variables: {
input: {
address: zkAppKeypair.publicKey.toBase58(),
},
},
document: parse(`${eventsQuery}`),
});
const events = results.data.events;
const lastEvent = events[events.length - 1];
assert.strictEqual(lastEvent.eventData.length, 3);
});
// test('Emitting multiple events with multiple fields should return multiple events with the correct data', async () => {
// await emitMultipleFieldsEvent(zkApp, senderKeypair, { numberOfEmits: 3 });
// const results = await executor({
// variables: {
// input: {
// address: zkAppKeypair.publicKey.toBase58(),
// },
// },
// document: parse(`${eventsQuery}`),
// });
// const events = results.data.events;
// const lastEvent = events[events.length - 1];
// assert.strictEqual(lastEvent.eventData.length, 3);
// });
});

describe('Actions', async () => {
test('Fetching actions with a valid address should not throw', async () => {
assert.doesNotThrow(async () => {
await executor({
variables: {
input: {
address: zkAppKeypair.publicKey.toBase58(),
},
},
document: parse(`${actionsQuery}`),
});
});
});
// describe('Actions', async () => {
// test('Fetching actions with a valid address should not throw', async () => {
// assert.doesNotThrow(async () => {
// await executor({
// variables: {
// input: {
// address: zkAppKeypair.publicKey.toBase58(),
// },
// },
// document: parse(`${actionsQuery}`),
// });
// });
// });

test('Fetching actions with a empty address should return empty list', async () => {
const results = await executor({
variables: {
input: {
address: '',
},
},
document: parse(`${actionsQuery}`),
});
assert.strictEqual(results.data.actions.length, 0);
});
// test('Fetching actions with a empty address should return empty list', async () => {
// const results = await executor({
// variables: {
// input: {
// address: '',
// },
// },
// document: parse(`${actionsQuery}`),
// });
// assert.strictEqual(results.data.actions.length, 0);
// });

test('Emitting an action should return a single action with the correct data', async () => {
await emitAction(zkApp, senderKeypair);
const results = await executor({
variables: {
input: {
address: zkAppKeypair.publicKey.toBase58(),
},
},
document: parse(`${actionsQuery}`),
});
const actions = results.data.actions;
const lastAction = actions[actions.length - 1];
assert.strictEqual(lastAction.actionData.length, 1);
});
// test('Emitting an action should return a single action with the correct data', async () => {
// await emitAction(zkApp, senderKeypair);
// const results = await executor({
// variables: {
// input: {
// address: zkAppKeypair.publicKey.toBase58(),
// },
// },
// document: parse(`${actionsQuery}`),
// });
// const actions = results.data.actions;
// const lastAction = actions[actions.length - 1];
// assert.strictEqual(lastAction.actionData.length, 1);
// });

test('Emitting multiple actions should return multiple actions with the correct data', async () => {
await emitAction(zkApp, senderKeypair, { numberOfEmits: 3 });
const results = await executor({
variables: {
input: {
address: zkAppKeypair.publicKey.toBase58(),
},
},
document: parse(`${actionsQuery}`),
});
const actions = results.data.actions;
const lastAction = actions[actions.length - 1];
assert.strictEqual(lastAction.actionData.length, 3);
});
// test('Emitting multiple actions should return multiple actions with the correct data', async () => {
// await emitAction(zkApp, senderKeypair, { numberOfEmits: 3 });
// const results = await executor({
// variables: {
// input: {
// address: zkAppKeypair.publicKey.toBase58(),
// },
// },
// document: parse(`${actionsQuery}`),
// });
// const actions = results.data.actions;
// const lastAction = actions[actions.length - 1];
// assert.strictEqual(lastAction.actionData.length, 3);
// });

describe('Actions from different accounts', async () => {
const sendersCount = 5;
const actionsCount = 3;
const senders: Keypair[] = [];
// describe('Actions from different accounts', async () => {
// const sendersCount = 5;
// const actionsCount = 3;
// const senders: Keypair[] = [];

before(async () => {
for (let i = 0; i < sendersCount; i++) {
senders.push(await Lightnet.acquireKeyPair());
}
// before(async () => {
// for (let i = 0; i < sendersCount; i++) {
// senders.push(await Lightnet.acquireKeyPair());
// }

await emitActionsFromMultipleSenders(zkApp, senders, {
numberOfEmits: actionsCount,
});
});
// await emitActionsFromMultipleSenders(zkApp, senders, {
// numberOfEmits: actionsCount,
// });
// });

test('Emitting actions from many accounts should be fetchable in o1js', async () => {
await Mina.fetchActions(zkApp.address); // This line will throw if actions do not reproduce the correct action hash
assert(true);
});
// test('Emitting actions from many accounts should be fetchable in o1js', async () => {
// await Mina.fetchActions(zkApp.address); // This line will throw if actions do not reproduce the correct action hash
// assert(true);
// });

test('Fetched actions have order metadata', async () => {
const results = await executor({
variables: {
input: {
address: zkApp.address,
},
},
document: parse(`${actionsQuery}`),
});
const actions: Actions = results.data.actions;
for (const block of actions) {
const actionData = block.actionData;
for (const action of actionData) {
assert(typeof action.transactionInfo.sequenceNumber === 'number');
assert(action.transactionInfo.zkappAccountUpdateIds.length > 0);
}
}
});
// test('Fetched actions have order metadata', async () => {
// const results = await executor({
// variables: {
// input: {
// address: zkApp.address,
// },
// },
// document: parse(`${actionsQuery}`),
// });
// const actions: Actions = results.data.actions;
// for (const block of actions) {
// const actionData = block.actionData;
// for (const action of actionData) {
// assert(typeof action.transactionInfo.sequenceNumber === 'number');
// assert(action.transactionInfo.zkappAccountUpdateIds.length > 0);
// }
// }
// });

test('Fetched actions have correct order', async () => {
const results = await executor({
variables: {
input: {
address: zkApp.address,
},
},
document: parse(`${actionsQuery}`),
});
const actions: Actions = results.data.actions;
// test('Fetched actions have correct order', async () => {
// const results = await executor({
// variables: {
// input: {
// address: zkApp.address,
// },
// },
// document: parse(`${actionsQuery}`),
// });
// const actions: Actions = results.data.actions;

let testedAccountUpdateOrder = false;
for (const block of actions) {
const actionData = block.actionData;
for (let i = 1; i < actionData.length; i++) {
const previousAction = actionData[i - 1];
const currentAction = actionData[i];
assert.ok(
previousAction.transactionInfo.sequenceNumber <=
currentAction.transactionInfo.sequenceNumber
);
if (
previousAction.transactionInfo.sequenceNumber ===
currentAction.transactionInfo.sequenceNumber
) {
testedAccountUpdateOrder = true;
assert.ok(
previousAction.accountUpdateId < currentAction.accountUpdateId
);
}
}
}
assert.ok(testedAccountUpdateOrder);
});
});
});
// let testedAccountUpdateOrder = false;
// for (const block of actions) {
// const actionData = block.actionData;
// for (let i = 1; i < actionData.length; i++) {
// const previousAction = actionData[i - 1];
// const currentAction = actionData[i];
// assert.ok(
// previousAction.transactionInfo.sequenceNumber <=
// currentAction.transactionInfo.sequenceNumber
// );
// if (
// previousAction.transactionInfo.sequenceNumber ===
// currentAction.transactionInfo.sequenceNumber
// ) {
// testedAccountUpdateOrder = true;
// assert.ok(
// previousAction.accountUpdateId < currentAction.accountUpdateId
// );
// }
// }
// }
// assert.ok(testedAccountUpdateOrder);
// });
// });
// });
});

0 comments on commit 0c4add3

Please sign in to comment.