Skip to content

Commit

Permalink
feat(sui)!: add a test for the new field added (#478)
Browse files Browse the repository at this point in the history
Co-authored-by: Blockchain Guy <[email protected]>
  • Loading branch information
Foivos and blockchainguyy authored Dec 17, 2024
1 parent 2186aa6 commit 117389b
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions sui/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,45 @@ async function checkVersionControl(version, options) {
}
}

async function testNewField(value, options) {
const config = loadConfig(options.env);

const chain = getChainConfig(config, options.chainName);
const [keypair, client] = getWallet(chain, options);
await printWalletInfo(keypair, client, chain, options);

if (!chain.contracts?.AxelarGateway) {
throw new Error('Axelar Gateway package not found.');
}

const contractConfig = chain.contracts.AxelarGateway;
const packageId = contractConfig.address;

let tx = new Transaction();

tx.moveCall({
target: `${packageId}::gateway::set_new_field`,
arguments: [tx.object(contractConfig.objects.Gateway), tx.pure.u64(value)],
});

await broadcast(client, keypair, tx, 'Set new_field');
await new Promise((resolve) => setTimeout(resolve, 1000));

tx = new Transaction();

tx.moveCall({
target: `${packageId}::gateway::new_field`,
arguments: [tx.object(contractConfig.objects.Gateway)],
});

const response = await client.devInspectTransactionBlock({
transactionBlock: tx,
sender: keypair.toSuiAddress(),
});
const returnedValue = bcs.U64.parse(new Uint8Array(response.results[0].returnValues[0][0]));
console.log(`Set the value to ${value} and it was set to ${returnedValue}.`);
}

async function mainProcessor(processor, args, options) {
const config = loadConfig(options.env);

Expand Down Expand Up @@ -565,6 +604,13 @@ if (require.main === module) {
checkVersionControl(version, options);
});

program
.command('test-new-field <value>')
.description('Test the new field added for upgrade-versioned')
.action((value, options) => {
testNewField(value, options);
});

addOptionsToCommands(program, addBaseOptions, { offline: true });

program.parse();
Expand Down

0 comments on commit 117389b

Please sign in to comment.