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

Support new features from indexer 2.3.2 #296

Merged
merged 6 commits into from
Mar 18, 2021
Merged
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
unit:
node_modules/.bin/cucumber-js --tags "@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.tealsign or @unit.dryrun or @unit.applications or @unit.responses or @unit.transactions" tests/cucumber/features --require tests/cucumber/steps/index.js
node_modules/.bin/cucumber-js --tags "@unit.offline or @unit.algod or @unit.indexer or @unit.rekey or @unit.tealsign or @unit.dryrun or @unit.applications or @unit.responses or @unit.transactions or @unit.responses.231" tests/cucumber/features --require tests/cucumber/steps/index.js
integration:
node_modules/.bin/cucumber-js --tags "@algod or @assets or @auction or @kmd or @send or @template or @indexer or @rekey or @dryrun or @compile or @applications or @indexer.applications or @applications.verified" tests/cucumber/features --require tests/cucumber/steps/index.js
node_modules/.bin/cucumber-js --tags "@algod or @assets or @auction or @kmd or @send or @template or @indexer or @rekey or @dryrun or @compile or @applications or @indexer.applications or @applications.verified or @indexer.231" tests/cucumber/features --require tests/cucumber/steps/index.js

docker-test:
./tests/cucumber/docker/run_docker.sh
18 changes: 18 additions & 0 deletions src/client/v2/algod/algod.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const sab = require('./statusAfterBlock');
const sp = require('./suggestedParams');
const supply = require('./supply');
const versions = require('./versions');
const genesis = require('./genesis');
const proof = require('./proof');

class AlgodClient {
constructor(
Expand Down Expand Up @@ -157,6 +159,22 @@ class AlgodClient {
getApplicationByID(index) {
return new gapbid.GetApplicationByID(this.c, this.intDecoding, index);
}

/**
* Returns the entire genesis file.
*/
genesis() {
return new genesis.Genesis(this.c, this.intDecoding);
}

/**
* Get the proof for a given transaction in a round.
* @param {number} round The round in which the transaction appears.
* @param {string} txID The transaction ID for which to generate a proof.
*/
getProof(round, txID) {
return new proof.Proof(this.c, this.intDecoding, round, txID);
}
}

module.exports = { AlgodClient };
10 changes: 10 additions & 0 deletions src/client/v2/algod/genesis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { JSONRequest } = require('../jsonrequest');

class Genesis extends JSONRequest {
// eslint-disable-next-line no-underscore-dangle,class-methods-use-this
_path() {
return '/genesis';
}
}

module.exports = { Genesis };
16 changes: 16 additions & 0 deletions src/client/v2/algod/proof.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { JSONRequest } = require('../jsonrequest');

class Proof extends JSONRequest {
constructor(c, intDecoding, round, txID) {
super(c, intDecoding);
this.round = round;
this.txID = txID;
}

// eslint-disable-next-line no-underscore-dangle
_path() {
return `/v2/blocks/${this.round}/transactions/${this.txID}/proof`;
}
}

module.exports = { Proof };
9 changes: 9 additions & 0 deletions src/client/v2/indexer/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const lasb = require('./lookupAssetBalances');
const lasbid = require('./lookupAssetByID');
const last = require('./lookupAssetTransactions');
const lb = require('./lookupBlock');
const ltbid = require('./lookupTransactionByID');
const sfas = require('./searchForAssets');
const sfapp = require('./searchForApplications');
const sft = require('./searchForTransactions');
Expand Down Expand Up @@ -90,6 +91,14 @@ class IndexerClient {
return new lb.LookupBlock(this.c, this.intDecoding, round);
}

/**
* Returns information about the given transaction.
* @param {string} txID The ID of the transaction to look up.
*/
lookupTransactionByID(txID) {
return new ltbid.LookupTransactionByID(this.c, this.intDecoding, txID);
}

/**
* Returns information about the given account.
* @param {string} account The address of the account to look up.
Expand Down
7 changes: 7 additions & 0 deletions src/client/v2/indexer/lookupAccountByID.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ class LookupAccountByID extends JSONRequest {
return `/v2/accounts/${this.account}`;
}

// specific round to search
round(round) {
this.query.round = round;
return this;
}

// include all items including closed accounts, deleted applications, destroyed assets, opted-out asset holdings, and closed-out application localstates
includeAll(value = true) {
this.query['include-all'] = value;
return this;
}
}

module.exports = { LookupAccountByID };
6 changes: 3 additions & 3 deletions src/client/v2/indexer/lookupApplications.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class LookupApplications extends JSONRequest {
return `/v2/applications/${this.index}`;
}

// specific round to search
round(round) {
this.query.round = round;
// include all items including closed accounts, deleted applications, destroyed assets, opted-out asset holdings, and closed-out application localstates
includeAll(value = true) {
this.query['include-all'] = value;
return this;
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/client/v2/indexer/lookupAssetBalances.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class LookupAssetBalances extends JSONRequest {
this.query.next = nextToken;
return this;
}

// include all items including closed accounts, deleted applications, destroyed assets, opted-out asset holdings, and closed-out application localstates
includeAll(value = true) {
this.query['include-all'] = value;
return this;
}
}

module.exports = { LookupAssetBalances };
6 changes: 6 additions & 0 deletions src/client/v2/indexer/lookupAssetByID.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class LookupAssetByID extends JSONRequest {
_path() {
return `/v2/assets/${this.index}`;
}

// include all items including closed accounts, deleted applications, destroyed assets, opted-out asset holdings, and closed-out application localstates
includeAll(value = true) {
this.query['include-all'] = value;
return this;
}
}

module.exports = { LookupAssetByID };
15 changes: 15 additions & 0 deletions src/client/v2/indexer/lookupTransactionByID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { JSONRequest } = require('../jsonrequest');

class LookupTransactionByID extends JSONRequest {
constructor(c, intDecoding, txID) {
super(c, intDecoding);
this.txID = txID;
}

// eslint-disable-next-line no-underscore-dangle
_path() {
return `/v2/transactions/${this.txID}`;
}
}

module.exports = { LookupTransactionByID };
6 changes: 6 additions & 0 deletions src/client/v2/indexer/searchAccounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class SearchAccounts extends JSONRequest {
this.query['application-id'] = applicationID;
return this;
}

// include all items including closed accounts, deleted applications, destroyed assets, opted-out asset holdings, and closed-out application localstates
includeAll(value = true) {
this.query['include-all'] = value;
return this;
}
}

module.exports = { SearchAccounts };
12 changes: 6 additions & 6 deletions src/client/v2/indexer/searchForApplications.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ class SearchForApplications extends JSONRequest {
return this;
}

// specific round to search
round(round) {
this.query.round = round;
return this;
}

// token for pagination
nextToken(next) {
this.query.next = next;
Expand All @@ -29,6 +23,12 @@ class SearchForApplications extends JSONRequest {
this.query.limit = limit;
return this;
}

// include all items including closed accounts, deleted applications, destroyed assets, opted-out asset holdings, and closed-out application localstates
includeAll(value = true) {
this.query['include-all'] = value;
return this;
}
}

module.exports = { SearchForApplications };
6 changes: 6 additions & 0 deletions src/client/v2/indexer/searchForAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class SearchForAssets extends JSONRequest {
this.query.next = nextToken;
return this;
}

// include all items including closed accounts, deleted applications, destroyed assets, opted-out asset holdings, and closed-out application localstates
includeAll(value = true) {
this.query['include-all'] = value;
return this;
}
}

module.exports = { SearchForAssets };
8 changes: 8 additions & 0 deletions tests/cucumber/browser/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ window.makeUint8Array = function makeUint8Array(arg) {
window.makeEmptyObject = function makeEmptyObject() {
return {};
};

window.formatIncludeAll = function formatIncludeAll(includeAll) {
if (!['true', 'false'].includes(includeAll)) {
throw new Error(`Unknown value for includeAll: ${includeAll}`);
}

return includeAll === 'true';
};
69 changes: 69 additions & 0 deletions tests/cucumber/steps/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ function makeEmptyObject() {
return {};
}

function formatIncludeAll(includeAll) {
if (!['true', 'false'].includes(includeAll)) {
throw new Error(`Unknown value for includeAll: ${includeAll}`);
}

return includeAll === 'true';
}

const steps = {
given: {},
when: {},
Expand Down Expand Up @@ -3219,6 +3227,35 @@ module.exports = function getSteps(options) {
}
);

When(
'I use {int} to search for an account with {int}, {int}, {int}, {int}, {string}, {int}, {string} and token {string}',
async function (
clientNum,
assetIndex,
limit,
currencyGreater,
currencyLesser,
authAddr,
appID,
includeAll,
nextToken
) {
const ic = indexerIntegrationClients[clientNum];
integrationSearchAccountsResponse = await ic
.searchAccounts()
.assetID(assetIndex)
.currencyGreaterThan(currencyGreater)
.currencyLessThan(currencyLesser)
.limit(limit)
.authAddr(authAddr)
.applicationID(appID)
.includeAll(formatIncludeAll(includeAll))
.nextToken(nextToken)
.do();
this.responseForDirectJsonComparison = integrationSearchAccountsResponse;
}
);

Then(
'There are {int}, the first has {int}, {int}, {int}, {int}, {string}, {int}, {string}, {string}',
(
Expand Down Expand Up @@ -3435,6 +3472,20 @@ module.exports = function getSteps(options) {
}
);

When(
'I use {int} to search for applications with {int}, {int}, {string} and token {string}',
async function (clientNum, limit, appID, includeAll, token) {
const ic = indexerIntegrationClients[clientNum];
this.responseForDirectJsonComparison = await ic
.searchForApplications()
.limit(limit)
.index(appID)
.includeAll(formatIncludeAll(includeAll))
.nextToken(token)
.do();
}
);

When(
'I use {int} to lookup application with {int}',
async function (clientNum, appID) {
Expand All @@ -3445,6 +3496,24 @@ module.exports = function getSteps(options) {
}
);

When(
'I use {int} to lookup application with {int} and {string}',
async function (clientNum, appID, includeAll) {
const ic = indexerIntegrationClients[clientNum];
try {
this.responseForDirectJsonComparison = await ic
.lookupApplications(appID)
.includeAll(formatIncludeAll(includeAll))
.do();
} catch (err) {
if (err.status !== 404) {
throw err;
}
this.responseForDirectJsonComparison = err.response.body;
}
}
);

function sortKeys(x) {
// recursively sorts on keys, unless the passed object is an array of dicts that all contain the property 'key',
// in which case it sorts on the value corresponding to key 'key'
Expand Down