Skip to content
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,264 changes: 949 additions & 3,315 deletions example/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"author": "",
"license": "ISC",
"devDependencies": {
"qtest-js": "^0.4.1",
"qtest-js": "^0.5.0",
"jest": "^28.1.3"
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qtest-js",
"version": "0.4.3",
"version": "0.5.0",
"description": "eosio testing library",
"main": "dist/index.js",
"license": "MIT",
Expand Down
23 changes: 12 additions & 11 deletions src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { signatureProvider } from "./wallet";
import { Asset, Symbol as TokenSymbol } from "./asset";
import { Time } from "./time";
import { System } from "./system";
import { generateTapos } from "./utils";

export class Chain {
public coreSymbol: TokenSymbol;
Expand Down Expand Up @@ -152,21 +153,23 @@ export class Chain {
* @param {Action} action detail of action to push
* @param {boolean} broadcast Optional. Should broadcast this transaction to blockchain or not
* @param {boolean} sign Optional. should sign transaction or not
* @param {boolean} expireSeconds Optional. number of second transaction will expired
* @param {Object} tapos Optional. {blocksBehind: reference block number, expireSeconds: number of second transaction will expired}
* @return {Promise<TransactResult | ReadOnlyTransactResult | PushTransactionArgs>} transaction result
*
* @api public
*/

async pushAction(
action: Action,
broadcast: boolean = true,
sign: boolean = true,
expireSeconds: number = 120,
blocksBehind: number = 1
tapos: Object = {}
): Promise<TransactResult | ReadOnlyTransactResult | PushTransactionArgs> {
tapos =
JSON.stringify(tapos) === JSON.stringify({}) ? generateTapos() : tapos;
return this.api.transact(
{ actions: [action] },
{ broadcast, sign, expireSeconds, blocksBehind }
{ broadcast, sign, ...tapos }
);
}

Expand All @@ -176,7 +179,7 @@ export class Chain {
* @param {Action[]} actions detail of actions to push
* @param {boolean} broadcast Optional. Should broadcast this transaction to blockchain or not
* @param {boolean} sign Optional. should sign transaction or not
* @param {boolean} expireSeconds Optional. number of second transaction will expired
* @param {Object} tapos Optional. {blocksBehind: reference block number, expireSeconds: number of second transaction will expired}
* @return {Promise<TransactResult | ReadOnlyTransactResult | PushTransactionArgs>} transaction result
*
* @api public
Expand All @@ -185,13 +188,11 @@ export class Chain {
actions: Action[],
broadcast: boolean = true,
sign: boolean = true,
expireSeconds: number = 120,
blocksBehind: number = 1
tapos: Object = {}
): Promise<TransactResult | ReadOnlyTransactResult | PushTransactionArgs> {
return this.api.transact(
{ actions },
{ broadcast, sign, expireSeconds, blocksBehind }
);
tapos =
JSON.stringify(tapos) === JSON.stringify({}) ? generateTapos() : tapos;
return this.api.transact({ actions }, { broadcast, sign, ...tapos });
}

/**
Expand Down
1 change: 0 additions & 1 deletion src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class Contract {
authorization,
data,
};

// @ts-ignore
return this.account.chain.pushAction(action) as TransactResult;
};
Expand Down
9 changes: 6 additions & 3 deletions test/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { generateTapos } from "../src/utils";
import { TESTING_PUBLIC_KEY } from "../src/wallet";

describe("account test", () => {
let chain;
let account;
let chain: Chain;
let account: Account;
let chainName = process.env.CHAIN_NAME || "WAX";

beforeAll(async () => {
Expand Down Expand Up @@ -200,7 +200,10 @@ describe("account test", () => {
},
true,
true,
366
{
blocksBehind: 1,
expireSeconds: 366,
}
);
// @ts-ignore
expect(transaction.processed.action_traces[0].console).toBe(
Expand Down
2 changes: 1 addition & 1 deletion test/chain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Chain } from "../src/chain";
import { blockTimeToMs } from "../src/utils";

describe("chain test", () => {
let chain;
let chain: Chain;
let chainName = process.env.CHAIN_NAME || "WAX";

afterAll(async () => {
Expand Down
24 changes: 9 additions & 15 deletions test/contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Chain } from "../src/chain";
import { Chain, Contract, Account } from "../src";
import { expectAction, expectThrow, expectBalance } from "../src/assertion";

describe("account test", () => {
let chain;
let contract;
let chain: Chain;
let contract: Contract;
let chainName = process.env.CHAIN_NAME || "WAX";
let contractAccount, user1, user2, user3;
let contractAccount, user1, user2, user3: Account;

beforeAll(async () => {
chain = await Chain.setupChain(chainName);
Expand Down Expand Up @@ -51,12 +51,11 @@ describe("account test", () => {
[{ actor: user1.name, permission: "active" }]
);

const logTableRows = await contract.table.logs.get({
const lastRow = await contract.table.logs.getLastRow({
scope: user1.name,
});
const savedLogItem = logTableRows.rows[logTableRows.rows.length - 1];
expect(savedLogItem.value1).toBe(2291);
expect(savedLogItem.value2).toBe("98123");
expect(lastRow.value1).toBe(2291);
expect(lastRow.value2).toBe("98123");
}, 100000);
});

Expand All @@ -71,17 +70,16 @@ describe("account test", () => {
[{ actor: user1.name, permission: "active" }]
);

const logTableRows = await contract.table.logs.get({
const lastRow = await contract.table.logs.getLastRow({
scope: user1.name,
});
const savedLogItem = logTableRows.rows[logTableRows.rows.length - 1];
expectAction(
transaction,
contract.account.name,
"testlog",
{
user: user1.name,
id: savedLogItem.id,
id: lastRow.id,
value1: 123,
value2: "456789",
},
Expand All @@ -99,10 +97,6 @@ describe("account test", () => {
[{ actor: user1.name, permission: "active" }]
);

const logTableRows = await contract.table.logs.get({
scope: user1.name,
});
const savedLogItem = logTableRows.rows[logTableRows.rows.length - 1];
await expectAction(transaction, contract.account.name, "testlog");
await expect(
expectAction(transaction, contract.account.name, "testlog", {
Expand Down
6 changes: 3 additions & 3 deletions test/passingtime.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Chain } from "../src/index";
import { Chain, Account } from "../src/index";
import { expectAction, expectThrow } from "../src/assertion";
import { blockTimeToMs } from "../src/utils";

describe("account test", () => {
let chain;
let chain: Chain;
let passingtimeContract;
let chainName = process.env.CHAIN_NAME || "WAX";
let contractAccount;
let contractAccount: Account;

beforeAll(async () => {
chain = await Chain.setupChain(chainName);
Expand Down
6 changes: 3 additions & 3 deletions test/startchain.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { expectBalance } from "../src/assertion";
import { Chain } from "../src/chain";
import { Chain, Account } from "../src";
import { generateTapos } from "../src/utils";
import { TESTING_PUBLIC_KEY } from "../src/wallet";

describe("setup chain test", () => {
let chain;
let account;
let chain: Chain;
let account: Account;
let chainName = process.env.CHAIN_NAME || "WAX";

afterAll(async () => {
Expand Down
4 changes: 2 additions & 2 deletions test/system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { generateTapos } from "../src/utils";
import { TESTING_PUBLIC_KEY } from "../src/wallet";

describe("account test", () => {
let chain;
let account;
let chain: Chain;
let account: Account;
let chainName = process.env.CHAIN_NAME || "WAX";

beforeAll(async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/table.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Chain } from "../src/index";
import { Chain, Contract } from "../src/index";
import { expectAction, expectThrow } from "../src/assertion";

describe("account test", () => {
let chain;
let inittableContract;
let chain: Chain;
let inittableContract: Contract;
let chainName = process.env.CHAIN_NAME || "WAX";

beforeAll(async () => {
Expand Down
6 changes: 3 additions & 3 deletions test/wallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Chain } from "../src/chain";
import { Chain, Account } from "../src";
import { generateTapos } from "../src/utils";
import { importKey, signatureProvider, createKey } from "../src/wallet";

describe("test wallet", () => {
let chain;
let account;
let chain: Chain;
let account: Account;
let chainName = process.env.CHAIN_NAME || "WAX";

beforeAll(async () => {
Expand Down