diff --git a/tests/cucumber/steps/steps.js b/tests/cucumber/steps/steps.js index 8a4b14dcd..53d9613e7 100644 --- a/tests/cucumber/steps/steps.js +++ b/tests/cucumber/steps/steps.js @@ -120,17 +120,6 @@ module.exports = function getSteps(options) { // Dev Mode State const DEV_MODE_INITIAL_MICROALGOS = 10_000_000; - /* - * waitForAlgodInDevMode is a Dev mode helper method that waits for a transaction to resolve. - * Since Dev mode produces blocks on a per transaction basis, it's possible - * algod generates a block _before_ the corresponding SDK call to wait for a block. - * Without _any_ wait, it's possible the SDK looks for the transaction before algod completes processing. - * So, the method performs a local sleep to simulate waiting for a block. - */ - function waitForAlgodInDevMode() { - return new Promise((resolve) => setTimeout(resolve, 500)); - } - const { algod_token: algodToken, kmd_token: kmdToken } = options; // String parsing helper methods @@ -187,11 +176,6 @@ module.exports = function getSteps(options) { return boxRefArray; } - Given('an algod client', async function () { - this.acl = new algosdk.Algod(algodToken, 'http://localhost', 60000); - return this.acl; - }); - Given('a kmd client', function () { this.kcl = new algosdk.Kmd(kmdToken, 'http://localhost', 60001); return this.kcl; @@ -228,7 +212,7 @@ module.exports = function getSteps(options) { }); When('I get versions with algod', async function () { - this.versions = await this.acl.versions(); + this.versions = await this.v2Client.versionsCheck().do(); this.versions = this.versions.versions; return this.versions; }); @@ -237,47 +221,16 @@ module.exports = function getSteps(options) { assert.deepStrictEqual(true, this.versions.indexOf('v1') >= 0); }); + Then('v2 should be in the versions', function () { + assert.deepStrictEqual(true, this.versions.indexOf('v2') >= 0); + }); + When('I get versions with kmd', async function () { this.versions = await this.kcl.versions(); this.versions = this.versions.versions; return this.versions; }); - When('I get the status', async function () { - this.status = await this.acl.status(); - return this.status; - }); - - When('I get status after this block', async function () { - // Send a transaction to advance blocks in dev mode. - const sp = await this.acl.getTransactionParams(); - if (sp.firstRound === 0) sp.firstRound = 1; - const fundingTxnArgs = { - from: this.accounts[0], - to: this.accounts[0], - amount: 0, - fee: sp.fee, - firstRound: sp.lastRound + 1, - lastRound: sp.lastRound + 1000, - genesisHash: sp.genesishashb64, - genesisID: sp.genesisID, - }; - const stxKmd = await this.kcl.signTransaction( - this.handle, - this.wallet_pswd, - fundingTxnArgs - ); - await this.acl.sendRawTransaction(stxKmd); - - this.statusAfter = await this.acl.statusAfterBlock(this.status.lastRound); - return this.statusAfter; - }); - - Then('I can get the block info', async function () { - this.block = await this.acl.block(this.statusAfter.lastRound); - assert.deepStrictEqual(true, Number.isInteger(this.block.round)); - }); - Given( 'payment transaction parameters {int} {int} {int} {string} {string} {string} {int} {string} {string}', function (fee, fv, lv, gh, to, close, amt, gen, note) { @@ -426,16 +379,16 @@ module.exports = function getSteps(options) { this.rekey = await this.kcl.generateKey(this.handle); this.rekey = this.rekey.address; // Fund the rekey address with some Algos - const sp = await this.acl.getTransactionParams(); + const sp = await this.v2Client.getTransactionParams().do(); if (sp.firstRound === 0) sp.firstRound = 1; const fundingTxnArgs = { from: this.accounts[0], to: this.rekey, amount: DEV_MODE_INITIAL_MICROALGOS, fee: sp.fee, - firstRound: sp.lastRound + 1, - lastRound: sp.lastRound + 1000, - genesisHash: sp.genesishashb64, + firstRound: sp.firstRound, + lastRound: sp.lastRound, + genesisHash: sp.genesisHash, genesisID: sp.genesisID, }; @@ -444,7 +397,7 @@ module.exports = function getSteps(options) { this.wallet_pswd, fundingTxnArgs ); - await this.acl.sendRawTransaction(stxKmd); + await this.v2Client.sendRawTransaction(stxKmd).do(); return this.rekey; } ); @@ -504,15 +457,15 @@ module.exports = function getSteps(options) { 'default transaction with parameters {int} {string}', async function (amt, note) { [this.pk] = this.accounts; - const result = await this.acl.getTransactionParams(); + const result = await this.v2Client.getTransactionParams().do(); this.lastRound = result.lastRound; this.txn = { from: this.accounts[0], to: this.accounts[1], fee: result.fee, - firstRound: result.lastRound + 1, - lastRound: result.lastRound + 1000, - genesisHash: result.genesishashb64, + firstRound: result.firstRound, + lastRound: result.lastRound, + genesisHash: result.genesisHash, genesisID: result.genesisID, note: makeUint8Array(Buffer.from(note, 'base64')), amount: parseInt(amt), @@ -525,15 +478,15 @@ module.exports = function getSteps(options) { 'default transaction with parameters {int} {string} and rekeying key', async function (amt, note) { this.pk = this.rekey; - const result = await this.acl.getTransactionParams(); + const result = await this.v2Client.getTransactionParams().do(); this.lastRound = result.lastRound; this.txn = { from: this.rekey, to: this.accounts[1], fee: result.fee, - firstRound: result.lastRound + 1, - lastRound: result.lastRound + 1000, - genesisHash: result.genesishashb64, + firstRound: result.firstRound, + lastRound: result.lastRound, + genesisHash: result.genesisHash, genesisID: result.genesisID, note: makeUint8Array(Buffer.from(note, 'base64')), amount: parseInt(amt), @@ -546,7 +499,7 @@ module.exports = function getSteps(options) { 'default multisig transaction with parameters {int} {string}', async function (amt, note) { [this.pk] = this.accounts; - const result = await this.acl.getTransactionParams(); + const result = await this.v2Client.getTransactionParams().do(); this.msig = { version: 1, threshold: 1, @@ -557,9 +510,9 @@ module.exports = function getSteps(options) { from: algosdk.multisigAddress(this.msig), to: this.accounts[1], fee: result.fee, - firstRound: result.lastRound + 1, - lastRound: result.lastRound + 1000, - genesisHash: result.genesishashb64, + firstRound: result.firstRound, + lastRound: result.lastRound, + genesisHash: result.genesisHash, genesisID: result.genesisID, note: makeUint8Array(Buffer.from(note, 'base64')), amount: parseInt(amt), @@ -635,55 +588,14 @@ module.exports = function getSteps(options) { }); Then('the node should be healthy', async function () { - const health = await this.acl.healthCheck(); + const health = await this.v2Client.healthCheck().do(); assert.deepStrictEqual(health, makeObject({})); }); Then('I get the ledger supply', async function () { - return this.acl.ledgerSupply(); - }); - - Then('I get transactions by address and round', async function () { - const lastRound = await this.acl.status(); - const transactions = await this.acl.transactionByAddress( - this.accounts[0], - 1, - lastRound.lastRound - ); - assert.deepStrictEqual( - true, - Object.entries(transactions).length === 0 || - 'transactions' in transactions - ); + return this.v2Client.supply().do(); }); - Then('I get pending transactions', async function () { - const transactions = await this.acl.pendingTransactions(10); - assert.deepStrictEqual( - true, - Object.entries(transactions).length === 0 || - 'truncatedTxns' in transactions - ); - }); - - When('I get the suggested params', async function () { - this.params = await this.acl.getTransactionParams(); - return this.params; - }); - - When('I get the suggested fee', async function () { - this.fee = await this.acl.suggestedFee(); - this.fee = this.fee.fee; - return this.fee; - }); - - Then( - 'the fee in the suggested params should equal the suggested fee', - function () { - assert.deepStrictEqual(this.params.fee, this.fee); - } - ); - When('I create a bid', function () { let addr = algosdk.generateAccount(); this.sk = addr.sk; @@ -865,21 +777,23 @@ module.exports = function getSteps(options) { }); When('I send the transaction', async function () { - this.txid = await this.acl.sendRawTransaction(this.stx); - this.txid = this.txid.txId; + const txid = await this.v2Client.sendRawTransaction(this.stx).do(); + this.txid = txid.txId; + this.appTxid = txid; // Alias to use in waitForTransaction. return this.txid; }); When('I send the kmd-signed transaction', async function () { - this.txid = await this.acl.sendRawTransaction(this.stxKmd); - this.txid = this.txid.txId; + const txid = await this.v2Client.sendRawTransaction(this.stxKmd).do(); + this.txid = txid.txId; + this.appTxid = txid; // Alias to use in waitForTransaction. return this.txid; }); // eslint-disable-next-line consistent-return When('I send the multisig transaction', async function () { try { - this.txid = await this.acl.sendRawTransaction(this.stx); + this.txid = await this.v2Client.sendRawTransaction(this.stx).do(); this.err = false; return this.txid; } catch (e) { @@ -887,19 +801,6 @@ module.exports = function getSteps(options) { } }); - Then('the transaction should go through', async function () { - await waitForAlgodInDevMode(); - const info = await this.acl.pendingTransactionInformation(this.txid); - assert.deepStrictEqual(true, 'type' in info); - - // TODO: this needs to be modified/removed when v1 is no longer supported - // let localParams = await this.acl.getTransactionParams(); - // this.lastRound = localParams.lastRound; - // await waitForAlgodInDevMode(); - // info = await this.acl.transactionById(this.txid); - // assert.deepStrictEqual(true, 'type' in info); - }); - Then('the transaction should not go through', function () { assert.deepStrictEqual(true, this.err); }); @@ -1006,12 +907,8 @@ module.exports = function getSteps(options) { // return this.txid // }) - Then('I get account information', async function () { - return this.acl.accountInformation(this.accounts[0]); - }); - Then('I can get account information', async function () { - await this.acl.accountInformation(this.pk); + await this.v2Client.accountInformation(this.pk).do(); return this.kcl.deleteKey(this.handle, this.wallet_pswd, this.pk); }); @@ -1034,12 +931,12 @@ module.exports = function getSteps(options) { const from = this.accounts[0]; this.pk = from; - const result = await this.acl.getTransactionParams(); + const result = await this.v2Client.getTransactionParams().do(); const suggestedParams = { fee: result.fee, - firstRound: result.lastRound + 1, - lastRound: result.lastRound + 1000, - genesisHash: result.genesishashb64, + firstRound: result.firstRound, + lastRound: result.lastRound, + genesisHash: result.genesisHash, genesisID: result.genesisID, }; this.lastRound = result.lastRound; @@ -1094,12 +991,12 @@ module.exports = function getSteps(options) { 'default asset creation transaction with total issuance {int}', async function (issuance) { [this.assetTestFixture.creator] = this.accounts; - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const parsedIssuance = parseInt(issuance); const decimals = 0; const defaultFrozen = false; @@ -1160,12 +1057,12 @@ module.exports = function getSteps(options) { 'default-frozen asset creation transaction with total issuance {int}', async function (issuance) { [this.assetTestFixture.creator] = this.accounts; - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const parsedIssuance = parseInt(issuance); const decimals = 0; const defaultFrozen = true; @@ -1235,22 +1132,22 @@ module.exports = function getSteps(options) { } When('I update the asset index', async function () { - const accountResponse = await this.acl.accountInformation( - this.assetTestFixture.creator - ); - const heldAssets = accountResponse.thisassettotal; - let keys = Object.keys(heldAssets).map((key) => parseInt(key)); - keys = keys.sort(sortKeysAscending); - const assetIndex = keys[keys.length - 1]; + const accountResponse = await this.v2Client + .accountInformation(this.assetTestFixture.creator) + .do(); + const heldAssets = accountResponse['created-assets']; + let assetIds = heldAssets.map((asset) => asset.index); + assetIds = assetIds.sort(sortKeysAscending); + const assetIndex = assetIds[assetIds.length - 1]; // this is stored as a string so it can be used as a key later. this.assetTestFixture.index = assetIndex.toString(); }); When('I get the asset info', async function () { - this.assetTestFixture.queriedParams = await this.acl.assetInformation( - this.assetTestFixture.index - ); + this.assetTestFixture.queriedParams = await this.v2Client + .getAssetByID(this.assetTestFixture.index) + .do(); }); Then('the asset info should match the expected asset info', function () { @@ -1258,9 +1155,9 @@ module.exports = function getSteps(options) { assert.strictEqual( true, this.assetTestFixture.expectedParams[key] === - this.assetTestFixture.queriedParams[key] || + this.assetTestFixture.queriedParams.params[key] || typeof this.assetTestFixture.expectedParams[key] === 'undefined' || - typeof this.assetTestFixture.queriedParams[key] === 'undefined' + typeof this.assetTestFixture.queriedParams.params[key] === 'undefined' ); }); }); @@ -1269,12 +1166,12 @@ module.exports = function getSteps(options) { 'I create a no-managers asset reconfigure transaction', async function () { [this.assetTestFixture.creator] = this.accounts; - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; // if we truly supplied no managers at all, it would be an asset destroy txn // so leave one key written const manager = this.assetTestFixture.creator; @@ -1311,12 +1208,12 @@ module.exports = function getSteps(options) { When('I create an asset destroy transaction', async function () { [this.assetTestFixture.creator] = this.accounts; - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const genesisID = ''; const type = 'acfg'; @@ -1340,7 +1237,7 @@ module.exports = function getSteps(options) { Then('I should be unable to get the asset info', async function () { let failed = false; try { - await this.acl.assetInformation(this.assetTestFixture.index); + await this.v2Client.getAssetByID(this.assetTestFixture.index).do(); } catch (e) { failed = true; } @@ -1351,12 +1248,12 @@ module.exports = function getSteps(options) { 'I create a transaction for a second account, signalling asset acceptance', async function () { const accountToUse = this.accounts[1]; - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const genesisID = ''; const type = 'axfer'; @@ -1383,12 +1280,12 @@ module.exports = function getSteps(options) { When( 'I create a transaction transferring {int} assets from creator to a second account', async function (amount) { - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const genesisID = ''; const type = 'axfer'; @@ -1415,12 +1312,12 @@ module.exports = function getSteps(options) { When( 'I create a transaction transferring {int} assets from a second account to creator', async function (amount) { - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const genesisID = ''; const type = 'axfer'; @@ -1447,18 +1344,21 @@ module.exports = function getSteps(options) { Then( 'the creator should have {int} assets remaining', async function (expectedTotal) { - const accountInformation = await this.acl.accountInformation( - this.assetTestFixture.creator - ); - const assetsHeld = accountInformation.assets[this.assetTestFixture.index]; - assert.deepStrictEqual(assetsHeld.amount, parseInt(expectedTotal)); + const accountInformation = await this.v2Client + .accountInformation(this.assetTestFixture.creator) + .do(); + for (const asset of accountInformation.assets) { + if (asset['asset-id'] === this.assetTestFixture.index) { + assert.deepStrictEqual(asset.amount, parseInt(expectedTotal)); + } + } } ); When('I send the bogus kmd-signed transaction', async function () { this.err = false; try { - await this.acl.sendRawTransaction(this.stxKmd); + await this.v2Client.sendRawTransaction(this.stxKmd).do(); } catch (e) { this.err = true; } @@ -1467,12 +1367,12 @@ module.exports = function getSteps(options) { When( 'I create an un-freeze transaction targeting the second account', async function () { - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const freezer = this.assetTestFixture.creator; this.assetTestFixture.lastTxn = { @@ -1497,12 +1397,12 @@ module.exports = function getSteps(options) { When( 'I create a freeze transaction targeting the second account', async function () { - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const freezer = this.assetTestFixture.creator; this.assetTestFixture.lastTxn = { @@ -1527,12 +1427,12 @@ module.exports = function getSteps(options) { When( 'I create a transaction revoking {int} assets from a second account to creator', async function (amount) { - this.params = await this.acl.getTransactionParams(); + this.params = await this.v2Client.getTransactionParams().do(); this.fee = this.params.fee; - this.fv = this.params.lastRound; - this.lv = this.fv + 1000; + this.fv = this.params.firstRound; + this.lv = this.params.lastRound; this.note = undefined; - this.gh = this.params.genesishashb64; + this.gh = this.params.genesisHash; const genesisID = ''; const type = 'axfer';