Skip to content

Commit

Permalink
Merge pull request #141 from Agoric/test/psm-wallet-provisioning
Browse files Browse the repository at this point in the history
test: testing wallet provisioning in psm
  • Loading branch information
samsiegart authored Apr 24, 2024
2 parents 2cd5564 + 0f8b299 commit 0360f0e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 49 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"format": "prettier --write . && yarn lint --fix",
"test": "vitest",
"coverage": "vitest run --coverage",
"test:e2e": "EXTENSION=keplr synpress run --configFile=tests/e2e/synpress.config.cjs",
"test:e2e": "EXTENSION=keplr SKIP_EXTENSION_SETUP=true synpress run --configFile=tests/e2e/synpress.config.cjs",
"test:e2e:ci": "start-server-and-test 'yarn dev' http-get://localhost:5173 'yarn test:e2e'"
},
"dependencies": {
Expand All @@ -23,7 +23,7 @@
"@agoric/ertp": "^0.16.2",
"@agoric/rpc": "^0.9.0",
"@agoric/smart-wallet": "^0.5.3",
"@agoric/synpress": "^3.7.2-beta.12",
"@agoric/synpress": "^3.8.1",
"@agoric/ui-components": "^0.9.0",
"@agoric/web-components": "^0.15.0",
"@agoric/zoe": "^0.26.2",
Expand Down
93 changes: 50 additions & 43 deletions tests/e2e/specs/swap-tokens.spec.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
/* eslint-disable ui-testing/no-disabled-tests */
import { DEFAULT_TIMEOUT, phrasesList } from '../utils';

describe('Swap Tokens Tests', () => {
const limitFloat = float => parseFloat(float.toFixed(5));
const amountToSwap = 0.001;
const transactionFee = 0.2;
const phrasesList = {
emerynet: {
walletButton: 'li[data-value="testnet"]',
psmNetwork: 'Agoric Emerynet',
token: 'ToyUSD',
},
local: {
walletButton: 'li[data-value="local"]',
psmNetwork: 'Local Network',
token: 'USDC_axl',
},
const walletAddress = {
value: null,
};
const networkPhrases = phrasesList[Cypress.env('AGORIC_NET')];

it(`should connect with Agoric Chain on https;//wallet.agoric.app`, () => {
cy.origin('https://wallet.agoric.app/', () => {
cy.visit('/');
});
cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});

cy.origin(
'https://wallet.agoric.app/',
{ args: { networkPhrases } },
({ networkPhrases }) => {
cy.visit('/wallet/');

cy.get('input.PrivateSwitchBase-input').click();
cy.contains('Proceed').click();

cy.get('button[aria-label="Settings"]').click();

cy.get('#demo-simple-select').click();
cy.get(networkPhrases.walletButton).click();
cy.contains('button', 'Connect').click();
}
);

cy.acceptAccess().then(taskCompleted => {
expect(taskCompleted).to.be.true;
});
it('should setup wallet for test', () => {
if (networkPhrases.isLocal) {
cy.setupWallet();
} else {
cy.setupWallet({
createNewWallet: true,
walletName: 'my created wallet',
selectedChains: ['Agoric'],
});

cy.getWalletAddress('Agoric').then(
address => (walletAddress.value = address)
);

// Provision IST for wallet
cy.origin(
'https://emerynet.faucet.agoric.net',
{ args: { walletAddress } },
({ walletAddress }) => {
cy.visit('/');
cy.get('[id="address"]').first().type(walletAddress.value);
cy.get('[type="radio"][value="client"]').click();
cy.get('[name="clientType"]').select('REMOTE_WALLET');

cy.get('[type="submit"]').first().click();
cy.get('body')
.contains('success', { timeout: DEFAULT_TIMEOUT })
.should('exist');
}
);
}
});

it('should connect with wallet', () => {
Expand Down Expand Up @@ -83,16 +79,27 @@ describe('Swap Tokens Tests', () => {
cy.get('input[type="number"]').first().type(amountToSwap);
cy.get('button').contains('Swap').click();

// Should show dialog for wallet provision
if (!networkPhrases.isLocal) {
cy.contains('h3', 'Smart Wallet Required').should('exist');
cy.contains('button', 'Proceed').click();
}

// Confirm transactions
cy.confirmTransaction();
cy.get('div')
.contains('Swap Completed', { timeout: 60000 })
.contains('Swap Completed', { timeout: DEFAULT_TIMEOUT })
.should('be.visible');

cy.getTokenAmount('IST').then(amount =>
expect(amount).to.be.oneOf([
limitFloat(istBalance - amountToSwap),
limitFloat(istBalance - amountToSwap - transactionFee),
limitFloat(istBalance - amountToSwap - networkPhrases.provisionFee),
limitFloat(
istBalance -
amountToSwap -
networkPhrases.provisionFee -
transactionFee
),
])
);
});
Expand All @@ -117,7 +124,7 @@ describe('Swap Tokens Tests', () => {
// Confirm transactions
cy.confirmTransaction();
cy.get('div')
.contains('Swap Completed', { timeout: 60000 })
.contains('Swap Completed', { timeout: DEFAULT_TIMEOUT })
.should('be.visible');

cy.getTokenAmount('IST').then(amount =>
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const DEFAULT_TIMEOUT = 60_000;

export const phrasesList = {
emerynet: {
walletButton: 'li[data-value="testnet"]',
psmNetwork: 'Agoric Emerynet',
token: 'ToyUSD',
isLocal: false,
provisionFee: 0.75,
},
local: {
walletButton: 'li[data-value="local"]',
psmNetwork: 'Local Network',
token: 'USDC_axl',
isLocal: true,
provisionFee: 0,
},
};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@
resolved "https://registry.yarnpkg.com/@agoric/swingset-xsnap-supervisor/-/swingset-xsnap-supervisor-0.10.3-u13.0.tgz#83c7744c28b0093a93ef1dbdf3e3c7244dbf5265"
integrity sha512-gEIOlyLd34JZkVRPWq9982Eu7G4ggE6H3I3RueO9JbbhOXwU+irYL922t0Ztdjc9aJW2H5f78ukcn9j1SZmtHQ==

"@agoric/synpress@^3.7.2-beta.12":
version "3.7.2-beta.12"
resolved "https://registry.yarnpkg.com/@agoric/synpress/-/synpress-3.7.2-beta.12.tgz#1a1d35c3c2c56e985630e0cd4c05039b8b6878b3"
integrity sha512-mSDc0IJLdNIXF5re6Bd/7NBXjyeGTNRIji69ZpflikY4BuQpxaQdfvK3TOsdWfs74Z5ReIXADly9YYOuhbkdLw==
"@agoric/synpress@^3.8.1":
version "3.8.1"
resolved "https://registry.yarnpkg.com/@agoric/synpress/-/synpress-3.8.1.tgz#0c71e16a5ce81b77f8b20588946d55c312acc34d"
integrity sha512-vD8TeKOWup/yrPO7LBiYwvKSy6LAjGJaMiCU52yfp/zqKFBWopfwCdUSpvzTnhBEZAz3VUxsrgzgfil5wCiRNQ==
dependencies:
"@cypress/code-coverage" "^3.11.0"
"@cypress/webpack-dev-server" "^3.5.2"
Expand Down

0 comments on commit 0360f0e

Please sign in to comment.