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

test: pause old auctioneer to avoid clobbering vstorage #367

Draft
wants to merge 6 commits into
base: rs-test-with-u17
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions test/e2e/specs/liquidation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@
});
});

context('Old auctioneer', () => {
it('should pause the old auctioneer', () => {
cy.pauseOldAuctioneer();
});
});

context('Adjusting auction params from econ-gov', () => {
it('should allow gov1 to create a proposal', () => {
cy.skipWhen(AGORIC_NET !== networks.LOCAL);
Expand Down Expand Up @@ -304,6 +310,9 @@
});

context('Creating vaults and changing ATOM price', () => {
it('should pause the old auctioneer', () => {
cy.pauseOldAuctioneer();
});
it(
'should connect with the wallet',
{
Expand Down Expand Up @@ -374,6 +383,10 @@
});

context('Place bids and make all vaults enter liquidation', () => {
it('should pause the old auctioneer', () => {
cy.pauseOldAuctioneer();
});

it('should create a vault minting 400 ISTs and giving 80 ATOMs as collateral', () => {
cy.skipWhen(AGORIC_NET !== networks.LOCAL);
cy.createVault({ wantMinted: 400, giveCollateral: 80, userKey: 'gov1' });
Expand Down Expand Up @@ -435,14 +448,14 @@
});

it('should verify the value of startProceedsGoal from the CLI successfully', () => {
cy.wait(30000); // Wait for 30 seconds

Check failure on line 451 in test/e2e/specs/liquidation.spec.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Do not wait for arbitrary time periods
const propertyName = 'book0.startProceedsGoal';
const expectedValue = '309.54 IST';
cy.verifyAuctionData(propertyName, expectedValue);
});

it('should verify the value of startCollateral from the CLI successfully', () => {
cy.wait(30000); // Wait for 30 seconds

Check failure on line 458 in test/e2e/specs/liquidation.spec.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Do not wait for arbitrary time periods
const propertyName = 'book0.startCollateral';
const expectedValue = '45 ATOM';
cy.verifyAuctionData(propertyName, expectedValue);
Expand All @@ -467,7 +480,7 @@
);

it('should verify the value of collateralAvailable from the CLI successfully', () => {
cy.wait(30000); // Wait for 30 seconds

Check failure on line 483 in test/e2e/specs/liquidation.spec.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Do not wait for arbitrary time periods
const propertyName = 'book0.collateralAvailable';
const expectedValue = '9.659301 ATOM';
cy.wait(2 * MINUTE_MS);
Expand Down
64 changes: 64 additions & 0 deletions test/e2e/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
FACUET_HEADERS,
agoricNetworks,
} from './test.utils';
import { makeMarshal, Far } from './unmarshal.js';

const AGORIC_NET = Cypress.env('AGORIC_NET') || 'local';
const network = AGORIC_NET !== 'local' ? 'testnet' : 'local';
Expand Down Expand Up @@ -104,6 +105,69 @@
});
});

const { fromCapData } = makeMarshal(undefined, (s, iface) =>
Far(iface, { getSlot: () => s }),
);

Cypress.Commands.add('pauseOldAuctioneer', () => {
const agopsOpts = {
env: { AGORIC_NET },
timeout: COMMAND_TIMEOUT,
};
const netConfig =
AGORIC_NET === 'local'
? ''
: `-B https://${AGORIC_NET}.agoric.net/network-config`;
cy.exec(
`agoric follow ${netConfig} -lF :published.agoricNames.instance -o text`,
).then(async ({ stdout }) => {
cy.wait(2 * 60 * 1000);
const byName = Object.fromEntries(fromCapData(JSON.parse(stdout)));
cy.expect(byName).to.have.property('auctioneer');
cy.task('info', `Object is: ${JSON.stringify(byName)}`);
const auctioneer = byName.auctioneer;

Check warning on line 128 in test/e2e/support.js

View workflow job for this annotation

GitHub Actions / build (18.x)

'auctioneer' is assigned a value but never used. Allowed unused vars must match /^_/u
// cy.expect(byName).to.have.property('auctioneer175');
const oldAuctioneer = byName.auctioneer175;

cy.exec(
`${agops} ec find-continuing-id --from gov1 --for 'charter member invitation'`,
agopsOpts,
).then(({ stdout }) => {
const acceptId = stdout.trim();
cy.expect(acceptId).to.be.a('string');
cy.expect(acceptId).to.have.length.of.at.least(2);

const changeFile = '/tmp/proposeChange.json';
cy.expect(acceptId).to.be.a('string');
cy.expect(acceptId).to.have.length.of.at.least(2);
cy.exec(
`${agops} auctioneer proposeParamChange --charterAcceptOfferId ${acceptId} --start-frequency 100000000000000`,
agopsOpts,
).then(({ stdout }) => {
const offerSpec = JSON.parse(stdout);
cy.task('info', `offerSpec is: ${JSON.stringify(offerSpec)}`);
// cy.expect(offerSpec.slots[0]).to.equal(auctioneer.getSlot());
offerSpec.slots[0] = oldAuctioneer.getSlot();
cy.writeFile(changeFile, JSON.stringify(offerSpec), 'utf8');

const broadcastCommand = `${agops} perf satisfaction --executeOffer ${changeFile} --from gov1 --keyring-backend=test`;

cy.exec(broadcastCommand, {
env: { AGORIC_NET },
timeout: COMMAND_TIMEOUT,
failOnNonZeroExit: false, //@@@
}).then(({ stdout, stderr }) => {
console.log('@@broadcast', { stdout, stderr });
expect(stdout).not.to.contain('Error');
});

cy.exec(`${agops} ec vote --send-from gov1 --forPosition 0`, agopsOpts);
cy.exec(`${agops} ec vote --send-from gov2 --forPosition 0`, agopsOpts);
});
});
});
});

Cypress.Commands.add('skipWhen', function (expression) {
if (expression) {
this.skip();
Expand Down
110 changes: 110 additions & 0 deletions test/e2e/unmarshal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// @ts-check
'use strict';

const {
create,
entries,
fromEntries,
freeze,
keys,
setPrototypeOf,
prototype: objectPrototype,
} = Object;
const { isArray } = Array;

const { freeze: harden } = Object;

const sigilDoc = {
'!': 'escaped string',
'+': `non-negative bigint`,
'-': `negative bigint`,
'#': `manifest constant`,
'%': `symbol`,
$: `remotable`,
'&': `promise`,
};
const sigils = keys(sigilDoc).join('');

/** @type {<V, U>(obj: Record<string, V>, f: (v: V) => U) => Record<string, U>} */
const objMap = (obj, f) =>
fromEntries(entries(obj).map(([p, v]) => [f(p), f(v)]));

export const makeMarshal = (_v2s, convertSlotToVal = (s, _i) => s) => {
const fromCapData = ({ body, slots }) => {
const recur = (v) => {
switch (typeof v) {
case 'boolean':
case 'number':
return v;
case 'string':
if (v === '') return v;
const sigil = v.slice(0, 1);

Check failure on line 41 in test/e2e/unmarshal.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected lexical declaration in case block
if (!sigils.includes(sigil)) return v;
switch (sigil) {
case '!':
return v.slice(1);
case '+':
return BigInt(v.slice(1));
case '-':
return -BigInt(v.slice(1));
case '$': {
const [ix, iface] = v.slice(1).split('.');
return convertSlotToVal(slots[Number(ix)], iface);
}
case '#':
switch (v) {
case '#undefined':
return undefined;
case '#Infinity':
return Infinity;
case '#NaN':
return Infinity;
default:
throw RangeError(`Unexpected constant ${v}`);
}
case '%':
// TODO: @@asyncIterator
return Symbol.for(v.slice(1));
default:
throw RangeError(`Unexpected sigil ${sigil}`);
}
case 'object':
if (v === null) return v;
if (isArray(v)) {
return freeze(v.map(recur));
}
return freeze(objMap(v, recur));
default:
throw RangeError(`Unexpected value type ${typeof v}`);
}
};
const encoding = JSON.parse(body.replace(/^#/, ''));
return recur(encoding);
};

const toCapData = () => {
throw Error('not implemented');
};

return harden({
fromCapData,
unserialize: fromCapData,
toCapData,
serialize: toCapData,
});
};

const PASS_STYLE = Symbol.for('passStyle');
export const Far = (iface, methods) => {
const proto = freeze(
create(objectPrototype, {
[PASS_STYLE]: { value: 'remotable' },
[Symbol.toStringTag]: { value: iface },
})
);
setPrototypeOf(methods, proto);
freeze(methods);
return methods;
};

// export { makeUnmarshal };
Loading