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

Enhancement: Boxes Indexer Integration test #641

Merged
merged 14 commits into from
Sep 15, 2022
2 changes: 1 addition & 1 deletion .test-env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configs for testing repo download:
SDK_TESTING_URL="https://github.com/algorand/algorand-sdk-testing"
SDK_TESTING_BRANCH="feature/box-storage"
SDK_TESTING_BRANCH="ahangsu/indexer-integration-boxes"
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
SDK_TESTING_HARNESS="test-harness"

VERBOSE_HARNESS=0
Expand Down
1 change: 1 addition & 0 deletions tests/cucumber/integration.tags
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@algod
@applications
@applications.boxes
@applications.boxes_indexer_confirmed
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
@applications.verified
@assets
@auction
Expand Down
120 changes: 108 additions & 12 deletions tests/cucumber/steps/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ module.exports = function getSteps(options) {
this.v2Client = new algosdk.Algodv2(algodToken, 'http://localhost', 60000);
});

Given('an indexer v2 client', function () {
this.indexerV2client = new algosdk.Indexer('', 'http://localhost', 59999);
});

Given('wallet information', async function () {
this.wallet_name = 'unencrypted-default-wallet';
this.wallet_pswd = '';
Expand Down Expand Up @@ -4439,14 +4443,29 @@ module.exports = function getSteps(options) {
);

Then(
'the contents of the box with name {string} in the current application should be {string}. If there is an error it is {string}.',
async function (boxName, boxValue, errString) {
'according to {string}, the contents of the box with name {string} in the current application should be {string}. If there is an error it is {string}.',
async function (fromClient, boxName, boxValue, errString) {
try {
const boxKey = splitAndProcessAppArgs(boxName)[0];
const resp = await this.v2Client
.getApplicationBoxByName(this.currentApplicationIndex)
.name(boxKey)
.do();

let resp = null;
if (fromClient === 'algod') {
resp = await this.v2Client
.getApplicationBoxByName(this.currentApplicationIndex)
.name(boxKey)
.do();
} else if (fromClient === 'indexer') {
resp = await this.indexerV2client
.lookupApplicationBoxByIDandName(this.currentApplicationIndex)
.name(boxKey)
.do();
} else {
assert(
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
false,
''.join(['expecting algod or indexer, got ', fromClient])
);
}

const actualName = resp.name;
const actualValue = resp.value;
assert.deepStrictEqual(
Expand All @@ -4468,14 +4487,83 @@ module.exports = function getSteps(options) {
}
);

Then(
'the current application should have the following boxes {string}.',
async function (boxNames) {
const boxes = splitAndProcessAppArgs(boxNames);
function splitBoxNames(boxB64Names) {
if (boxB64Names == null || boxB64Names === '') {
return [];
}
const splitBoxB64Names = boxB64Names.split(':');
const boxNames = [];
splitBoxB64Names.forEach((subArg) => {
boxNames.push(makeUint8Array(Buffer.from(subArg, 'base64')));
});
return boxNames;
}

const resp = await this.v2Client
.getApplicationBoxes(this.currentApplicationIndex)
Then(
'according to indexer, by parameter max {int} and next {string}, the current application should have the following boxes {string}.',
async function (limit, nextPage, boxNames) {
const boxes = splitBoxNames(boxNames);
const resp = await this.indexerV2client
.searchForApplicationBoxes(this.currentApplicationIndex)
.limit(limit)
.nextToken(nextPage)
.do();

assert.deepStrictEqual(boxes.length, resp.boxes.length);
const actualBoxes = new Set(
resp.boxes.map((b) => Buffer.from(b.name, 'base64'))
);
const expectedBoxes = new Set(boxes.map(Buffer.from));
assert.deepStrictEqual(expectedBoxes, actualBoxes);
}
);

Then(
'according to {string}, by parameter max {int}, the current application should have {int} boxes.',
async function (fromClient, limit, expectedBoxNum) {
let resp = null;
if (fromClient === 'algod') {
resp = await this.v2Client
.getApplicationBoxes(this.currentApplicationIndex)
.max(limit)
.do();
} else if (fromClient === 'indexer') {
resp = await this.indexerV2client
.searchForApplicationBoxes(this.currentApplicationIndex)
.limit(limit)
.do();
} else {
assert(
false,
''.join(['expecting algod or indexer, got ', fromClient])
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
);
}

assert.deepStrictEqual(expectedBoxNum, resp.boxes.length);
}
);

Then(
'according to {string}, the current application should have the following boxes {string}.',
async function (fromClient, boxNames) {
const boxes = splitBoxNames(boxNames);

let resp = null;
if (fromClient === 'algod') {
resp = await this.v2Client
.getApplicationBoxes(this.currentApplicationIndex)
.do();
} else if (fromClient === 'indexer') {
resp = await this.indexerV2client
.searchForApplicationBoxes(this.currentApplicationIndex)
.do();
} else {
assert(
false,
''.join(['expecting algod or indexer, got ', fromClient])
ahangsu marked this conversation as resolved.
Show resolved Hide resolved
);
}

assert.deepStrictEqual(boxes.length, resp.boxes.length);
const actualBoxes = new Set(
resp.boxes.map((b) => Buffer.from(b.name, 'base64'))
Expand All @@ -4485,6 +4573,14 @@ module.exports = function getSteps(options) {
}
);

Then(
'I sleep for {int} milliseconds for indexer to digest things down.',
async (milliseconds) => {
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
await sleep(milliseconds);
}
);

Given('a source map json file {string}', async function (srcmap) {
const js = parseJSON(await loadResource(srcmap));
this.sourcemap = new algosdk.SourceMap(js);
Expand Down