Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify things by utilising test fixtures. #493

Merged
merged 1 commit into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/fixtures/on-chain-state-mgmt-zkapp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test as base } from '@playwright/test';
import { OnChainStateMgmtZkAppPage } from '../pages/on-chain-state-mgmt-zkapp.js';

type OnChainStateMgmtZkAppFixture = {
onChainStateMgmtZkAppPage: OnChainStateMgmtZkAppPage;
};

export const test = base.extend<OnChainStateMgmtZkAppFixture>({
onChainStateMgmtZkAppPage: async ({ page }, use) => {
await use(new OnChainStateMgmtZkAppPage(page));
},
});
111 changes: 56 additions & 55 deletions tests/on-chain-state-mgmt-zkapp-ui.spec.ts
Original file line number Diff line number Diff line change
@@ -1,104 +1,105 @@
import { test } from '@playwright/test';
import { OnChainStateMgmtZkAppPage } from './page/on-chain-state-mgmt-zkapp-ui.js';
import { test } from './fixtures/on-chain-state-mgmt-zkapp.js';

test.describe('On-Chain State Management zkApp UI', () => {
test('should load page and initialize SnarkyJS', async ({ page }) => {
const onChainStateMgmtZkApp = new OnChainStateMgmtZkAppPage(page);
await onChainStateMgmtZkApp.goto();
await onChainStateMgmtZkApp.checkSnarkyJsInitialization();
test('should load page and initialize SnarkyJS', async ({
onChainStateMgmtZkAppPage,
}) => {
await onChainStateMgmtZkAppPage.goto();
await onChainStateMgmtZkAppPage.checkSnarkyJsInitialization();
});

test('should fail to update account state since zkApp was not yet deployed', async ({
page,
onChainStateMgmtZkAppPage,
}) => {
test.skip(process.env.CI === 'true', 'Skipping test in CI');

const onChainStateMgmtZkApp = new OnChainStateMgmtZkAppPage(page);
await onChainStateMgmtZkApp.goto();
await onChainStateMgmtZkApp.checkSnarkyJsInitialization();
await onChainStateMgmtZkApp.updateZkAppState('3');
await onChainStateMgmtZkApp.checkZkAppStateUpdateFailureByUnknownAccount();
await onChainStateMgmtZkAppPage.goto();
await onChainStateMgmtZkAppPage.checkSnarkyJsInitialization();
await onChainStateMgmtZkAppPage.updateZkAppState('3');
await onChainStateMgmtZkAppPage.checkZkAppStateUpdateFailureByUnknownAccount();
});

test('should compile and deploy zkApp', async ({ page }) => {
const onChainStateMgmtZkApp = new OnChainStateMgmtZkAppPage(page);
await onChainStateMgmtZkApp.goto();
await onChainStateMgmtZkApp.checkSnarkyJsInitialization();
await onChainStateMgmtZkApp.compileAndDeployZkApp();
await onChainStateMgmtZkApp.checkDeployedZkApp();
test('should compile and deploy zkApp', async ({
onChainStateMgmtZkAppPage,
}) => {
await onChainStateMgmtZkAppPage.goto();
await onChainStateMgmtZkAppPage.checkSnarkyJsInitialization();
await onChainStateMgmtZkAppPage.compileAndDeployZkApp();
await onChainStateMgmtZkAppPage.checkDeployedZkApp();
});

test('should prove transaction and update zkApp account state', async ({
page,
onChainStateMgmtZkAppPage,
}) => {
const currentAccountState = '2';
const newAccountState = '4';
const onChainStateMgmtZkApp = new OnChainStateMgmtZkAppPage(page);
await onChainStateMgmtZkApp.goto();
await onChainStateMgmtZkApp.checkSnarkyJsInitialization();
await onChainStateMgmtZkApp.compileAndDeployZkApp();
await onChainStateMgmtZkApp.checkDeployedZkApp();
await onChainStateMgmtZkApp.updateZkAppState(newAccountState);
await onChainStateMgmtZkApp.checkUpdatedZkAppState(

await onChainStateMgmtZkAppPage.goto();
await onChainStateMgmtZkAppPage.checkSnarkyJsInitialization();
await onChainStateMgmtZkAppPage.compileAndDeployZkApp();
await onChainStateMgmtZkAppPage.checkDeployedZkApp();
await onChainStateMgmtZkAppPage.updateZkAppState(newAccountState);
await onChainStateMgmtZkAppPage.checkUpdatedZkAppState(
currentAccountState,
newAccountState
);
});

test('should re-deploy zkApp', async ({ page }) => {
test('should re-deploy zkApp', async ({ onChainStateMgmtZkAppPage }) => {
test.skip(process.env.CI === 'true', 'Skipping test in CI');

const currentAccountState = '2';
const newAccountState = '4';
const onChainStateMgmtZkApp = new OnChainStateMgmtZkAppPage(page);
await onChainStateMgmtZkApp.goto();
await onChainStateMgmtZkApp.checkSnarkyJsInitialization();
await onChainStateMgmtZkApp.compileAndDeployZkApp();
await onChainStateMgmtZkApp.checkDeployedZkApp();
await onChainStateMgmtZkApp.updateZkAppState(newAccountState);
await onChainStateMgmtZkApp.checkUpdatedZkAppState(

await onChainStateMgmtZkAppPage.goto();
await onChainStateMgmtZkAppPage.checkSnarkyJsInitialization();
await onChainStateMgmtZkAppPage.compileAndDeployZkApp();
await onChainStateMgmtZkAppPage.checkDeployedZkApp();
await onChainStateMgmtZkAppPage.updateZkAppState(newAccountState);
await onChainStateMgmtZkAppPage.checkUpdatedZkAppState(
currentAccountState,
newAccountState
);
await onChainStateMgmtZkApp.compileAndDeployZkApp();
await onChainStateMgmtZkApp.checkDeployedZkApp();
await onChainStateMgmtZkAppPage.compileAndDeployZkApp();
await onChainStateMgmtZkAppPage.checkDeployedZkApp();
});

test('should fail to re-deploy zkApp by fee excess', async ({ page }) => {
test('should fail to re-deploy zkApp by fee excess', async ({
onChainStateMgmtZkAppPage,
}) => {
test.skip(process.env.CI === 'true', 'Skipping test in CI');

const onChainStateMgmtZkApp = new OnChainStateMgmtZkAppPage(page);
await onChainStateMgmtZkApp.goto();
await onChainStateMgmtZkApp.checkSnarkyJsInitialization();
await onChainStateMgmtZkApp.compileAndDeployZkApp();
await onChainStateMgmtZkApp.checkDeployedZkApp();
await onChainStateMgmtZkApp.clearEvents();
await onChainStateMgmtZkApp.compileAndDeployZkApp();
await onChainStateMgmtZkApp.checkZkAppDeploymentFailureByFeeExcess();
await onChainStateMgmtZkAppPage.goto();
await onChainStateMgmtZkAppPage.checkSnarkyJsInitialization();
await onChainStateMgmtZkAppPage.compileAndDeployZkApp();
await onChainStateMgmtZkAppPage.checkDeployedZkApp();
await onChainStateMgmtZkAppPage.clearEvents();
await onChainStateMgmtZkAppPage.compileAndDeployZkApp();
await onChainStateMgmtZkAppPage.checkZkAppDeploymentFailureByFeeExcess();
});

test('should fail to update account state by zkApp constraint', async ({
page,
onChainStateMgmtZkAppPage,
}) => {
test.skip(process.env.CI === 'true', 'Skipping test in CI');

let currentAccountState = '2';
let newAccountState = '4';
const nextAccountState = '16';
const onChainStateMgmtZkApp = new OnChainStateMgmtZkAppPage(page);
await onChainStateMgmtZkApp.goto();
await onChainStateMgmtZkApp.checkSnarkyJsInitialization();
await onChainStateMgmtZkApp.compileAndDeployZkApp();
await onChainStateMgmtZkApp.checkDeployedZkApp();
await onChainStateMgmtZkApp.updateZkAppState(newAccountState);
await onChainStateMgmtZkApp.checkUpdatedZkAppState(

await onChainStateMgmtZkAppPage.goto();
await onChainStateMgmtZkAppPage.checkSnarkyJsInitialization();
await onChainStateMgmtZkAppPage.compileAndDeployZkApp();
await onChainStateMgmtZkAppPage.checkDeployedZkApp();
await onChainStateMgmtZkAppPage.updateZkAppState(newAccountState);
await onChainStateMgmtZkAppPage.checkUpdatedZkAppState(
currentAccountState,
newAccountState
);
currentAccountState = newAccountState;
newAccountState = '1';
await onChainStateMgmtZkApp.updateZkAppState(newAccountState);
await onChainStateMgmtZkApp.checkZkAppStateUpdateFailureByStateConstraint(
await onChainStateMgmtZkAppPage.updateZkAppState(newAccountState);
await onChainStateMgmtZkAppPage.checkZkAppStateUpdateFailureByStateConstraint(
currentAccountState,
nextAccountState,
newAccountState
Expand Down