Skip to content

Commit

Permalink
Sketch tests on mainnet (outcome parsing).
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Oct 7, 2024
1 parent 5b74913 commit 4e58c12
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { assert } from "chai";

Check failure on line 1 in src/transactionsOutcomeParsers/smartContractTransactionsOutcomeParser.main.net.spec.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'"../testutils/networkProviders"' has no exported member named 'createMainnetProvider'. Did you mean 'createLocalnetProvider'?
import { promises } from "fs";
import { createMainnetProvider } from "../testutils/networkProviders";
import { SmartContractTransactionsOutcomeParser } from "./smartContractTransactionsOutcomeParser";

describe("test smart contract transactions outcome parser on mainnet", () => {
const networkProvider = createMainnetProvider();
const parser = new SmartContractTransactionsOutcomeParser();

it("should parse (1)", async function () {
this.timeout(3600000);
await testRecords("src/testdata/transactions_01.mainnet.json");
});

it("should parse (2)", async function () {
this.timeout(3600000);
await testRecords("src/testdata/transactions_02.mainnet.json");
});

it("should parse (3)", async function () {
this.timeout(3600000);
await testRecords("src/testdata/transactions_02.mainnet.json");
});

async function testRecords(path: string) {
const content: string = await promises.readFile(path, { encoding: "utf8" });
const records = JSON.parse(content);

for (let i = 0; i < records.length; i++) {
const { hash, kind } = records[i];
const transactionOnNetwork = await networkProvider.getTransaction(hash);
const outcome = parser.parseExecute({ transactionOnNetwork });

console.log(i, hash, kind);
console.log(hash, transactionOnNetwork.function, outcome.returnCode, outcome.returnMessage, outcome.values);

if (kind == "simple_move_balance") {
assert.equal(outcome.returnCode, "");
assert.equal(outcome.returnMessage, "");
assert.lengthOf(outcome.values, 0);
} else if (kind == "relayed_error" || kind == "transfer_execute_error" || kind == "execute_error") {
assert.isTrue(outcome.returnCode.length > 0);
assert.isTrue(outcome.returnMessage.length > 0);
assert.lengthOf(outcome.values, 0);
} else if (kind == "relayed_success" || kind == "transfer_execute_success" || kind == "execute_success") {
assert.equal(outcome.returnCode, "ok");
assert.equal(outcome.returnMessage, "ok");
} else {
assert.fail("unknown kind");
}
}
}
});

0 comments on commit 4e58c12

Please sign in to comment.