Skip to content

Commit

Permalink
feat: startContract helper
Browse files Browse the repository at this point in the history
- helper function to install a contract from a proposal builder
- queries vstorage and skips installation and CoreEval if instance is found
  • Loading branch information
0xpatrickdev committed Aug 29, 2024
1 parent ac9d0c2 commit 3639831
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
11 changes: 2 additions & 9 deletions multichain-testing/test/auto-stake-it.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,8 @@ test.before(async t => {
deleteTestKeys(accounts).catch();
const wallets = await setupTestKeys(accounts);
t.context = { ...rest, wallets, deleteTestKeys };

t.log('bundle and install contract', contractName);
await t.context.deployBuilder(contractBuilder);
const { vstorageClient } = t.context;
await t.context.retryUntilCondition(
() => vstorageClient.queryData(`published.agoricNames.instance`),
res => contractName in Object.fromEntries(res),
`${contractName} instance is available`,
);
const { startContract } = rest;
await startContract(contractName, contractBuilder);
});

test.after(async t => {
Expand Down
11 changes: 2 additions & 9 deletions multichain-testing/test/basic-flows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ test.before(async t => {
deleteTestKeys(accounts).catch();
const wallets = await setupTestKeys(accounts);
t.context = { ...rest, wallets, deleteTestKeys };

t.log('bundle and install contract', contractName);
await t.context.deployBuilder(contractBuilder);
const { vstorageClient } = t.context;
await t.context.retryUntilCondition(
() => vstorageClient.queryData(`published.agoricNames.instance`),
res => contractName in Object.fromEntries(res),
`${contractName} instance is available`,
);
const { startContract } = rest;
await startContract(contractName, contractBuilder);
});

test.after(async t => {
Expand Down
11 changes: 2 additions & 9 deletions multichain-testing/test/send-anywhere.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,8 @@ test.before(async t => {
deleteTestKeys(accounts).catch();
const wallets = await setupTestKeys(accounts);
t.context = { ...rest, wallets, deleteTestKeys };

t.log('bundle and install contract', contractName);
await t.context.deployBuilder(contractBuilder);
const { vstorageClient } = t.context;
await t.context.retryUntilCondition(
() => vstorageClient.queryData(`published.agoricNames.instance`),
res => contractName in Object.fromEntries(res),
`${contractName} instance is available`,
);
const { startContract } = rest;
await startContract(contractName, contractBuilder);
});

test.after(async t => {
Expand Down
28 changes: 28 additions & 0 deletions multichain-testing/test/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,41 @@ export const commonSetup = async (t: ExecutionContext) => {
});
const hermes = makeHermes(childProcess);

/**
* Starts a contract if instance not found. Takes care of installing
* bundles and voting on the CoreEval proposal.
*
* @param contractName name of the contract in agoricNames
* @param contractBuilder path to proposal builder
*/
const startContract = async (
contractName: string,
contractBuilder: string,
) => {
const { vstorageClient } = tools;
const instances = Object.fromEntries(
await vstorageClient.queryData(`published.agoricNames.instance`),
);
if (contractName in instances) {
return t.log('Contract found. Skipping installation...');
}
t.log('bundle and install contract', contractName);
await deployBuilder(contractBuilder);
await retryUntilCondition(
() => vstorageClient.queryData(`published.agoricNames.instance`),
res => contractName in Object.fromEntries(res),
`${contractName} instance is available`,
);
};

return {
useChain,
...tools,
...keyring,
retryUntilCondition,
deployBuilder,
hermes,
startContract,
};
};

Expand Down

0 comments on commit 3639831

Please sign in to comment.