Skip to content

Commit

Permalink
Merge pull request #383 from Agoric/rs-new-wallet-for-testing
Browse files Browse the repository at this point in the history
Create a new wallet designed for vault creation
  • Loading branch information
rabi-siddique authored Oct 15, 2024
2 parents a6010f1 + 76e3fd5 commit 5e58e6a
Show file tree
Hide file tree
Showing 4 changed files with 340 additions and 128 deletions.
264 changes: 182 additions & 82 deletions test/e2e/specs/liquidation-reconstitution.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ describe('Liquidation Reconstitution Testing', () => {
const DEFAULT_TASK_TIMEOUT = currentConfig.DEFAULT_TASK_TIMEOUT;
const LIQUIDATING_TIMEOUT = currentConfig.LIQUIDATING_TIMEOUT;
const LIQUIDATED_TIMEOUT = currentConfig.LIQUIDATED_TIMEOUT;
const user1Mnemonic = currentConfig.user1Mnemonic;
const user1Address = currentConfig.user1Address;
const bidderMnemonic = currentConfig.bidderMnemonic;
const bidderAddress = currentConfig.bidderAddress;
const bidderWalletName = currentConfig.bidderWalletName;
Expand All @@ -34,10 +32,99 @@ describe('Liquidation Reconstitution Testing', () => {
const econGovURL = currentConfig.econGovURL;
const auctionURL = currentConfig.auctionURL;
const reserveURL = currentConfig.reserveURL;
let user1Mnemonic =
AGORIC_NET === networks.LOCAL ? currentConfig.user1Mnemonic : null;
let user1Address =
AGORIC_NET === networks.LOCAL ? currentConfig.user1Address : null;
let bidderAtomBalance = 0;
let bidderIstBalance = 0;
let shortfallBalance = 0;

context('Add key for user1 wallet', () => {
it('add key for user1 wallet using agd', () => {
cy.task('info', `AGORIC_NET: ${AGORIC_NET}`);

if (AGORIC_NET === networks.LOCAL) {
cy.addKeys({
keyName: 'user1',
mnemonic: user1Mnemonic,
expectedAddress: user1Address,
});
} else {
cy.task('info', 'get mnemonic for the new wallet using agd');
cy.createNewUser({ keyName: 'user1' })
.then(output => {
cy.task('info', `${JSON.stringify(output)}`);
cy.wrap(output);
})
.then(({ mnemonic, address }) => {
user1Mnemonic = mnemonic;
cy.task('info', `user1 mnemonic: ${user1Mnemonic}`);
user1Address = address;
cy.task('info', `user1 address: ${address}`);
})
.then(() => {
expect(user1Mnemonic).to.not.be.null;
expect(user1Address).to.not.be.null;
});
}
});

it(
'should provision the user1 wallet',
{
retries: {
runMode: 2,
openMode: 2,
},
},
() => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
// UNTIL https://github.com/Agoric/instagoric/issues/64
for (let i = 0; i < 3; i++) {
cy.provisionFromFaucet(user1Address, 'delegate');
}
cy.provisionFromFaucet(user1Address, 'client');
},
);
});

context('Add key for bidder wallet', () => {
it('add key for bidder wallet using agd', () => {
if (AGORIC_NET === networks.LOCAL) {
cy.task('info', 'gov1 is the bidder wallet');
cy.addKeys({
keyName: 'gov1',
mnemonic: gov1Mnemonic,
expectedAddress: gov1Address,
});
} else {
cy.addKeys({
keyName: 'bidder',
mnemonic: bidderMnemonic,
expectedAddress: bidderAddress,
});
}
});
});

context('Add keys for gov1 and gov2 wallet', () => {
it('add keys for gov1 and gov2 wallet using agd', () => {
if (AGORIC_NET !== networks.LOCAL) {
cy.addKeys({
keyName: 'gov1',
mnemonic: gov1Mnemonic,
expectedAddress: gov1Address,
});
}
cy.addKeys({
keyName: 'gov2',
mnemonic: gov2Mnemonic,
expectedAddress: gov2Address,
});
});
});

context('Verify if both bidder and user1 have sufficient balance', () => {
// Note: Transaction fees are not considered in these calculations.

Expand Down Expand Up @@ -66,7 +153,7 @@ describe('Liquidation Reconstitution Testing', () => {
});
});

context('Setting up accounts', () => {
context('Setting up Keplr wallets', () => {
// Using exports from the synthetic-chain lib instead of hardcoding mnemonics UNTIL https://github.com/Agoric/agoric-3-proposals/issues/154
it('should set up bidder wallet', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
Expand Down Expand Up @@ -354,46 +441,59 @@ describe('Liquidation Reconstitution Testing', () => {
},
);

it('should add all the keys successfully', () => {
cy.addKeys({
keyName: 'gov1',
mnemonic: gov1Mnemonic,
expectedAddress: gov1Address,
});
cy.addKeys({
keyName: 'gov2',
mnemonic: gov2Mnemonic,
expectedAddress: gov2Address,
});
cy.addKeys({
keyName: 'user1',
mnemonic: user1Mnemonic,
expectedAddress: user1Address,
});
});

it('should add the bidder key successfully', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
cy.addKeys({
keyName: 'bidder',
mnemonic: bidderMnemonic,
expectedAddress: bidderAddress,
});
});
it('should set ATOM price to 12.34', () => {
cy.setOraclePrice(12.34);
});
it('should create a vault minting 100 ISTs and giving 15 ATOMs as collateral', () => {
cy.createVault({ wantMinted: 100, giveCollateral: 15, userKey: 'user1' });
});
it(
'should create a vault minting 100 ISTs and giving 15 ATOMs as collateral',
{
retries: {
runMode: 1,
openMode: 1,
},
},
() => {
cy.createVault({
wantMinted: 100,
giveCollateral: 15,
userKey: 'user1',
});
},
);

it('should create a vault minting 103 ISTs and giving 15 ATOMs as collateral', () => {
cy.createVault({ wantMinted: 103, giveCollateral: 15, userKey: 'user1' });
});
it(
'should create a vault minting 103 ISTs and giving 15 ATOMs as collateral',
{
retries: {
runMode: 1,
openMode: 1,
},
},
() => {
cy.createVault({
wantMinted: 103,
giveCollateral: 15,
userKey: 'user1',
});
},
);

it('should create a vault minting 105 ISTs and giving 15 ATOMs as collateral', () => {
cy.createVault({ wantMinted: 105, giveCollateral: 15, userKey: 'user1' });
});
it(
'should create a vault minting 105 ISTs and giving 15 ATOMs as collateral',
{
retries: {
runMode: 1,
openMode: 1,
},
},
() => {
cy.createVault({
wantMinted: 105,
giveCollateral: 15,
userKey: 'user1',
});
},
);

it(
'should check for the existence of vaults on the UI',
Expand Down Expand Up @@ -671,8 +771,8 @@ describe('Liquidation Reconstitution Testing', () => {
);

context('Verification of Shortfall balance', () => {
it('should see an increase of 5.525 IST in shortfall balance', () => {
const expectedValue = 5.525;
it('should see an increase of 5.5 IST in shortfall balance', () => {
const expectedValue = 5.5;
cy.task('info', `Expected: ${expectedValue}`);

cy.fetchVStorageData({
Expand All @@ -682,7 +782,7 @@ describe('Liquidation Reconstitution Testing', () => {
})
.then(newBalanceObj => {
let newBalance = Number(
(Number(newBalanceObj.value.slice(1)) / 1_000_000).toFixed(2),
(Number(newBalanceObj.value.slice(1)) / 1_000_000).toFixed(1),
);
cy.task('info', `Initial shortfallBalance: ${shortfallBalance}`);
cy.task(
Expand All @@ -691,17 +791,50 @@ describe('Liquidation Reconstitution Testing', () => {
);

const balanceIncrease = Number(
(newBalance - shortfallBalance).toFixed(2),
(newBalance - shortfallBalance).toFixed(1),
);
cy.task('info', `Actual increase: ${balanceIncrease}`);
cy.wrap(balanceIncrease);
})
.then(balanceIncrease => {
expect(balanceIncrease).to.eq(Number(expectedValue.toFixed(2)));
expect(balanceIncrease).to.eq(expectedValue);
});
});
});

context('Close reconstituted Vaults - TESTNET(s)', () => {
it('should close the 100 IST vault and approve the transaction successfully', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
cy.wait(QUICK_WAIT);
const regexVault100 = new RegExp('100(\\.\\d+)?');
cy.contains(regexVault100, { timeout: DEFAULT_TIMEOUT }).click();
cy.contains('Close Out Vault').click();
cy.contains('button.bg-interPurple', 'Close Out Vault').click();

cy.confirmTransaction().then(taskCompleted => {
expect(taskCompleted).to.be.true;
cy.contains('button.bg-interPurple', 'Close Out Vault', {
timeout: DEFAULT_TIMEOUT,
}).should('not.exist');
});
});

it('should close the 103 IST vault and approve the transaction successfully', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
const regexVault103 = new RegExp('103(\\.\\d+)?');
cy.contains(regexVault103, { timeout: DEFAULT_TIMEOUT }).click();
cy.contains('Close Out Vault').click();
cy.contains('button.bg-interPurple', 'Close Out Vault').click();

cy.confirmTransaction().then(taskCompleted => {
expect(taskCompleted).to.be.true;
cy.contains('button.bg-interPurple', 'Close Out Vault', {
timeout: DEFAULT_TIMEOUT,
}).should('not.exist');
});
});
});

context('Verification of Filled Bids', () => {
it("should see increase in the bidder's ATOM balance", () => {
const expectedValue = 13.585;
Expand Down Expand Up @@ -774,43 +907,10 @@ describe('Liquidation Reconstitution Testing', () => {
});
});

context(
'Close the vaults and restore ATOM price to 12.34 on TESTNET(s).',
() => {
it('should close the 100 IST vault and approve the transaction successfully', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
const regexVault100 = new RegExp('100(\\.\\d+)?');
cy.contains(regexVault100, { timeout: LIQUIDATING_TIMEOUT }).click();
cy.contains('Close Out Vault').click();
cy.contains('button.bg-interPurple', 'Close Out Vault').click();

cy.confirmTransaction().then(taskCompleted => {
expect(taskCompleted).to.be.true;
cy.contains('button.bg-interPurple', 'Close Out Vault').should(
'not.exist',
);
});
});

it('should close the 103 IST vault and approve the transaction successfully', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
const regexVault103 = new RegExp('103(\\.\\d+)?');
cy.contains(regexVault103, { timeout: LIQUIDATING_TIMEOUT }).click();
cy.contains('Close Out Vault').click();
cy.contains('button.bg-interPurple', 'Close Out Vault').click();

cy.confirmTransaction().then(taskCompleted => {
expect(taskCompleted).to.be.true;
cy.contains('button.bg-interPurple', 'Close Out Vault').should(
'not.exist',
);
});
});

it('should set ATOM price back to 12.34', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
cy.setOraclePrice(12.34);
});
},
);
context('Restore ATOM price to 12.34 on TESTNET(s).', () => {
it('should set ATOM price back to 12.34', () => {
cy.skipWhen(AGORIC_NET === networks.LOCAL);
cy.setOraclePrice(12.34);
});
});
});
Loading

0 comments on commit 5e58e6a

Please sign in to comment.