diff --git a/test/package.json b/test/package.json index 8f36426958..f8e67cb16b 100644 --- a/test/package.json +++ b/test/package.json @@ -50,6 +50,7 @@ "codechain-sdk": "https://github.com/junha1/codechain-sdk-js#test2.0.1", "codechain-stakeholder-sdk": "https://github.com/junha1/codechain-stakeholder-sdk-js#master", "elliptic": "^6.4.1", + "foundry-rpc": "git://github.com/CodeChain-io/foundry-rpc-js.git#alpha", "lodash": "^4.17.11", "mkdirp": "^0.5.1", "ncp": "^2.0.0", diff --git a/test/src/e2e/account.test.ts b/test/src/e2e/account.test.ts index ce4519e7d3..b9e4e040aa 100644 --- a/test/src/e2e/account.test.ts +++ b/test/src/e2e/account.test.ts @@ -29,13 +29,14 @@ describe("account", function() { }); it("getList", async function() { - expect(await node.sdk.rpc.account.getList()).not.to.be.null; + expect(await node.rpc.account.getList()).not.to.be.null; }); it("create", async function() { - expect(await node.sdk.rpc.account.create()).not.to.be.null; - expect(await node.sdk.rpc.account.create("my-password")).not.to.be - .null; + expect(await node.rpc.account.create({ passphrase: "my-password" })) + .not.to.be.null; + expect(await node.rpc.account.create({ passphrase: "my-password" })) + .not.to.be.null; }); describe("importRaw", function() { @@ -53,26 +54,38 @@ describe("account", function() { { networkId: "tc" } ); expect( - await node.sdk.rpc.account.importRaw(randomSecret) + await node.rpc.account.importRaw({ + secret: "0x".concat(randomSecret), + passphrase: "" + }) ).to.equal(address.toString()); }); it("KeyError", async function() { try { - await node.sdk.rpc.account.importRaw(invalidSecret); + await node.rpc.account.importRaw({ + secret: "0x".concat(invalidSecret), + passphrase: "" + }); expect.fail(); } catch (e) { - expect(e).is.similarTo(ERROR.KEY_ERROR); + expect(e.toString()).is.include(ERROR.KEY_ERROR); } }); it("AlreadyExists", async function() { try { - await node.sdk.rpc.account.importRaw(randomSecret); - await node.sdk.rpc.account.importRaw(randomSecret); + await node.rpc.account.importRaw({ + secret: "0x".concat(randomSecret), + passphrase: null + }); + await node.rpc.account.importRaw({ + secret: "0x".concat(randomSecret), + passphrase: null + }); expect.fail(); } catch (e) { - expect(e).is.similarTo(ERROR.ALREADY_EXISTS); + expect(e.toString()).is.include(ERROR.ALREADY_EXISTS); } }); }); @@ -84,10 +97,10 @@ describe("account", function() { let secret: string; beforeEach(async function() { secret = node.sdk.util.generatePrivateKey(); - address = await node.sdk.rpc.account.importRaw( - secret, - "my-password" - ); + address = await node.rpc.account.importRaw({ + secret: "0x".concat(secret), + passphrase: "my-password" + }); }); it("Ok", async function() { @@ -95,37 +108,37 @@ describe("account", function() { message, secret ); - const signature = await node.sdk.rpc.account.sign( - message, - address, - "my-password" - ); + const signature = await node.rpc.account.sign({ + message: `0x${message}`, + account: address, + passphrase: "my-password" + }); expect(signature).to.equal(`0x${calculatedSignature}`); }); it("WrongPassword", async function() { try { - await node.sdk.rpc.account.sign( - message, - address, - "wrong-password" - ); + await node.rpc.account.sign({ + message: `0x${message}`, + account: address, + passphrase: "wrong-password" + }); expect.fail(); } catch (e) { - expect(e).is.similarTo(ERROR.WRONG_PASSWORD); + expect(e.toString()).is.include(ERROR.WRONG_PASSWORD); } }); it("NoSuchAccount", async function() { try { - await node.sdk.rpc.account.sign( - message, - invalidAddress, - "my-password" - ); + await node.rpc.account.sign({ + message: `0x${message}`, + account: invalidAddress, + passphrase: "my-password" + }); expect.fail(); } catch (e) { - expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT); + expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT); } }); }); @@ -133,30 +146,47 @@ describe("account", function() { describe("unlock", function() { let address: string; beforeEach(async function() { - address = await node.sdk.rpc.account.create("123"); + address = await node.rpc.account.create({ passphrase: "123" }); }); it("Ok", async function() { - await node.sdk.rpc.account.unlock(address, "123"); - await node.sdk.rpc.account.unlock(address, "123", 0); - await node.sdk.rpc.account.unlock(address, "123", 300); + await node.rpc.account.unlock({ + account: address, + passphrase: "123" + }); + await node.rpc.account.unlock({ + account: address, + passphrase: "123", + duration: 0 + }); + await node.rpc.account.unlock({ + account: address, + passphrase: "123", + duration: 300 + }); }); it("WrongPassword", async function() { try { - await node.sdk.rpc.account.unlock(address, "456"); + await node.rpc.account.unlock({ + account: address, + passphrase: "456" + }); expect.fail(); } catch (e) { - expect(e).is.similarTo(ERROR.WRONG_PASSWORD); + expect(e.toString()).is.include(ERROR.WRONG_PASSWORD); } }); it("NoSuchAccount", async function() { try { - await node.sdk.rpc.account.unlock(invalidAddress, "456"); + await node.rpc.account.unlock({ + account: invalidAddress.toString(), + passphrase: "456" + }); expect.fail(); } catch (e) { - expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT); + expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT); } }); }); @@ -164,38 +194,40 @@ describe("account", function() { describe("changePassword", function() { let address: string; beforeEach(async function() { - address = await node.sdk.rpc.account.create("123"); + address = await node.rpc.account.create({ passphrase: "123" }); }); it("Ok", async function() { - await node.sdk.rpc.sendRpcRequest("account_changePassword", [ - address, - "123", - "456" - ]); + await node.rpc.account.changePassword({ + account: address, + oldPassphrase: "123", + newPassphrase: "456" + }); }); it("WrongPassword", async function() { try { - await node.sdk.rpc.sendRpcRequest( - "account_changePassword", - [address, "456", "123"] - ); + await node.rpc.account.changePassword({ + account: address, + oldPassphrase: "456", + newPassphrase: "123" + }); expect.fail(); } catch (e) { - expect(e).is.similarTo(ERROR.WRONG_PASSWORD); + expect(e.toString()).is.include(ERROR.WRONG_PASSWORD); } }); it("NoSuchAccount", async function() { try { - await node.sdk.rpc.sendRpcRequest( - "account_changePassword", - [invalidAddress, "123", "345"] - ); + await node.rpc.account.changePassword({ + account: invalidAddress, + oldPassphrase: "123", + newPassphrase: "345" + }); expect.fail(); } catch (e) { - expect(e).is.similarTo(ERROR.NO_SUCH_ACCOUNT); + expect(e.toString()).is.include(ERROR.NO_SUCH_ACCOUNT); } }); }); diff --git a/test/src/e2e/basic.test.ts b/test/src/e2e/basic.test.ts index c67592e361..b9ef270cfb 100644 --- a/test/src/e2e/basic.test.ts +++ b/test/src/e2e/basic.test.ts @@ -17,6 +17,7 @@ import { expect } from "chai"; import "mocha"; import CodeChain from "../helper/spawn"; +import { log } from "util"; describe("solo - 1 node", function() { let node: CodeChain; @@ -26,19 +27,17 @@ describe("solo - 1 node", function() { }); it("ping", async function() { - expect(await node.sdk.rpc.node.ping()).to.equal("pong"); + expect(await node.rpc.ping()).to.contain("pong"); }); it("getNodeVersion", async function() { - expect(await node.sdk.rpc.node.getNodeVersion()).to.match( + expect(await node.rpc.version()).to.match( /^[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9.]*)?$/ ); }); it("getCommitHash", async function() { - expect(await node.sdk.rpc.node.getCommitHash()).to.match( - /^[a-fA-F0-9]{40}$/ - ); + expect(await node.rpc.commitHash()).to.match(/^[a-fA-F0-9]{40}$/); }); afterEach(function() { diff --git a/test/src/e2e/chain.test.ts b/test/src/e2e/chain.test.ts index eb3575a45a..d4a10adef3 100644 --- a/test/src/e2e/chain.test.ts +++ b/test/src/e2e/chain.test.ts @@ -26,6 +26,8 @@ import { invalidAddress } from "../helper/constants"; import CodeChain from "../helper/spawn"; +const RLP = require("rlp"); +import { toHex } from "codechain-sdk/lib/utils"; describe("chain", function() { const invalidH160 = H160.zero(); @@ -38,50 +40,46 @@ describe("chain", function() { }); it("getNetworkId", async function() { - expect(await node.sdk.rpc.chain.getNetworkId()).to.equal("tc"); + expect(await node.rpc.chain.getNetworkId()).to.equal("tc"); }); it("getBestBlockNumber", async function() { - expect(await node.sdk.rpc.chain.getBestBlockNumber()).to.be.a("number"); + expect(await node.rpc.chain.getBestBlockNumber()).to.be.a("number"); }); it("getPossibleAuthors", async function() { - expect( - await node.sdk.rpc.sendRpcRequest("chain_getPossibleAuthors", [ - null - ]) - ).be.null; + expect(await node.rpc.chain.getPossibleAuthors({ blockNumber: null })) + .be.null; }); it("getPossibleAuthors of the genesis block", async function() { expect( - await node.sdk.rpc.sendRpcRequest("chain_getPossibleAuthors", [0]) + await node.rpc.chain.getPossibleAuthors({ blockNumber: 0 }) ).deep.equal(["tccqyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhhn9p3"]); }); it("getBestBlockId", async function() { - const value = await node.sdk.rpc.sendRpcRequest( - "chain_getBestBlockId", - [] - ); - expect(value.hash).to.be.a("string"); - new H256(value.hash); - expect(value.number).to.be.a("number"); + const value = await node.rpc.chain.getBestBlockNumber(); + expect(value).to.be.a("number"); }); it("getBlockHash", async function() { - const bestBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - expect(await node.sdk.rpc.chain.getBlockHash(bestBlockNumber)).not.to.be - .null; - expect(await node.sdk.rpc.chain.getBlockHash(bestBlockNumber + 1)).to.be - .null; + const bestBlockNumber = await node.rpc.chain.getBestBlockNumber(); + expect( + await node.rpc.chain.getBlockHash({ blockNumber: bestBlockNumber }) + ).not.to.be.null; + expect( + await node.rpc.chain.getBlockHash({ + blockNumber: bestBlockNumber + 1 + }) + ).to.be.null; }); it("getBlockByHash", async function() { - const bestBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - const blockHash = await node.sdk.rpc.chain.getBlockHash( - bestBlockNumber - ); + const bestBlockNumber = await node.rpc.chain.getBestBlockNumber(); + const blockHash = await node.rpc.chain.getBlockHash({ + blockNumber: bestBlockNumber + }); expect( (await node.sdk.rpc.chain.getBlock(blockHash!))!.number ).to.equal(bestBlockNumber); @@ -89,33 +87,62 @@ describe("chain", function() { }); it("getSeq", async function() { - await node.sdk.rpc.chain.getSeq(faucetAddress); - expect(await node.sdk.rpc.chain.getSeq(invalidAddress)).to.equal(0); + await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }); + expect( + await node.rpc.chain.getSeq({ + address: invalidAddress, + blockNumber: null + }) + ).to.equal(0); const bestBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - await node.sdk.rpc.chain.getSeq(faucetAddress, 0); - await node.sdk.rpc.chain.getSeq(faucetAddress, bestBlockNumber); + await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: 0 + }); + await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: bestBlockNumber + }); await expect( - node.sdk.rpc.chain.getSeq(faucetAddress, bestBlockNumber + 1) - ).to.be.rejectedWith("chain_getSeq returns undefined"); + node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: bestBlockNumber + 1 + }) + ).to.be.empty; }); it("getBalance", async function() { - await node.sdk.rpc.chain.getBalance(faucetAddress); + await node.rpc.chain.getBalance({ + address: faucetAddress.toString(), + blockNumber: null + }); expect( - await node.sdk.rpc.chain.getBalance(invalidAddress) - ).to.deep.equal(new U64(0)); - const bestBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - await node.sdk.rpc.chain.getBalance(faucetAddress, 0); - await node.sdk.rpc.chain.getBalance(faucetAddress, bestBlockNumber); - await node.sdk.rpc.chain.getBalance(faucetAddress, bestBlockNumber + 1); + await node.rpc.chain.getBalance({ + address: invalidAddress.toString(), + blockNumber: null + }) + ).to.deep.include(new U64(0)); + const bestBlockNumber = await node.rpc.chain.getBestBlockNumber(); + await node.rpc.chain.getBalance({ + address: faucetAddress.toString(), + blockNumber: 0 + }); + await node.rpc.chain.getBalance({ + address: faucetAddress.toString(), + blockNumber: bestBlockNumber + }); + await node.rpc.chain.getBalance({ + address: faucetAddress.toString(), + blockNumber: bestBlockNumber + 1 + }); }); it("getGenesisAccounts", async function() { // FIXME: Add an API to SDK - const accounts = await node.sdk.rpc.sendRpcRequest( - "chain_getGenesisAccounts", - [] - ); + const accounts = await node.rpc.chain.getGenesisAccounts(); const expected = [ "tccqyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqyca3rwt", "tccqyqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgfrhflv", @@ -151,7 +178,10 @@ describe("chain", function() { recipient: "tccqxv9y4cw0jwphhu65tn4605wadyd2sxu5yezqghw", quantity: 0 }); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const hash = await node.sdk.rpc.chain.sendSignedTransaction( tx.sign({ secret: faucetSecret, @@ -159,7 +189,11 @@ describe("chain", function() { seq }) ); - expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(hash.toString()) + }) + ).be.true; const signed = await node.sdk.rpc.chain.getTransaction(hash); expect(signed).not.null; expect(signed!.unsigned).to.deep.equal(tx); @@ -170,7 +204,10 @@ describe("chain", function() { recipient: "tccqxv9y4cw0jwphhu65tn4605wadyd2sxu5yezqghw", quantity: 0 }); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const hash = await node.sdk.rpc.chain.sendSignedTransaction( tx.sign({ secret: faucetSecret, @@ -218,7 +255,10 @@ describe("chain", function() { .sign({ secret, fee: 10, - seq: await node.sdk.rpc.chain.getSeq(address) + seq: (await node.rpc.chain.getSeq({ + address: address.toString(), + blockNumber: null + }))! }); await node.sdk.rpc.chain.sendSignedTransaction(tx); @@ -251,43 +291,38 @@ describe("chain", function() { }); it("getNumberOfShards", async function() { - expect( - await node.sdk.rpc.sendRpcRequest("chain_getNumberOfShards", [null]) - ).to.equal(1); + expect(await node.rpc.chain.getNumberOfShards()).to.equal(1); expect( - await node.sdk.rpc.sendRpcRequest("chain_getNumberOfShards", [0]) + await node.rpc.chain.getNumberOfShards({ blockNumber: 0 }) ).to.equal(1); }); it("getShardRoot", async function() { - await node.sdk.rpc - .sendRpcRequest("chain_getShardRoot", [0, null]) - .then(result => { - expect(result).not.to.be.null; - H256.ensure(result); - }); - - await node.sdk.rpc - .sendRpcRequest("chain_getShardRoot", [0, 0]) - .then(result => { - expect(result).not.to.be.null; - H256.ensure(result); - }); - - await node.sdk.rpc - .sendRpcRequest("chain_getShardRoot", [10000, null]) - .then(result => { - expect(result).to.be.null; - }); + const result1 = (await node.rpc.chain.getShardRoot({ + shardId: 0, + blockNumber: null + }))!; + expect(result1).not.to.be.null; + H256.ensure(result1); + const result2 = (await node.rpc.chain.getShardRoot({ + shardId: 0, + blockNumber: 0 + }))!; + expect(result2).not.to.be.null; + H256.ensure(result2); + expect( + await node.rpc.chain.getShardRoot({ + shardId: 10000, + blockNumber: null + }) + ).to.be.null; }); it("getMiningReward", async function() { - await node.sdk.rpc - .sendRpcRequest("chain_getMiningReward", [0]) - .then(result => { - expect(result).to.equal(0); - }); + expect( + await node.rpc.chain.getMiningReward({ blockNumber: 0 }) + ).to.equal(0); }); afterEach(function() { diff --git a/test/src/e2e/changeParams.test.ts b/test/src/e2e/changeParams.test.ts index 810d9c1950..facaaa4b99 100644 --- a/test/src/e2e/changeParams.test.ts +++ b/test/src/e2e/changeParams.test.ts @@ -53,7 +53,11 @@ describe("ChangeParams", function() { quantity: 100_000, recipient: aliceAddress }); - expect(await node.sdk.rpc.chain.containsTransaction(tx.hash())).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(tx.hash().toString()) + }) + ).be.true; }); it("change", async function() { @@ -98,15 +102,21 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }) ); - expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(hash.toString()) + }) + ).be.true; } await expect(node.sendPayTx({ fee: 10 })).rejectedWith(/Too Low Fee/); - const params = await node.sdk.rpc.sendRpcRequest( "chain_getCommonParams", [null] @@ -154,7 +164,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); await expect(node.sdk.rpc.chain.sendSignedTransaction(tx)).rejectedWith( @@ -205,9 +218,12 @@ describe("ChangeParams", function() { changeParams.push(`0x${node.sdk.util.signEcdsa(message, carolSecret)}`); { - await node.sdk.rpc.devel.stopSealing(); - const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + await node.rpc.devel!.stopSealing(); + const blockNumber = await node.rpc.chain.getBestBlockNumber(); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const changeHash = await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createCustomTransaction({ @@ -221,12 +237,18 @@ describe("ChangeParams", function() { }) ); const pay = await node.sendPayTx({ seq: seq + 1, fee: 10 }); - await node.sdk.rpc.devel.startSealing(); - expect(await node.sdk.rpc.chain.containsTransaction(changeHash)).be - .true; - expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be - .true; - expect(await node.sdk.rpc.chain.getBestBlockNumber()).equal( + await node.rpc.devel!.startSealing(); + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(changeHash.toString()) + }) + ).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(pay.hash().toString()) + }) + ).be.true; + expect(await node.rpc.chain.getBestBlockNumber()).equal( blockNumber + 1 ); } @@ -309,9 +331,12 @@ describe("ChangeParams", function() { ); { - await node.sdk.rpc.devel.stopSealing(); - const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + await node.rpc.devel!.stopSealing(); + const blockNumber = await node.rpc.chain.getBestBlockNumber(); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const changeHash1 = await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createCustomTransaction({ @@ -336,19 +361,28 @@ describe("ChangeParams", function() { fee: 10 }) ); - await node.sdk.rpc.devel.startSealing(); - expect(await node.sdk.rpc.chain.containsTransaction(changeHash1)).be - .true; - expect(await node.sdk.rpc.chain.containsTransaction(changeHash2)).be - .true; - expect(await node.sdk.rpc.chain.getBestBlockNumber()).equal( + await node.rpc.devel!.startSealing(); + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(changeHash1.toString()) + }) + ).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(changeHash2.toString()) + }) + ).be.true; + expect(await node.rpc.chain.getBestBlockNumber()).equal( blockNumber + 1 ); } const pay = await node.sendPayTx({ fee: 5 }); - expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be - .true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(pay.hash().toString()) + }) + ).be.true; await expect(node.sendPayTx({ fee: 4 })).rejectedWith(/Too Low Fee/); }); @@ -427,9 +461,12 @@ describe("ChangeParams", function() { ); { - await node.sdk.rpc.devel.stopSealing(); + await node.rpc.devel!.stopSealing(); const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const changeHash1 = await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createCustomTransaction({ @@ -454,19 +491,28 @@ describe("ChangeParams", function() { fee: 10 }) ); - await node.sdk.rpc.devel.startSealing(); - expect(await node.sdk.rpc.chain.containsTransaction(changeHash1)).be - .true; - expect(await node.sdk.rpc.chain.containsTransaction(changeHash2)).be - .true; - expect(await node.sdk.rpc.chain.getBestBlockNumber()).equal( + await node.rpc.devel!.startSealing(); + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(changeHash1.toString()) + }) + ).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(changeHash2.toString()) + }) + ).be.true; + expect(await node.rpc.chain.getBestBlockNumber()).equal( blockNumber + 1 ); } const pay = await node.sendPayTx({ fee: 5 }); - expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be - .true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(pay.hash().toString()) + }) + ).be.true; await expect(node.sendPayTx({ fee: 4 })).rejectedWith(/Too Low Fee/); }); @@ -512,11 +558,18 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }) ); - expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(hash.toString()) + }) + ).be.true; } { @@ -529,8 +582,10 @@ describe("ChangeParams", function() { .sign({ secret: faucetSecret, seq: - (await node.sdk.rpc.chain.getSeq(faucetAddress)) + - 1, + (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))! + 1, fee: 10 }), { error: "Invalid transaction seq Expected 1, found 0" } @@ -578,7 +633,11 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: (await node.sdk.rpc.chain.getSeq(faucetAddress)) + 1, + seq: + (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))! + 1, fee: 10 }); await node.sendSignedTransactionExpectedToFail(tx, { @@ -632,7 +691,11 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: (await node.sdk.rpc.chain.getSeq(faucetAddress)) + 1, + seq: + (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))! + 1, fee: 10 }); await node.sendSignedTransactionExpectedToFail(tx, { @@ -657,11 +720,18 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); const hash = await node.sdk.rpc.chain.sendSignedTransaction(tx); - expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(hash.toString()) + }) + ).be.true; expect(await node.sdk.rpc.chain.getTransaction(hash)).not.be.null; } @@ -715,12 +785,18 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }) ); - expect(await node.sdk.rpc.chain.containsTransaction(hash)).be - .true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: "0x".concat(hash.toString()) + }) + ).be.true; } await expect(node.sendPayTx({ fee: 10 })).rejectedWith( @@ -787,7 +863,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); await expect( @@ -848,7 +927,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); await expect( @@ -909,7 +991,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); await expect( @@ -970,7 +1055,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); try { @@ -1035,7 +1123,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); await expect( @@ -1096,7 +1187,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); await expect( @@ -1157,7 +1251,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); await expect( @@ -1218,7 +1315,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); await expect( @@ -1279,7 +1379,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); try { @@ -1344,7 +1447,10 @@ describe("ChangeParams", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); try { @@ -1382,7 +1488,11 @@ async function sendStakeToken(params: { senderSecret, quantity } = params; - const { seq = await node.sdk.rpc.chain.getSeq(senderAddress) } = params; + const { + seq = (await node.rpc.chain.getSeq({ + address: senderAddress.toString() + }))! + } = params; return node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core diff --git a/test/src/e2e/customAction.test.ts b/test/src/e2e/customAction.test.ts index 2d199719f0..15b850e200 100644 --- a/test/src/e2e/customAction.test.ts +++ b/test/src/e2e/customAction.test.ts @@ -32,6 +32,9 @@ const expect = chai.expect; const RLP = require("rlp"); +const hitcount = toHex(RLP.encode(["hit count"])); +const closecount = toHex(RLP.encode(["close count"])); +const nonexistingkey = toHex(RLP.encode(["non-existing-key"])); describe("customAction", function() { let node: CodeChain; @@ -42,27 +45,32 @@ describe("customAction", function() { describe("customAction", function() { it("should get initial state", async function() { - const actionData = await node.sdk.rpc.engine.getCustomActionData( - hitActionHandlerId, - ["hit count"] - ); + const actionData = await node.rpc.engine.getCustomActionData({ + handlerId: hitActionHandlerId, + bytes: `0x${hitcount}`, + blockNumber: null + }); expect(actionData).to.be.equal(toHex(RLP.encode(1))); }); it("should alter state", async function() { - const previousHitData = (await node.sdk.rpc.engine.getCustomActionData( - hitActionHandlerId, - ["hit count"] - ))!; + const previousHitData = (await node.rpc.engine.getCustomActionData({ + handlerId: hitActionHandlerId, + bytes: `0x${hitcount}`, + blockNumber: null + }))!; const previousHitCount = Buffer.from( previousHitData, "hex" ).readUInt8(0); - const previousBlockCloseData = (await node.sdk.rpc.engine.getCustomActionData( - hitActionHandlerId, - ["close count"] + const previousBlockCloseData = (await node.rpc.engine.getCustomActionData( + { + handlerId: hitActionHandlerId, + bytes: `0x${closecount}`, + blockNumber: null + } ))!; const previousBlockCloseCount = Buffer.from( previousBlockCloseData, @@ -78,59 +86,75 @@ describe("customAction", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }) ); - expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${hash.toString()}` + }) + ).be.true; expect(await node.sdk.rpc.chain.getTransaction(hash)).not.null; - const hitData = await node.sdk.rpc.engine.getCustomActionData( - hitActionHandlerId, - ["hit count"] - ); + const hitData = (await node.rpc.engine.getCustomActionData({ + handlerId: hitActionHandlerId, + bytes: `0x${hitcount}`, + blockNumber: null + }))!; expect(hitData).to.be.equal( toHex(RLP.encode(previousHitCount + increment)) ); - const closeData = await node.sdk.rpc.engine.getCustomActionData( - hitActionHandlerId, - ["close count"] - ); + const closeData = (await node.rpc.engine.getCustomActionData({ + handlerId: hitActionHandlerId, + bytes: `0x${closecount}`, + blockNumber: null + }))!; expect(closeData).to.be.equal( toHex(RLP.encode(previousBlockCloseCount + 1)) ); }); it("should return null", async function() { - const actionData = await node.sdk.rpc.engine.getCustomActionData( - hitActionHandlerId, - ["non-existing-key"] - ); + const actionData = await node.rpc.engine.getCustomActionData({ + handlerId: hitActionHandlerId, + bytes: `0x${nonexistingkey}`, + blockNumber: null + }); expect(actionData).to.be.null; }); it("should throw state not exist", async function() { try { - await node.sdk.rpc.engine.getCustomActionData( - hitActionHandlerId, - ["hit count"], - 99999 - ); + await node.rpc.engine.getCustomActionData({ + handlerId: hitActionHandlerId, + bytes: `0x${hitcount}`, + blockNumber: 99999 + }); fail(); } catch (e) { - expect(e).similarTo(ERROR.STATE_NOT_EXIST); + expect(e.toString()).include(ERROR.STATE_NOT_EXIST); } }); it("should throw handler not found on getCustomActionData", async function() { try { - await node.sdk.rpc.engine.getCustomActionData(999999, []); + await node.rpc.engine.getCustomActionData({ + handlerId: 999999, + bytes: `0x${toHex(RLP.encode([]))}`, + blockNumber: null + }); fail(); } catch (e) { - expect(e).similarTo(ERROR.ACTION_DATA_HANDLER_NOT_FOUND); + expect(e.toString()).include( + ERROR.ACTION_DATA_HANDLER_NOT_FOUND + ); } }); @@ -144,7 +168,10 @@ describe("customAction", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }) ); @@ -155,8 +182,11 @@ describe("customAction", function() { }); it("should fail on handling error", async function() { - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); - const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; + const blockNumber = await node.rpc.chain.getBestBlockNumber(); expect( node.sdk.rpc.chain.sendSignedTransaction( diff --git a/test/src/e2e/engine.test.ts b/test/src/e2e/engine.test.ts index 6c58401a39..db7ee70b90 100644 --- a/test/src/e2e/engine.test.ts +++ b/test/src/e2e/engine.test.ts @@ -27,19 +27,12 @@ describe("engine", function() { it("getCoinbase", async function() { // TODO: Coinbase is not defined in solo mode, so it always returns null. Need to test in other modes. - expect( - await node.sdk.rpc.sendRpcRequest("engine_getCoinbase", []) - ).to.be.a("null"); + expect(await node.rpc.engine.getCoinbase()).to.be.a("null"); }); it("getRecommendedConfirmation", async function() { // TODO: The rcommended confirmation of solo is always 1. Need to test in other modes. - expect( - await node.sdk.rpc.sendRpcRequest( - "engine_getRecommendedConfirmation", - [] - ) - ).to.equal(1); + expect(await node.rpc.engine.getRecommendedConfirmation()).to.equal(1); }); afterEach(function() { diff --git a/test/src/e2e/mempool.test.ts b/test/src/e2e/mempool.test.ts index c7bc02641a..82c95e37b8 100644 --- a/test/src/e2e/mempool.test.ts +++ b/test/src/e2e/mempool.test.ts @@ -28,10 +28,10 @@ describe("Sealing test", function() { }); it("stopSealing then startSealing", async function() { - await node.sdk.rpc.devel.stopSealing(); + await node.rpc.devel!.stopSealing(); await node.sendPayTx(); expect(await node.getBestBlockNumber()).to.equal(0); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); expect(await node.getBestBlockNumber()).to.equal(1); }); @@ -52,18 +52,39 @@ describe("Future queue", function() { }); it("all pending transactions must be mined", async function() { - const seq = (await node.sdk.rpc.chain.getSeq(faucetAddress)) || 0; + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sendPayTx({ seq: seq + 3 }); - expect(await node.sdk.rpc.chain.getSeq(faucetAddress)).to.equal(seq); + expect( + (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))! + ).to.equal(seq); await node.sendPayTx({ seq: seq + 2 }); - expect(await node.sdk.rpc.chain.getSeq(faucetAddress)).to.equal(seq); + expect( + (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))! + ).to.equal(seq); await node.sendPayTx({ seq: seq + 1 }); - expect(await node.sdk.rpc.chain.getSeq(faucetAddress)).to.equal(seq); + expect( + (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))! + ).to.equal(seq); await node.sendPayTx({ seq: seq }); - expect(await node.sdk.rpc.chain.getSeq(faucetAddress)).to.equal( - seq + 4 - ); + expect( + (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))! + ).to.equal(seq + 4); }); afterEach(async function() { @@ -83,24 +104,23 @@ describe("Delete All Pending Transactions", function() { }); it("all pending transactions should be deleted", async function() { - await node.sdk.rpc.devel.stopSealing(); + await node.rpc.devel!.stopSealing(); - const sq = (await node.sdk.rpc.chain.getSeq(faucetAddress)) || 0; + const sq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sendPayTx({ seq: sq + 0 }); // will be in the current queue await node.sendPayTx({ seq: sq + 3 }); // will be in the future queue - - await node.sdk.rpc.sendRpcRequest( - "mempool_deleteAllPendingTransactions", - [] - ); + await node.rpc.mempool.deleteAllPendingTransactions(); const { transactions: wholeTXs - } = await node.sdk.rpc.sendRpcRequest( - "mempool_getPendingTransactions", - [null, null] - ); + } = await node.rpc.mempool.getPendingTransactions({ + from: null, + to: null + }); expect(wholeTXs.length).to.equal(0); }); diff --git a/test/src/e2e/network1.test.ts b/test/src/e2e/network1.test.ts index 4014b295cd..66473828c1 100644 --- a/test/src/e2e/network1.test.ts +++ b/test/src/e2e/network1.test.ts @@ -26,13 +26,13 @@ describe("network1 node test", function() { }); it(`default whitelist [], disabled`, async function() { - const { list, enabled } = await node.sdk.rpc.network.getWhitelist(); + const { list, enabled } = await node.rpc.net.getWhitelist(); expect(list).to.be.empty; expect(enabled).to.equal(false); }); it("default blacklist [], disabled", async function() { - const { list, enabled } = await node.sdk.rpc.network.getBlacklist(); + const { list, enabled } = await node.rpc.net.getBlacklist(); expect(list).to.be.empty; expect(enabled).to.equal(false); }); @@ -40,56 +40,56 @@ describe("network1 node test", function() { it("addToWhiteList and removeFromWhitelist", async function() { const target = "2.2.2.2"; - await node.sdk.rpc.network.addToWhitelist( - target, - "tag string for the target" - ); - let { list } = await node.sdk.rpc.network.getWhitelist(); + await node.rpc.net.addToWhitelist({ + address: target, + tag: "tag string for the target" + }); + let { list } = await node.rpc.net.getWhitelist(); expect(list).to.deep.include([ "2.2.2.2/32", "tag string for the target" ]); await node.sdk.rpc.network.removeFromWhitelist(target); - ({ list } = await node.sdk.rpc.network.getWhitelist()); + ({ list } = await node.rpc.net.getWhitelist()); expect(list).not.to.include(target); }); it("addToBlacklist and removeFromBlacklist", async function() { const target = "1.1.1.1"; - await node.sdk.rpc.network.addToBlacklist( - target, - "tag string for the target" - ); - let { list } = await node.sdk.rpc.network.getBlacklist(); + await node.rpc.net.addToBlacklist({ + address: target, + tag: "tag string for the target" + }); + let { list } = await node.rpc.net.getBlacklist(); expect(list).to.deep.include([ "1.1.1.1/32", "tag string for the target" ]); - await node.sdk.rpc.network.removeFromBlacklist(target); - ({ list } = await node.sdk.rpc.network.getBlacklist()); + await node.rpc.net.removeFromBlacklist({ address: target }); + ({ list } = await node.rpc.net.getBlacklist()); expect(list).not.to.include(target); }); it("enableWhitelist and disableWhitelist", async function() { - await node.sdk.rpc.network.enableWhitelist(); - let { enabled } = await node.sdk.rpc.network.getWhitelist(); + await node.rpc.net.enableWhitelist(); + let { enabled } = await node.rpc.net.getWhitelist(); expect(enabled).to.be.true; - await node.sdk.rpc.network.disableWhitelist(); - ({ enabled } = await node.sdk.rpc.network.getWhitelist()); + await node.rpc.net.disableWhitelist(); + ({ enabled } = await node.rpc.net.getWhitelist()); expect(enabled).to.be.false; }); it("enableBlacklist and disableBlacklist", async function() { - await node.sdk.rpc.network.enableBlacklist(); - let { enabled } = await node.sdk.rpc.network.getBlacklist(); + await node.rpc.net.enableBlacklist(); + let { enabled } = await node.rpc.net.getBlacklist(); expect(enabled).to.be.true; - await node.sdk.rpc.network.disableBlacklist(); - ({ enabled } = await node.sdk.rpc.network.getBlacklist()); + await node.rpc.net.disableBlacklist(); + ({ enabled } = await node.rpc.net.getBlacklist()); expect(enabled).to.be.false; }); diff --git a/test/src/e2e/network2.test.ts b/test/src/e2e/network2.test.ts index cb09ef7b28..435fda6e16 100644 --- a/test/src/e2e/network2.test.ts +++ b/test/src/e2e/network2.test.ts @@ -34,13 +34,22 @@ describe("network2 nodes", function() { this.timeout(60_000); // ensure disconnected if ( - !(await nodeA.sdk.rpc.network.isConnected(address, nodeB.port)) + !(await nodeA.rpc.net.isConnected({ + address: address.toString(), + port: nodeB.port + })) ) { return; } - await nodeA.sdk.rpc.network.disconnect(address, nodeB.port); + await nodeA.rpc.net.disconnect({ + address: address.toString(), + port: nodeB.port + }); while ( - await nodeA.sdk.rpc.network.isConnected(address, nodeB.port) + await nodeA.rpc.net.isConnected({ + address: address.toString(), + port: nodeB.port + }) ) { await wait(500); } @@ -51,14 +60,17 @@ describe("network2 nodes", function() { .be.null; while ( - !(await nodeA.sdk.rpc.network.isConnected(address, nodeB.port)) + !(await nodeA.rpc.net.isConnected({ + address: address.toString(), + port: nodeB.port + })) ) { await wait(500); } }); it("getPeerCount", async function() { - expect(await nodeA.sdk.rpc.network.getPeerCount()).to.equal(0); + expect(await nodeA.rpc.net.getPeerCount()).to.equal(0); }); it("getPeers", async function() { @@ -70,36 +82,58 @@ describe("network2 nodes", function() { beforeEach(async function() { this.timeout(60_000); // ensure connected - if (await nodeA.sdk.rpc.network.isConnected(address, nodeB.port)) { + if ( + await nodeA.rpc.net.isConnected({ + address: address.toString(), + port: nodeB.port + }) + ) { return; } - await nodeA.sdk.rpc.network.connect(address, nodeB.port); + await nodeA.rpc.net.connect({ + address: address.toString(), + port: nodeB.port + }); while ( - !(await nodeA.sdk.rpc.network.isConnected(address, nodeB.port)) + !(await nodeA.rpc.net.isConnected({ + address: address.toString(), + port: nodeB.port + })) ) { await wait(500); } }); it("isConnected", async function() { - expect(await nodeA.sdk.rpc.network.isConnected(address, nodeB.port)) - .to.be.true; + expect( + await nodeA.rpc.net.isConnected({ + address: address.toString(), + port: nodeB.port + }) + ).to.be.true; }); it("disconnect", async function() { - expect(await nodeA.sdk.rpc.network.disconnect(address, nodeB.port)) - .to.be.null; + expect( + await nodeA.rpc.net.disconnect({ + address: address.toString(), + port: nodeB.port + }) + ).to.be.undefined; while ( - await nodeA.sdk.rpc.network.isConnected(address, nodeB.port) + await nodeA.rpc.net.isConnected({ + address: address.toString(), + port: nodeB.port + }) ) { await wait(500); } }); it("getPeerCount", async function() { - expect(await nodeA.sdk.rpc.network.getPeerCount()).to.equal(1); - expect(await nodeB.sdk.rpc.network.getPeerCount()).to.equal(1); + expect(await nodeA.rpc.net.getPeerCount()).to.equal(1); + expect(await nodeB.rpc.net.getPeerCount()).to.equal(1); }); it("getPeers", async function() { diff --git a/test/src/e2e/pay.test.ts b/test/src/e2e/pay.test.ts index a580089cf2..9ea20ba58a 100644 --- a/test/src/e2e/pay.test.ts +++ b/test/src/e2e/pay.test.ts @@ -29,9 +29,16 @@ describe("Pay", async function() { it("Allow zero pay", async function() { const pay = await node.sendPayTx({ quantity: 0 }); - expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be - .true; - expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${pay.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${pay.hash().toString()}` + }) + ).not.null; }); it("Allow pay to itself", async function() { @@ -39,9 +46,16 @@ describe("Pay", async function() { quantity: 100, recipient: faucetAddress }); - expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be - .true; - expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${pay.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${pay.hash().toString()}` + }) + ).not.null; }); it("Cannot pay to regular key", async function() { @@ -49,13 +63,23 @@ describe("Pay", async function() { quantity: 100000, recipient: aliceAddress }); - expect(await node.sdk.rpc.chain.containsTransaction(charge.hash())).be - .true; - expect(await node.sdk.rpc.chain.getTransaction(charge.hash())).not.null; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${charge.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${charge.hash().toString()}` + }) + ).not.null; const privKey = node.sdk.util.generatePrivateKey(); const pubKey = node.sdk.util.getPublicFromPrivate(privKey); - const aliceSeq = await node.sdk.rpc.chain.getSeq(aliceAddress); + const aliceSeq = (await node.rpc.chain.getSeq({ + address: aliceAddress.toString(), + blockNumber: null + }))!; await node.setRegularKey(pubKey, { seq: aliceSeq, secret: aliceSecret @@ -64,10 +88,13 @@ describe("Pay", async function() { networkId: node.sdk.networkId }); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const blockNumber = await node.getBestBlockNumber(); - await node.sdk.rpc.devel.stopSealing(); + await node.rpc.devel!.stopSealing(); const pay = await node.sendPayTx({ quantity: 0, seq }); const fail = await node.sendPayTx({ @@ -76,16 +103,30 @@ describe("Pay", async function() { seq: seq + 1 }); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); await node.waitBlockNumber(blockNumber + 1); - expect(await node.sdk.rpc.chain.containsTransaction(pay.hash())).be - .true; - expect(await node.sdk.rpc.chain.getTransaction(pay.hash())).not.null; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${charge.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${pay.hash().toString()}` + }) + ).not.null; - expect(await node.sdk.rpc.chain.containsTransaction(fail.hash())).be - .false; - expect(await node.sdk.rpc.chain.getTransaction(fail.hash())).null; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${fail.hash().toString()}` + }) + ).be.false; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${fail.hash().toString()}` + }) + ).null; expect(await node.sdk.rpc.chain.getErrorHint(fail.hash())).not.null; }); diff --git a/test/src/e2e/regularkey.test.ts b/test/src/e2e/regularkey.test.ts index 231b8ce2e4..e16640031b 100644 --- a/test/src/e2e/regularkey.test.ts +++ b/test/src/e2e/regularkey.test.ts @@ -80,12 +80,15 @@ describe("solo - 1 node", function() { }); it("Try to use the master key instead of the regular key", async function() { - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); - const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - await node.sdk.rpc.devel.stopSealing(); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; + const blockNumber = await node.rpc.chain.getBestBlockNumber(); + await node.rpc.devel!.stopSealing(); const hash = await node.setRegularKey(pubKey, { seq }); const tx = await node.sendPayTx({ seq: seq + 1 }); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); await node.waitBlockNumber(blockNumber + 1); expect(await node.sdk.rpc.chain.getErrorHint(hash)).be.null; @@ -99,16 +102,19 @@ describe("solo - 1 node", function() { { networkId: "tc" } ).toString(); - await node.sdk.rpc.devel.stopSealing(); - const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + await node.rpc.devel!.stopSealing(); + const blockNumber = await node.rpc.chain.getBestBlockNumber(); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const tx1 = await node.sendPayTx({ quantity: 5, recipient: address, seq }); const hash2 = await node.setRegularKey(pubKey, { seq: seq + 1 }); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); await node.waitBlockNumber(blockNumber + 1); const block = (await node.sdk.rpc.chain.getBlock(blockNumber + 1))!; @@ -127,11 +133,14 @@ describe("solo - 1 node", function() { ).toString(); await node.sendPayTx({ quantity: 100, recipient: address }); - const seq = await node.sdk.rpc.chain.getSeq(address); + const seq = (await node.rpc.chain.getSeq({ + address: address.toString(), + blockNumber: null + }))!; const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - await node.sdk.rpc.devel.stopSealing(); + await node.rpc.devel!.stopSealing(); const hash1 = await node.setRegularKey(pubKey, { seq, secret: newPrivKey @@ -139,7 +148,7 @@ describe("solo - 1 node", function() { const hash2 = await node.setRegularKey(pubKey, { seq: seq + 1 }); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); await node.waitBlockNumber(blockNumber); diff --git a/test/src/e2e/reward.test.ts b/test/src/e2e/reward.test.ts index 955cd31dbe..da20c2cde3 100644 --- a/test/src/e2e/reward.test.ts +++ b/test/src/e2e/reward.test.ts @@ -23,14 +23,16 @@ import { bobAddress, carolAddress, daveAddress, + faucetAccointId, faucetAddress } from "../helper/constants"; import CodeChain from "../helper/spawn"; describe("Reward = 50, 1 miner", function() { + // FIXME: Change Number to U64 const MIN_FEE_PAY = 10; const BLOCK_REWARD = 50; - const FAUCET_INITIAL_CCS = new U64("18000000000000000000"); + const FAUCET_INITIAL_CCS = 18000000000000000000; let node: CodeChain; @@ -43,46 +45,66 @@ describe("Reward = 50, 1 miner", function() { }); it("Mining an empty block", async function() { - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); expect( - await node.sdk.rpc.chain.getBalance(faucetAddress) - ).to.deep.equal(FAUCET_INITIAL_CCS); - expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal( - new U64(BLOCK_REWARD) - ); - expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal( - new U64(0) - ); - expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal( - new U64(0) - ); - expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal( - new U64(0) - ); + +(await node.rpc.chain.getBalance({ + address: faucetAddress.toString() + }))! + ).to.equal(FAUCET_INITIAL_CCS); + expect( + +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))! + ).to.equal(BLOCK_REWARD); + expect( + +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))! + ).to.equal(0); + expect( + +(await node.rpc.chain.getBalance({ + address: carolAddress.toString() + }))! + ).to.equal(0); + expect( + +(await node.rpc.chain.getBalance({ + address: daveAddress.toString() + }))! + ).to.equal(0); }); it("Mining a block with 1 transaction", async function() { await node.sendPayTx({ fee: 10 }); expect( - await node.sdk.rpc.chain.getBalance(faucetAddress) - ).to.deep.equal(FAUCET_INITIAL_CCS.minus(10 /* fee */)); - expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal( - new U64(4 /* share */).plus(BLOCK_REWARD) - ); - expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal( - new U64(3 /* share */) - ); - expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal( - new U64(2 /* share */) - ); - expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal( - new U64(1 /* share */) - ); + +(await node.rpc.chain.getBalance({ + address: faucetAddress.toString() + }))! + ).to.equal(FAUCET_INITIAL_CCS - 10 /* fee */); + expect( + +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))! + ).to.equal(4 /* share */ + BLOCK_REWARD); + expect( + +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))! + ).to.deep.equal(3 /* share */); + expect( + +(await node.rpc.chain.getBalance({ + address: carolAddress.toString() + }))! + ).to.deep.equal(2 /* share */); + expect( + +(await node.rpc.chain.getBalance({ + address: daveAddress.toString() + }))! + ).to.deep.equal(1 /* share */); }); it("Mining a block with 3 transactions", async function() { - await node.sdk.rpc.devel.stopSealing(); + await node.rpc.devel!.stopSealing(); await node.sendPayTx({ fee: 10, seq: 0 @@ -95,79 +117,116 @@ describe("Reward = 50, 1 miner", function() { fee: 15, seq: 2 }); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); const TOTAL_FEE = 10 + 10 + 15; const TOTAL_MIN_FEE = MIN_FEE_PAY * 3; expect( - await node.sdk.rpc.chain.getBalance(faucetAddress) - ).to.deep.equal(FAUCET_INITIAL_CCS.minus(TOTAL_FEE)); - expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal( - new U64(Math.floor((TOTAL_MIN_FEE * 4) / 10) /* share */) - .plus(TOTAL_FEE) // block author get the remaining fee - .minus(Math.floor((TOTAL_MIN_FEE * 4) / 10)) - .minus(Math.floor((TOTAL_MIN_FEE * 3) / 10)) - .minus(Math.floor((TOTAL_MIN_FEE * 2) / 10)) - .minus(Math.floor((TOTAL_MIN_FEE * 1) / 10)) - .plus(BLOCK_REWARD) + +(await node.rpc.chain.getBalance({ + address: faucetAddress.toString() + }))! + ).to.deep.equal(FAUCET_INITIAL_CCS - TOTAL_FEE); + expect( + +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))! + ).to.equal( + Number(Math.floor((TOTAL_MIN_FEE * 4) / 10) /* share */) + + TOTAL_FEE - // block author get the remaining fee + Math.floor((TOTAL_MIN_FEE * 4) / 10) - + Math.floor((TOTAL_MIN_FEE * 3) / 10) - + Math.floor((TOTAL_MIN_FEE * 2) / 10) - + Math.floor((TOTAL_MIN_FEE * 1) / 10) + + BLOCK_REWARD ); - expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal( - new U64(Math.floor((TOTAL_MIN_FEE * 3) / 10) /* share */) + expect( + +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))! + ).to.deep.equal( + Number(Math.floor((TOTAL_MIN_FEE * 3) / 10) /* share */) ); - expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal( - new U64(Math.floor((TOTAL_MIN_FEE * 2) / 10) /* share */) + expect( + +(await node.rpc.chain.getBalance({ + address: carolAddress.toString() + }))! + ).to.deep.equal( + Number(Math.floor((TOTAL_MIN_FEE * 2) / 10) /* share */) ); - expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal( - new U64(Math.floor((TOTAL_MIN_FEE * 1) / 10) /* share */) + expect( + +(await node.rpc.chain.getBalance({ + address: daveAddress.toString() + }))! + ).to.deep.equal( + Number(Math.floor((TOTAL_MIN_FEE * 1) / 10) /* share */) ); }); it("Mining a block with a transaction that pays the author", async function() { await node.pay(aliceAddress, 100); expect( - await node.sdk.rpc.chain.getBalance(faucetAddress) - ).to.deep.equal( - FAUCET_INITIAL_CCS.minus(100 /* pay */).minus(10 /* fee */) - ); - expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal( - new U64(100 /* pay */) - .plus(Math.floor((10 * 4) / 10) /* share */) - .plus(BLOCK_REWARD) - ); - expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal( - new U64(Math.floor((10 * 3) / 10) /* share */) - ); - expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal( - new U64(Math.floor((10 * 2) / 10) /* share */) - ); - expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal( - new U64(Math.floor((10 * 1) / 10) /* share */) + +(await node.rpc.chain.getBalance({ + address: faucetAddress.toString() + }))! + ).to.equal(FAUCET_INITIAL_CCS + 100 /* pay */ - 10 /* fee */); + expect( + +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))! + ).to.equal( + Number( + 100 /* pay */ + + Math.floor((10 * 4) / 10) /* share */ + + BLOCK_REWARD + ) ); + expect( + +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))! + ).to.equal(Number(Math.floor((10 * 3) / 10) /* share */)); + expect( + +(await node.rpc.chain.getBalance({ + address: carolAddress.toString() + }))! + ).to.equal(Number(Math.floor((10 * 2) / 10) /* share */)); + expect( + +(await node.rpc.chain.getBalance({ + address: daveAddress.toString() + }))! + ).to.equal(Number(Math.floor((10 * 1) / 10) /* share */)); }); it("Mining a block with a transaction which author pays someone in", async function() { await node.sendPayTx({ fee: 10 }); - const faucetBalance = await node.sdk.rpc.chain.getBalance( - faucetAddress - ); - const aliceBalance = await node.sdk.rpc.chain.getBalance(aliceAddress); - const bobBalance = await node.sdk.rpc.chain.getBalance(bobAddress); - const carolBalance = await node.sdk.rpc.chain.getBalance(carolAddress); - const daveBalance = await node.sdk.rpc.chain.getBalance(daveAddress); - expect(faucetBalance).to.deep.equal( - FAUCET_INITIAL_CCS.minus(10 /* fee */) - ); - expect(aliceBalance).to.deep.equal( - new U64(Math.floor((10 * 4) / 10) /* share */).plus(BLOCK_REWARD) + const faucetBalance = +(await node.rpc.chain.getBalance({ + address: faucetAddress.toString() + }))!; + const aliceBalance = +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))!; + const bobBalance = +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))!; + const carolBalance = +(await node.rpc.chain.getBalance({ + address: carolAddress.toString() + }))!; + const daveBalance = +(await node.rpc.chain.getBalance({ + address: daveAddress.toString() + }))!; + + expect(faucetBalance).to.equal(FAUCET_INITIAL_CCS - 10 /* fee */); + expect(aliceBalance).to.equal( + Number(Math.floor((10 * 4) / 10)) /* share */ + BLOCK_REWARD ); - expect(bobBalance).to.deep.equal( - new U64(Math.floor((10 * 3) / 10) /* share */) + expect(bobBalance).to.equal( + Number(Math.floor((10 * 3) / 10) /* share */) ); - expect(carolBalance).to.deep.equal( - new U64(Math.floor((10 * 2) / 10) /* share */) + expect(carolBalance).to.equal( + Number(Math.floor((10 * 2) / 10) /* share */) ); - expect(daveBalance).to.deep.equal( - new U64(Math.floor((10 * 1) / 10) /* share */) + expect(daveBalance).to.equal( + Number(Math.floor((10 * 1) / 10) /* share */) ); const tx = await node.sdk.core @@ -179,24 +238,36 @@ describe("Reward = 50, 1 miner", function() { await node.sdk.rpc.chain.sendSignedTransaction(tx); expect( - await node.sdk.rpc.chain.getBalance(faucetAddress) - ).to.deep.equal(faucetBalance.plus(20 /* pay */)); - expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal( - aliceBalance - .minus(20 /* pay */) - .minus(10 /* fee */) - .plus(Math.floor((10 * 4) / 10) /* share */) - .plus(BLOCK_REWARD) - ); - expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal( - bobBalance.plus(Math.floor((10 * 3) / 10)) - ); - expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal( - carolBalance.plus(Math.floor((10 * 2) / 10)) - ); - expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal( - daveBalance.plus(Math.floor((10 * 1) / 10)) + +(await node.rpc.chain.getBalance({ + address: faucetAddress.toString() + }))! + ).to.deep.equal(faucetBalance + 20 /* pay */); + expect( + +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))! + ).to.deep.equal( + aliceBalance - + 20 /* pay */ - + 10 /* fee */ + + Math.floor((10 * 4) / 10) /* share */ + + BLOCK_REWARD ); + expect( + +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))! + ).to.deep.equal(Number(bobBalance) + Math.floor((10 * 3) / 10)); + expect( + +(await node.rpc.chain.getBalance({ + address: carolAddress.toString() + }))! + ).to.deep.equal(Number(carolBalance) + Math.floor((10 * 2) / 10)); + expect( + +(await node.rpc.chain.getBalance({ + address: daveAddress.toString() + }))! + ).to.deep.equal(Number(daveBalance) + Math.floor((10 * 1) / 10)); }); afterEach(async function() { diff --git a/test/src/e2e/reward1.test.ts b/test/src/e2e/reward1.test.ts index a33f006378..a4b2783c7d 100644 --- a/test/src/e2e/reward1.test.ts +++ b/test/src/e2e/reward1.test.ts @@ -32,43 +32,41 @@ describe("reward1", function() { }); it("getBlockReward", async function() { - // FIXME: Add an API to SDK - const reward = await node.sdk.rpc.sendRpcRequest( - "engine_getBlockReward", - [10] - ); + const reward = await node.rpc.engine.getBlockReward({ + blockNumber: 10 + }); expect(reward).to.equal(50); }); it("null if the block is not mined", async function() { - const bestBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); + const bestBlockNumber = await node.rpc.chain.getBestBlockNumber(); const nonMinedBlockNumber = bestBlockNumber + 10; - // FIXME: Add an API to SDK - const reward = await node.sdk.rpc.sendRpcRequest( - "chain_getMiningReward", - [nonMinedBlockNumber] - ); - expect(reward).to.equal(null); + expect( + await node.rpc.chain.getMiningReward({ + blockNumber: nonMinedBlockNumber + }) + ).to.equal(null); }); it("mining reward of the empty block is the same with the block reward", async function() { - await node.sdk.rpc.devel.startSealing(); - const bestBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); + await node.rpc.devel!.startSealing(); + const bestBlockNumber = await node.rpc.chain.getBestBlockNumber(); // FIXME: Add an API to SDK - const miningReward = await node.sdk.rpc.sendRpcRequest( - "chain_getMiningReward", - [bestBlockNumber] - ); - const blockReward = await node.sdk.rpc.sendRpcRequest( - "engine_getBlockReward", - [bestBlockNumber] - ); + const miningReward = await node.rpc.chain.getMiningReward({ + blockNumber: bestBlockNumber + }); + const blockReward = +(await node.rpc.engine.getBlockReward({ + blockNumber: bestBlockNumber + }))!; expect(miningReward).to.equal(blockReward); }); it("mining reward includes the block fee", async function() { - await node.sdk.rpc.devel.stopSealing(); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + await node.rpc.devel!.stopSealing(); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sendPayTx({ quantity: 10, fee: 123, @@ -84,17 +82,15 @@ describe("reward1", function() { fee: 321, seq: seq + 2 }); - await node.sdk.rpc.devel.startSealing(); - const bestBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); + await node.rpc.devel!.startSealing(); + const bestBlockNumber = await node.rpc.chain.getBestBlockNumber(); // FIXME: Add an API to SDK - const miningReward = await node.sdk.rpc.sendRpcRequest( - "chain_getMiningReward", - [bestBlockNumber] - ); - const blockReward = await node.sdk.rpc.sendRpcRequest( - "engine_getBlockReward", - [bestBlockNumber] - ); + const miningReward = await node.rpc.chain.getMiningReward({ + blockNumber: bestBlockNumber + }); + const blockReward = +(await node.rpc.engine.getBlockReward({ + blockNumber: bestBlockNumber + }))!; expect(miningReward).to.equal(blockReward + 123 + 456 + 321); }); diff --git a/test/src/e2e/shard.test.ts b/test/src/e2e/shard.test.ts index fcd8e235ab..f3f4381a43 100644 --- a/test/src/e2e/shard.test.ts +++ b/test/src/e2e/shard.test.ts @@ -38,7 +38,10 @@ describe.skip("CreateShard", function() { }); it("Create 1 shard", async function() { - const seq: number = (await node.sdk.rpc.chain.getSeq(faucetAddress))!; + const seq: number = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core @@ -49,49 +52,60 @@ describe.skip("CreateShard", function() { const tx = node.sdk.core .createCreateShardTransaction({ users: [aliceAddress] }) .sign({ secret: faucetSecret, seq: seq + 1, fee: 10 }); - const beforeBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); + const beforeBlockNumber = await node.rpc.chain.getBestBlockNumber(); expect( - await node.sdk.rpc.sendRpcRequest("chain_getShardIdByHash", [ - tx.hash(), - null - ]) + node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx.hash().toString()}`, + blockNumber: null + }) ).to.be.null; await node.sdk.rpc.chain.sendSignedTransaction(tx); - expect(await node.sdk.rpc.chain.containsTransaction(tx.hash())).be.true; - expect(await node.sdk.rpc.chain.getTransaction(tx.hash())).not.null; - const afterShardId = await node.sdk.rpc.sendRpcRequest( - "chain_getShardIdByHash", - [tx.hash(), null] - ); + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${tx.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${tx.hash().toString()}` + }) + ).not.null; + const afterShardId = (await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx.hash().toString()}`, + blockNumber: null + }))!; expect(afterShardId).not.to.be.null; - const shardOwners = await node.sdk.rpc.sendRpcRequest( - "chain_getShardOwners", - [afterShardId, null] - ); + const shardOwners = await node.rpc.chain.getShardOwners({ + shardId: afterShardId, + blockNumber: null + }); expect(shardOwners).to.deep.equal([faucetAddress.value]); // The creator becomes the owner. - const shardUsers = await node.sdk.rpc.sendRpcRequest( - "chain_getShardUsers", - [afterShardId, null] - ); + const shardUsers = await node.rpc.chain.getShardUsers({ + shardId: afterShardId, + blockNumber: null + }); expect(shardUsers).to.deep.equal([aliceAddress.value]); expect( - await node.sdk.rpc.sendRpcRequest("chain_getShardOwners", [ - afterShardId, - beforeBlockNumber - ]) + await node.rpc.chain.getShardOwners({ + shardId: afterShardId, + blockNumber: beforeBlockNumber + }) ).to.be.null; expect( - await node.sdk.rpc.sendRpcRequest("chain_getShardUsers", [ - afterShardId, - beforeBlockNumber - ]) + await node.rpc.chain.getShardUsers({ + shardId: afterShardId, + blockNumber: beforeBlockNumber + }) ).to.be.null; }); it("setShardUsers", async function() { - const seq: number = (await node.sdk.rpc.chain.getSeq(faucetAddress))!; + const seq: number = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createPayTransaction({ recipient: aliceAddress, quantity: 1 }) @@ -107,25 +121,27 @@ describe.skip("CreateShard", function() { .createCreateShardTransaction({ users: [aliceAddress] }) .sign({ secret: faucetSecret, seq: seq + 2, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(tx); - const shardId = await node.sdk.rpc.sendRpcRequest( - "chain_getShardIdByHash", - [tx.hash(), null] - ); - + const shardId = (await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx.hash().toString()}`, + blockNumber: null + }))!; const users = [aliceAddress, bobAddress]; const setShardUsers = node.sdk.core .createSetShardUsersTransaction({ shardId, users }) .sign({ secret: faucetSecret, seq: seq + 3, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(setShardUsers); - const shardUsers = await node.sdk.rpc.sendRpcRequest( - "chain_getShardUsers", - [shardId, null] - ); + const shardUsers = (await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx.hash().toString()}`, + blockNumber: null + }))!; expect(shardUsers).to.deep.equal(users.map(user => user.value)); }); it("setShardOwners", async function() { - const seq: number = (await node.sdk.rpc.chain.getSeq(faucetAddress))!; + const seq: number = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createPayTransaction({ recipient: aliceAddress, quantity: 1 }) @@ -140,25 +156,25 @@ describe.skip("CreateShard", function() { .createCreateShardTransaction({ users: [aliceAddress, bobAddress] }) .sign({ secret: faucetSecret, seq: seq + 2, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(tx); - const shardId = await node.sdk.rpc.sendRpcRequest( - "chain_getShardIdByHash", - [tx.hash(), null] - ); + const shardId = (await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx.hash().toString()}`, + blockNumber: null + }))!; const owners = [aliceAddress, faucetAddress, bobAddress]; const setShardOwners = node.sdk.core .createSetShardOwnersTransaction({ shardId, owners }) .sign({ secret: faucetSecret, seq: seq + 3, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(setShardOwners); - const shardOwners = await node.sdk.rpc.sendRpcRequest( - "chain_getShardOwners", - [shardId, null] - ); + const shardOwners = await node.rpc.chain.getShardOwners({ shardId })!; expect(shardOwners).to.deep.equal(owners.map(owner => owner.value)); }); it("Create 2 shards", async function() { - const seq: number = (await node.sdk.rpc.chain.getSeq(faucetAddress))!; + const seq: number = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createPayTransaction({ recipient: aliceAddress, quantity: 1 }) @@ -173,47 +189,62 @@ describe.skip("CreateShard", function() { .createCreateShardTransaction({ users: [aliceAddress, bobAddress] }) .sign({ secret: faucetSecret, seq: seq + 2, fee: 10 }); expect( - await node.sdk.rpc.sendRpcRequest("chain_getShardIdByHash", [ - tx1.hash(), - null - ]) + await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx1.hash().toString()}`, + blockNumber: null + }) ).to.be.null; await node.sdk.rpc.chain.sendSignedTransaction(tx1); - expect(await node.sdk.rpc.chain.containsTransaction(tx1.hash())).be - .true; - expect(await node.sdk.rpc.chain.getTransaction(tx1.hash())).not.null; expect( - await node.sdk.rpc.sendRpcRequest("chain_getShardIdByHash", [ - tx1.hash(), - null - ]) + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${tx1.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${tx1.hash().toString()}` + }) + ).not.null; + expect( + await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx1.hash().toString()}`, + blockNumber: null + }) ).not.to.be.null; const tx2 = node.sdk.core .createCreateShardTransaction({ users: [aliceAddress, bobAddress] }) .sign({ secret: faucetSecret, seq: seq + 3, fee: 10 }); expect( - await node.sdk.rpc.sendRpcRequest("chain_getShardIdByHash", [ - tx2.hash(), - null - ]) + await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx2.hash().toString()}`, + blockNumber: null + }) ).to.be.null; await node.sdk.rpc.chain.sendSignedTransaction(tx2); - expect(await node.sdk.rpc.chain.containsTransaction(tx2.hash())).be - .true; - expect(await node.sdk.rpc.chain.getTransaction(tx2.hash())).not.null; expect( - await node.sdk.rpc.sendRpcRequest("chain_getShardIdByHash", [ - tx2.hash(), - null - ]) + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${tx2.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${tx2.hash().toString()}` + }) + ).not.null; + expect( + await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx2.hash().toString()}`, + blockNumber: null + }) ).not.to.be.null; }); it("non-user cannot mint", async function() { - const faucetSeq: number = (await node.sdk.rpc.chain.getSeq( - faucetAddress - ))!; + const faucetSeq: number = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createPayTransaction({ recipient: aliceAddress, quantity: 1 }) @@ -228,10 +259,10 @@ describe.skip("CreateShard", function() { .createCreateShardTransaction({ users: [aliceAddress] }) .sign({ secret: faucetSecret, seq: faucetSeq + 2, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(createShard); - const shardId = await node.sdk.rpc.sendRpcRequest( - "chain_getShardIdByHash", - [createShard.hash(), null] - ); + const shardId = (await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${createShard.hash().toString()}`, + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createPayTransaction({ @@ -241,7 +272,10 @@ describe.skip("CreateShard", function() { .sign({ secret: faucetSecret, seq: faucetSeq + 3, fee: 10 }) ); - const bobSeq: number = (await node.sdk.rpc.chain.getSeq(bobAddress))!; + const bobSeq: number = (await node.rpc.chain.getSeq({ + address: bobAddress.toString(), + blockNumber: null + }))!; const pay = node.sdk.core .createPayTransaction({ recipient: aliceAddress, @@ -259,11 +293,11 @@ describe.skip("CreateShard", function() { }) .sign({ secret: bobSecret, seq: bobSeq + 1, fee: 10 }); - await node.sdk.rpc.devel.stopSealing(); - const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); + await node.rpc.devel!.stopSealing(); + const blockNumber = await node.rpc.chain.getBestBlockNumber(); await node.sdk.rpc.chain.sendSignedTransaction(pay); await node.sdk.rpc.chain.sendSignedTransaction(mint); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); await node.waitBlockNumber(blockNumber + 1); const hint = await node.sdk.rpc.chain.getErrorHint(mint.hash()); @@ -271,17 +305,18 @@ describe.skip("CreateShard", function() { }); it("user can mint", async function() { - const faucetSeq: number = (await node.sdk.rpc.chain.getSeq( - faucetAddress - ))!; + const faucetSeq: number = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const createShard = node.sdk.core .createCreateShardTransaction({ users: [aliceAddress] }) .sign({ secret: faucetSecret, seq: faucetSeq, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(createShard); - const shardId = await node.sdk.rpc.sendRpcRequest( - "chain_getShardIdByHash", - [createShard.hash(), null] - ); + const shardId = (await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${createShard.hash().toString()}`, + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createPayTransaction({ @@ -291,9 +326,10 @@ describe.skip("CreateShard", function() { .sign({ secret: faucetSecret, seq: faucetSeq + 1, fee: 10 }) ); - const aliceSeq: number = (await node.sdk.rpc.chain.getSeq( - aliceAddress - ))!; + const aliceSeq: number = (await node.rpc.chain.getSeq({ + address: aliceAddress.toString(), + blockNumber: null + }))!; const mint = node.sdk.core .createMintAssetTransaction({ scheme: { @@ -306,25 +342,33 @@ describe.skip("CreateShard", function() { .sign({ secret: aliceSecret, seq: aliceSeq, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(mint); - expect(await node.sdk.rpc.chain.containsTransaction(mint.hash())).be - .true; - expect(await node.sdk.rpc.chain.getTransaction(mint.hash())).not.null; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${mint.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${mint.hash().toString()}` + }) + ).not.null; const hint = await node.sdk.rpc.chain.getErrorHint(mint.hash()); expect(hint).to.be.null; }); it("non-user can mint after becoming a user", async function() { - const faucetSeq: number = (await node.sdk.rpc.chain.getSeq( - faucetAddress - ))!; + const faucetSeq: number = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const createShard = node.sdk.core .createCreateShardTransaction({ users: [aliceAddress] }) .sign({ secret: faucetSecret, seq: faucetSeq, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(createShard); - const shardId = await node.sdk.rpc.sendRpcRequest( - "chain_getShardIdByHash", - [createShard.hash(), null] - ); + const shardId = (await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${createShard.hash().toString()}`, + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createPayTransaction({ @@ -334,7 +378,10 @@ describe.skip("CreateShard", function() { .sign({ secret: faucetSecret, seq: faucetSeq + 1, fee: 10 }) ); - const bobSeq: number = (await node.sdk.rpc.chain.getSeq(bobAddress))!; + const bobSeq: number = (await node.rpc.chain.getSeq({ + address: bobAddress.toString(), + blockNumber: null + }))!; const recipient = await node.createP2PKHAddress(); const mint1 = node.sdk.core.createMintAssetTransaction({ scheme: { @@ -350,8 +397,8 @@ describe.skip("CreateShard", function() { fee: 30 }); - const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); - await node.sdk.rpc.devel.stopSealing(); + const blockNumber = await node.rpc.chain.getBestBlockNumber(); + await node.rpc.devel!.stopSealing(); await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core .createPayTransaction({ @@ -365,7 +412,7 @@ describe.skip("CreateShard", function() { }) ); await node.sdk.rpc.chain.sendSignedTransaction(signedMint1); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); await node.waitBlockNumber(blockNumber + 1); expect( await node.sdk.rpc.chain.getTransactionResultsByTracker( @@ -380,10 +427,7 @@ describe.skip("CreateShard", function() { .createSetShardUsersTransaction({ shardId, users: newUsers }) .sign({ secret: faucetSecret, seq: faucetSeq + 2, fee: 10 }); await node.sdk.rpc.chain.sendSignedTransaction(setShardUsers); - const shardUsers = await node.sdk.rpc.sendRpcRequest( - "chain_getShardUsers", - [shardId, null] - ); + const shardUsers = (await node.rpc.chain.getShardUsers({ shardId }))!; expect(shardUsers).to.deep.equal(newUsers.map(user => user.value)); const mint2 = node.sdk.core.createMintAssetTransaction({ @@ -402,10 +446,16 @@ describe.skip("CreateShard", function() { }); await node.sdk.rpc.chain.sendSignedTransaction(signedMint2); - expect(await node.sdk.rpc.chain.containsTransaction(signedMint2.hash())) - .be.true; - expect(await node.sdk.rpc.chain.getTransaction(signedMint2.hash())).not - .null; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${signedMint2.hash().toString()}` + }) + ).be.true; + expect( + await node.rpc.chain.getTransaction({ + transactionHash: `0x${signedMint2.hash().toString()}` + }) + ).not.null; expect( await node.sdk.rpc.chain.getTransactionResultsByTracker( mint2.tracker() @@ -428,7 +478,10 @@ describe.skip("Cannot create shard without allow-create-shard flag", function() }); it("Create 1 shard", async function() { - const seq: number = (await node.sdk.rpc.chain.getSeq(faucetAddress))!; + const seq: number = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; await node.sdk.rpc.chain.sendSignedTransaction( node.sdk.core @@ -440,19 +493,19 @@ describe.skip("Cannot create shard without allow-create-shard flag", function() .createCreateShardTransaction({ users: [aliceAddress] }) .sign({ secret: faucetSecret, seq: seq + 1, fee: 10 }); expect( - await node.sdk.rpc.sendRpcRequest("chain_getShardIdByHash", [ - tx.hash(), - null - ]) + await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx.hash().toString()}`, + blockNumber: null + }) ).be.null; expect(node.sdk.rpc.chain.sendSignedTransaction(tx)).be.rejected; expect(await node.sdk.rpc.chain.containsTransaction(tx.hash())).be .false; expect(await node.sdk.rpc.chain.getTransaction(tx.hash())).be.null; - const afterShardId = await node.sdk.rpc.sendRpcRequest( - "chain_getShardIdByHash", - [tx.hash(), null] - ); + const afterShardId = await node.rpc.chain.getShardIdByHash({ + transactionHash: `0x${tx.hash().toString()}`, + blockNumber: null + })!; expect(afterShardId).be.null; }); diff --git a/test/src/e2e/snapshot.test.ts b/test/src/e2e/snapshot.test.ts index d0b81f614d..81c8dc3890 100644 --- a/test/src/e2e/snapshot.test.ts +++ b/test/src/e2e/snapshot.test.ts @@ -41,9 +41,7 @@ describe("Snapshot", async function() { const blockHash = (await node.sdk.rpc.chain.getTransaction(pay.hash()))! .blockHash!; - await node.sdk.rpc.sendRpcRequest("devel_snapshot", [ - blockHash.toJSON() - ]); + await node.rpc.devel!.developSnapshot({ hash: blockHash.toJSON() })!; // Wait for 1 secs await new Promise(resolve => setTimeout(resolve, 1000)); diff --git a/test/src/e2e/staking.test.ts b/test/src/e2e/staking.test.ts index b770236818..f860437fe9 100644 --- a/test/src/e2e/staking.test.ts +++ b/test/src/e2e/staking.test.ts @@ -64,22 +64,32 @@ describe("Staking", function() { carolAddress, daveAddress ]; + const stackholderaddress = `0x${toHex( + RLP.encode(["StakeholderAddresses"]) + )}`; const amounts = await promiseExpect.shouldFulfill( "get customActionData", Promise.all( validatorAddresses.map(addr => - node.sdk.rpc.engine.getCustomActionData( - stakeActionHandlerId, - ["Account", addr.accountId.toEncodeObject()] - ) + node.rpc.engine.getCustomActionData({ + handlerId: stakeActionHandlerId, + bytes: `0x${toHex( + RLP.encode([ + "Account", + addr.accountId.toEncodeObject() + ]) + )}` + }) ) ) ); const stakeholders = await promiseExpect.shouldFulfill( "get customActionData", - node.sdk.rpc.engine.getCustomActionData(stakeActionHandlerId, [ - "StakeholderAddresses" - ]) + node.rpc.engine.getCustomActionData({ + handlerId: stakeActionHandlerId, + bytes: stackholderaddress, + blockNumber: null + }) ); return { amounts, stakeholders }; } @@ -98,10 +108,15 @@ describe("Staking", function() { "get customActionData", Promise.all( validatorAddresses.map(addr => - node.sdk.rpc.engine.getCustomActionData( - stakeActionHandlerId, - ["Delegation", addr.accountId.toEncodeObject()] - ) + node.rpc.engine.getCustomActionData({ + handlerId: stakeActionHandlerId, + bytes: `0x${toHex( + RLP.encode([ + "Delegation", + addr.accountId.toEncodeObject() + ]) + )}` + }) ) ) ); @@ -119,7 +134,9 @@ describe("Staking", function() { const { fee = 10 } = params; const seq = params.seq == null - ? await node.sdk.rpc.chain.getSeq(params.senderAddress) + ? (await node.rpc.chain.getSeq({ + address: params.senderAddress.toString() + }))! : params.seq; return promiseExpect.shouldFulfill( @@ -156,7 +173,9 @@ describe("Staking", function() { const { fee = 10 } = params; const seq = params.seq == null - ? await node.sdk.rpc.chain.getSeq(params.senderAddress) + ? (await node.rpc.chain.getSeq({ + address: params.senderAddress.toString() + }))! : params.seq; return promiseExpect.shouldFulfill( @@ -193,7 +212,9 @@ describe("Staking", function() { const { fee = 10 } = params; const seq = params.seq == null - ? await node.sdk.rpc.chain.getSeq(params.senderAddress) + ? (await node.rpc.chain.getSeq({ + address: params.senderAddress.toString() + }))! : params.seq; return promiseExpect.shouldFulfill( @@ -230,7 +251,9 @@ describe("Staking", function() { const { fee = 10, deposit, metadata } = params; const seq = params.seq == null - ? await node.sdk.rpc.chain.getSeq(params.senderAddress) + ? (await node.rpc.chain.getSeq({ + address: params.senderAddress.toString() + }))! : params.seq; return promiseExpect.shouldFulfill( @@ -261,7 +284,6 @@ describe("Staking", function() { toHex(RLP.encode(20000)), toHex(RLP.encode(10000)) ]); - expect(stakeholders).to.be.equal( toHex( RLP.encode([ @@ -485,12 +507,14 @@ describe("Staking", function() { quantity: 100 }); - await node.sdk.rpc.devel.stopSealing(); + await node.rpc.devel!.stopSealing(); await node.sendPayTx({ recipient: faucetAddress, secret: validator0Secret, quantity: 1, - seq: await node.sdk.rpc.chain.getSeq(validator0Address) + seq: (await node.rpc.chain.getSeq({ + address: validator0Address.toString() + }))! }); const hash = await revokeToken({ senderAddress: aliceAddress, @@ -498,7 +522,7 @@ describe("Staking", function() { delegateeAddress: validator0Address, quantity: 200 }); - await node.sdk.rpc.devel.startSealing(); + await node.rpc.devel!.startSealing(); expect(await node.sdk.rpc.chain.getErrorHint(hash)).not.to.be.null; @@ -593,57 +617,64 @@ describe("Staking", function() { ); const minCustomCost = require(chain).params.minCustomCost; - const oldAliceBalance = await node.sdk.rpc.chain.getBalance( - aliceAddress, - blockNumber - 1 - ); - const aliceBalance = await node.sdk.rpc.chain.getBalance(aliceAddress); + const oldAliceBalance = +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + // FIXME: Change Number to U64 + const aliceBalance = +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))!; expect(aliceBalance).to.be.deep.equal( - oldAliceBalance - .minus(fee) - .plus(Math.floor((minCustomCost * 2) / 10)) + oldAliceBalance - fee + Math.floor((minCustomCost * 2) / 10) ); - const oldBobBalance = await node.sdk.rpc.chain.getBalance( - bobAddress, - blockNumber - 1 - ); - const bobBalance = await node.sdk.rpc.chain.getBalance(bobAddress); + const oldBobBalance = +(await node.rpc.chain.getBalance({ + address: bobAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const bobBalance = +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))!; expect(bobBalance).to.be.deep.equal( - oldBobBalance.plus(Math.floor((minCustomCost * 3) / 10)) + oldBobBalance + Math.floor((minCustomCost * 3) / 10) ); - const oldCarolBalance = await node.sdk.rpc.chain.getBalance( - carolAddress, - blockNumber - 1 - ); - const carolBalance = await node.sdk.rpc.chain.getBalance(carolAddress); + const oldCarolBalance = +(await node.rpc.chain.getBalance({ + address: carolAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const carolBalance = +(await node.rpc.chain.getBalance({ + address: carolAddress.toString() + }))!; expect(carolBalance).to.be.deep.equal( - oldCarolBalance.plus(Math.floor((minCustomCost * 2) / 10)) + oldCarolBalance + Math.floor((minCustomCost * 2) / 10) ); - const oldDaveBalance = await node.sdk.rpc.chain.getBalance( - daveAddress, - blockNumber - 1 - ); - const daveBalance = await node.sdk.rpc.chain.getBalance(daveAddress); + const oldDaveBalance = +(await node.rpc.chain.getBalance({ + address: daveAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const daveBalance = +(await node.rpc.chain.getBalance({ + address: daveAddress.toString() + }))!; expect(daveBalance).to.be.deep.equal( - oldDaveBalance.plus(Math.floor((minCustomCost * 1) / 10)) + oldDaveBalance + Math.floor((minCustomCost * 1) / 10) ); - const oldValidator0Balance = await node.sdk.rpc.chain.getBalance( - validator0Address, - blockNumber - 1 - ); - const validator0Balance = await node.sdk.rpc.chain.getBalance( - validator0Address - ); + const oldValidator0Balance = +(await node.rpc.chain.getBalance({ + address: validator0Address.toString(), + blockNumber: blockNumber - 1 + }))!; + const validator0Balance = +(await node.rpc.chain.getBalance({ + address: validator0Address.toString() + }))!; expect(validator0Balance).to.be.deep.equal( - oldValidator0Balance - .plus(Math.floor((minCustomCost * 2) / 10)) - .plus(fee) - .minus(minCustomCost) - .plus(blockReward) + oldValidator0Balance + + Math.floor((minCustomCost * 2) / 10) + + fee - + minCustomCost + + blockReward ); }); @@ -702,65 +733,73 @@ describe("Staking", function() { ); const minCustomCost = require(chain).params.minCustomCost as number; - const oldAliceBalance = await node.sdk.rpc.chain.getBalance( - aliceAddress, - blockNumber - 1 - ); - const aliceBalance = await node.sdk.rpc.chain.getBalance(aliceAddress); + const oldAliceBalance = +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const aliceBalance = +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))!; expect(aliceBalance).to.be.deep.equal( - oldAliceBalance.plus(Math.floor((minCustomCost * 2) / 10)) + oldAliceBalance + Math.floor((minCustomCost * 2) / 10) ); - const oldBobBalance = await node.sdk.rpc.chain.getBalance( - bobAddress, - blockNumber - 1 - ); - const bobBalance = await node.sdk.rpc.chain.getBalance(bobAddress); + const oldBobBalance = +(await node.rpc.chain.getBalance({ + address: bobAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const bobBalance = +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))!; expect(bobBalance).to.be.deep.equal( - oldBobBalance.plus(Math.floor((minCustomCost * 3) / 10)) + oldBobBalance + Math.floor((minCustomCost * 3) / 10) ); - const oldCarolBalance = await node.sdk.rpc.chain.getBalance( - carolAddress, - blockNumber - 1 - ); - const carolBalance = await node.sdk.rpc.chain.getBalance(carolAddress); + const oldCarolBalance = +(await node.rpc.chain.getBalance({ + address: carolAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const carolBalance = +(await node.rpc.chain.getBalance({ + address: carolAddress.toString() + }))!; expect(carolBalance).to.be.deep.equal( - oldCarolBalance.plus(Math.floor((minCustomCost * 2) / 10)) + oldCarolBalance + Math.floor((minCustomCost * 2) / 10) ); - const oldDaveBalance = await node.sdk.rpc.chain.getBalance( - daveAddress, - blockNumber - 1 - ); - const daveBalance = await node.sdk.rpc.chain.getBalance(daveAddress); + const oldDaveBalance = +(await node.rpc.chain.getBalance({ + address: daveAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const daveBalance = +(await node.rpc.chain.getBalance({ + address: daveAddress.toString() + }))!; expect(daveBalance).to.be.deep.equal( - oldDaveBalance.plus(Math.floor((minCustomCost * 1) / 10)) + oldDaveBalance + Math.floor((minCustomCost * 1) / 10) ); - const oldValidator0Balance = await node.sdk.rpc.chain.getBalance( - validator0Address, - blockNumber - 1 - ); - const validator0Balance = await node.sdk.rpc.chain.getBalance( - validator0Address - ); + const oldValidator0Balance = +(await node.rpc.chain.getBalance({ + address: validator0Address.toString(), + blockNumber: blockNumber - 1 + }))!; + const validator0Balance = +(await node.rpc.chain.getBalance({ + address: validator0Address.toString() + }))!; expect(validator0Balance).to.be.deep.equal( - oldValidator0Balance - .plus(Math.floor((minCustomCost * 2) / 10)) - .minus(fee) - .plus(fee) - .minus(minCustomCost) - .plus(blockReward) - ); - - const oldValidator1Balance = await node.sdk.rpc.chain.getBalance( - validator1Address, - blockNumber - 1 - ); - const validator1Balance = await node.sdk.rpc.chain.getBalance( - validator1Address - ); + oldValidator0Balance + + Math.floor((minCustomCost * 2) / 10) - + fee + + fee - + minCustomCost + + blockReward + ); + + const oldValidator1Balance = +(await node.rpc.chain.getBalance({ + address: validator1Address.toString(), + blockNumber: blockNumber - 1 + }))!; + const validator1Balance = +(await node.rpc.chain.getBalance({ + address: validator1Address.toString() + }))!; expect(validator1Balance).to.be.deep.equal(oldValidator1Balance); }); @@ -829,58 +868,62 @@ describe("Staking", function() { ); const minCustomCost = require(chain).params.minCustomCost as number; - const oldAliceBalance = await node.sdk.rpc.chain.getBalance( - aliceAddress, - blockNumber - 1 - ); - const aliceBalance = await node.sdk.rpc.chain.getBalance(aliceAddress); + const oldAliceBalance = +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const aliceBalance = +(await node.rpc.chain.getBalance({ + address: aliceAddress.toString() + }))!; expect(aliceBalance).to.be.deep.equal( - oldAliceBalance.plus(Math.floor((minCustomCost * 1) / 10)) + oldAliceBalance + Math.floor((minCustomCost * 1) / 10) ); - const oldBobBalance = await node.sdk.rpc.chain.getBalance( - bobAddress, - blockNumber - 1 - ); - const bobBalance = await node.sdk.rpc.chain.getBalance(bobAddress); + const oldBobBalance = +(await node.rpc.chain.getBalance({ + address: bobAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const bobBalance = +(await node.rpc.chain.getBalance({ + address: bobAddress.toString() + }))!; expect(bobBalance).to.be.deep.equal( - oldBobBalance.plus(Math.floor((minCustomCost * 3) / 10)) + oldBobBalance + Math.floor((minCustomCost * 3) / 10) ); - const oldFaucetBalance = await node.sdk.rpc.chain.getBalance( - faucetAddress, - blockNumber - 1 - ); - const faucetBalance = await node.sdk.rpc.chain.getBalance( - faucetAddress - ); + const oldFaucetBalance = +(await node.rpc.chain.getBalance({ + address: faucetAddress.toString(), + blockNumber: blockNumber - 1 + }))!; + const faucetBalance = +(await node.rpc.chain.getBalance({ + address: faucetAddress.toString() + }))!; expect(faucetBalance).to.be.deep.equal(oldFaucetBalance); - const oldValidator0Balance = await node.sdk.rpc.chain.getBalance( - validator0Address, - blockNumber - 1 - ); - const validator0Balance = await node.sdk.rpc.chain.getBalance( - validator0Address - ); + const oldValidator0Balance = +(await node.rpc.chain.getBalance({ + address: validator0Address.toString(), + blockNumber: blockNumber - 1 + }))!; + const validator0Balance = +(await node.rpc.chain.getBalance({ + address: validator0Address.toString() + }))!; expect(validator0Balance).to.be.deep.equal( - oldValidator0Balance - .plus(Math.floor((minCustomCost * 2) / 10)) - .minus(fee) - .plus(fee) - .minus(minCustomCost) - .plus(blockReward) - ); - - const oldValidator1Balance = await node.sdk.rpc.chain.getBalance( - validator1Address, - blockNumber - 1 - ); - const validator1Balance = await node.sdk.rpc.chain.getBalance( - validator1Address - ); + oldValidator0Balance + + Math.floor((minCustomCost * 2) / 10) - + fee + + fee - + minCustomCost + + blockReward + ); + + const oldValidator1Balance = +(await node.rpc.chain.getBalance({ + address: validator1Address.toString(), + blockNumber: blockNumber - 1 + }))!; + const validator1Balance = +(await node.rpc.chain.getBalance({ + address: validator1Address.toString() + }))!; expect(validator1Balance).to.be.deep.equal( - oldValidator1Balance.plus(Math.floor((minCustomCost * 1) / 10)) + oldValidator1Balance + Math.floor((minCustomCost * 1) / 10) ); }); @@ -889,7 +932,9 @@ describe("Staking", function() { const pubKey = node.sdk.util.getPublicFromPrivate(privKey); await node.setRegularKey(pubKey, { - seq: await node.sdk.rpc.chain.getSeq(validator0Address), + seq: (await node.rpc.chain.getSeq({ + address: validator0Address.toString() + }))!, secret: validator0Secret }); diff --git a/test/src/e2e/termChange.test.ts b/test/src/e2e/termChange.test.ts index 7308d71f38..4fb5fcd8c6 100644 --- a/test/src/e2e/termChange.test.ts +++ b/test/src/e2e/termChange.test.ts @@ -46,7 +46,11 @@ describe("Term change", function() { quantity: 100_000, recipient: aliceAddress }); - expect(await node.sdk.rpc.chain.containsTransaction(tx.hash())).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${tx.hash().toString()}` + }) + ).be.true; }); async function changeTermSeconds(metadataSeq: number, termSeconds: number) { @@ -100,30 +104,36 @@ describe("Term change", function() { }) .sign({ secret: faucetSecret, - seq: await node.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }) ); - expect(await node.sdk.rpc.chain.containsTransaction(hash)).be.true; + expect( + await node.rpc.chain.containsTransaction({ + transactionHash: `0x${hash.toString()}` + }) + ).be.true; } } it("initial term metadata", async function() { - const params = await node.sdk.rpc.sendRpcRequest( - "chain_getTermMetadata", - [null] - ); + const params = (await node.rpc.chain.getTermMetadata({ + blockNumber: null + }))!; expect(params).to.be.deep.equals([0, 0]); }); async function waitForTermPeriodChange(termSeconds: number) { - const lastBlockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); + const lastBlockNumber = await node.rpc.chain.getBestBlockNumber(); const lastBlock = (await node.sdk.rpc.chain.getBlock(lastBlockNumber))!; let previousTs = lastBlock.timestamp; for (let count = 0; count < 20; count++) { - await node.sdk.rpc.devel.startSealing(); - const blockNumber = await node.sdk.rpc.chain.getBestBlockNumber(); + await node.rpc.devel!.startSealing(); + const blockNumber = await node.rpc.chain.getBestBlockNumber(); const block = (await node.sdk.rpc.chain.getBlock(blockNumber))!; const currentTs = block.timestamp; @@ -145,18 +155,16 @@ describe("Term change", function() { const blockNumber1 = await waitForTermPeriodChange(TERM_SECONDS); - const params1 = await node.sdk.rpc.sendRpcRequest( - "chain_getTermMetadata", - [blockNumber1] - ); + const params1 = (await node.rpc.chain.getTermMetadata({ + blockNumber: blockNumber1 + }))!; expect(params1).to.be.deep.equals([blockNumber1, 1]); const blockNumber2 = await waitForTermPeriodChange(TERM_SECONDS); - const params2 = await node.sdk.rpc.sendRpcRequest( - "chain_getTermMetadata", - [blockNumber2] - ); + const params2 = (await node.rpc.chain.getTermMetadata({ + blockNumber: blockNumber2 + }))!; expect(params2).to.be.deep.equals([blockNumber2, 2]); }).timeout(10_000); diff --git a/test/src/e2e/verification.test.ts b/test/src/e2e/verification.test.ts index 765350b1b1..5ff551553a 100644 --- a/test/src/e2e/verification.test.ts +++ b/test/src/e2e/verification.test.ts @@ -40,7 +40,10 @@ describe("solo - 1 node", function() { describe("Sending invalid transactions over the limits (general)", function() { let encoded: any[]; beforeEach(async function() { - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const tx = node.sdk.core .createPayTransaction({ recipient, @@ -178,7 +181,10 @@ describe("solo - 1 node", function() { describe("Sending invalid transactions over the limits (in action 2: Pay)", function() { let encoded: any[]; beforeEach(async function() { - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const signed = node.sdk.core .createPayTransaction({ recipient, @@ -232,7 +238,10 @@ describe("solo - 1 node", function() { beforeEach(async function() { const privKey = node.sdk.util.generatePrivateKey(); const key = node.sdk.util.getPublicFromPrivate(privKey); - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const signed = node.sdk.core .createSetRegularKeyTransaction({ key @@ -267,7 +276,10 @@ describe("solo - 1 node", function() { describe("Sending invalid transactions over the limits (in action 5: SetShardOwners)", function() { let encoded: any[]; beforeEach(async function() { - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const account = await node.createPlatformAddress(); const signed = node.sdk.core .createSetShardOwnersTransaction({ @@ -302,7 +314,10 @@ describe("solo - 1 node", function() { describe("Sending invalid transactions over the limits (in action 6: SetShardUsers)", function() { let encoded: any[]; beforeEach(async function() { - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const account = await node.createPlatformAddress(); const signed = node.sdk.core .createSetShardUsersTransaction({ @@ -336,7 +351,10 @@ describe("solo - 1 node", function() { [0, 9].forEach(function(fee) { it(`Sending invalid transactions (low fee): ${fee}`, async function() { - const seq = await node.sdk.rpc.chain.getSeq(faucetAddress); + const seq = (await node.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!; const signed = node.sdk.core .createPayTransaction({ recipient, diff --git a/test/src/helper/spawn.ts b/test/src/helper/spawn.ts index 40de53b090..5c58ae0964 100644 --- a/test/src/helper/spawn.ts +++ b/test/src/helper/spawn.ts @@ -33,6 +33,7 @@ import { AssetTransaction } from "codechain-sdk/lib/core/Transaction"; import { P2PKH } from "codechain-sdk/lib/key/P2PKH"; import { P2PKHBurn } from "codechain-sdk/lib/key/P2PKHBurn"; import * as stake from "codechain-stakeholder-sdk"; +import RPC from "foundry-rpc"; import { createWriteStream, mkdtempSync, unlinkSync } from "fs"; import * as mkdirp from "mkdirp"; import { ncp } from "ncp"; @@ -76,6 +77,7 @@ export interface Signer { export default class CodeChain { private static idCounter = 0; private readonly _id: number; + private readonly _rpc: RPC; private readonly _sdk: SDK; private readonly _localKeyStorePath: string; private readonly _dbPath: string; @@ -103,6 +105,13 @@ export default class CodeChain { throw new ProcessStateError(this.id, this.process); } } + public get rpc(): RPC { + if (this.process.state === "running") { + return this._rpc; + } else { + throw new ProcessStateError(this.id, this.process); + } + } public get localKeyStorePath(): string { return this._localKeyStorePath; } @@ -187,6 +196,9 @@ export default class CodeChain { this.id }.log`; this._logPath = `${projectRoot}/test/log/${this._logFile}`; + this._rpc = new RPC(`http://localhost:${this.rpcPort}`, { + devel: true + }); this._sdk = new SDK({ server: `http://localhost:${this.rpcPort}` }); this._chain = chain || "solo"; this.argv = argv || []; @@ -406,10 +418,12 @@ export default class CodeChain { if (!this.process) { return Promise.reject(Error("process isn't available")); } - await this.sdk.rpc.network.connect("127.0.0.1", peer.port); + await this.rpc.net.connect({ address: "127.0.0.1", port: peer.port }); while ( - (await this.sdk.rpc.network.isConnected("127.0.0.1", peer.port)) === - false + !(await this.rpc.net.isConnected({ + address: "127.0.0.1", + port: peer.port + })) ) { await wait(250); } @@ -419,11 +433,14 @@ export default class CodeChain { if (!this.process) { return Promise.reject(Error("process isn't available")); } - return this.sdk.rpc.network.disconnect("127.0.0.1", peer.port); + return this.rpc.net.disconnect({ + address: "127.0.0.1", + port: peer.port + }); } public async waitPeers(n: number) { - while (n > (await this.sdk.rpc.network.getPeerCount())) { + while (n > (await this.rpc.net.getPeerCount())) { await wait(500); } return; @@ -445,11 +462,15 @@ export default class CodeChain { } public async getBestBlockNumber() { - return this.sdk.rpc.chain.getBestBlockNumber(); + return this.rpc.chain.getBestBlockNumber(); } public async getBestBlockHash() { - return this.sdk.rpc.chain.getBlockHash(await this.getBestBlockNumber()); + return new H256( + await this.rpc.chain.getBlockHash({ + blockNumber: await this.getBestBlockNumber() + }) + ); } public async createP2PKHAddress() { @@ -526,7 +547,10 @@ export default class CodeChain { }) .sign({ secret: faucetSecret, - seq: await this.sdk.rpc.chain.getSeq(faucetAddress), + seq: (await this.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee: 10 }); return this.sdk.rpc.chain.sendSignedTransaction(tx); @@ -544,7 +568,12 @@ export default class CodeChain { this.localKeyStorePath ); const { account, fee = 10 } = params; - const { seq = await this.sdk.rpc.chain.getSeq(account) } = params; + const { + seq = (await this.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))! + } = params; const signed = await this.sdk.key.signTransaction(tx, { keyStore, account, @@ -563,7 +592,10 @@ export default class CodeChain { } ): Promise { const { - seq = (await this.sdk.rpc.chain.getSeq(faucetAddress)) || 0, + seq = (await this.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: null + }))!, fee = 10, secret = faucetSecret } = options || {}; @@ -634,7 +666,10 @@ export default class CodeChain { } ): Promise { const { - seq = (await this.sdk.rpc.chain.getSeq(faucetAddress)) || 0, + seq = (await this.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: await this.getBestBlockNumber() + })) || 0, secret = faucetSecret } = options || {}; const tx = this.sdk.core @@ -683,8 +718,12 @@ export default class CodeChain { secret?: any; fee?: number; }): Promise { - const { seq = (await this.sdk.rpc.chain.getSeq(faucetAddress)) || 0 } = - options || {}; + const { + seq = (await this.rpc.chain.getSeq({ + address: faucetAddress.toString(), + blockNumber: await this.getBestBlockNumber() + })) || 0 + } = options || {}; const tx = this.createPayTx({ seq, ...options @@ -699,11 +738,13 @@ export default class CodeChain { tx: Transaction & AssetTransaction, options: { seq?: number } = {} ): Promise { - await this.sdk.rpc.devel.stopSealing(); + await this.rpc.devel!.stopSealing(); const seq = options.seq == null - ? await this.sdk.rpc.chain.getSeq(faucetAddress) + ? (await this.rpc.chain.getSeq({ + address: faucetAddress.toString() + }))! : options.seq; const blockNumber = await this.getBestBlockNumber(); @@ -717,19 +758,32 @@ export default class CodeChain { seq: seq + 1 }); - await this.sdk.rpc.devel.startSealing(); + await this.rpc.devel!.startSealing(); await this.waitBlockNumber(blockNumber + 1); - expect(await this.sdk.rpc.chain.containsTransaction(targetTxHash)).be - .false; + expect( + await this.rpc.chain.containsTransaction({ + transactionHash: `0x${targetTxHash.toString()}` + }) + ).be.false; expect(await this.sdk.rpc.chain.getErrorHint(targetTxHash)).not.null; - expect(await this.sdk.rpc.chain.getTransaction(targetTxHash)).be.null; + expect( + await this.rpc.chain.getTransaction({ + transactionHash: `0x${targetTxHash.toString()}` + }) + ).be.null; - expect(await this.sdk.rpc.chain.containsTransaction(signedDummyTxHash)) - .be.true; + expect( + await this.rpc.chain.containsTransaction({ + transactionHash: `0x${signedDummyTxHash.toString()}` + }) + ).be.true; expect(await this.sdk.rpc.chain.getErrorHint(signedDummyTxHash)).null; - expect(await this.sdk.rpc.chain.getTransaction(signedDummyTxHash)).not - .be.null; + expect( + await this.rpc.chain.getTransaction({ + transactionHash: `0x${signedDummyTxHash.toString()}` + }) + ).not.be.null; return targetTxHash; } @@ -740,7 +794,7 @@ export default class CodeChain { options: { account: string | PlatformAddress } ): Promise { const { account } = options; - await this.sdk.rpc.devel.stopSealing(); + await this.rpc.devel!.stopSealing(); const blockNumber = await this.getBestBlockNumber(); const signedDummyTxHash = ( @@ -750,19 +804,32 @@ export default class CodeChain { ).hash(); const targetTxHash = await this.sendTransaction(tx, { account }); - await this.sdk.rpc.devel.startSealing(); + await this.rpc.devel!.startSealing(); await this.waitBlockNumber(blockNumber + 1); - expect(await this.sdk.rpc.chain.containsTransaction(targetTxHash)).be - .false; + expect( + await this.rpc.chain.containsTransaction({ + transactionHash: `0x${targetTxHash.toString()}` + }) + ).be.false; expect(await this.sdk.rpc.chain.getErrorHint(targetTxHash)).not.null; - expect(await this.sdk.rpc.chain.getTransaction(targetTxHash)).be.null; + expect( + await this.rpc.chain.getTransaction({ + transactionHash: `0x${targetTxHash.toString()}` + }) + ).be.null; - expect(await this.sdk.rpc.chain.containsTransaction(signedDummyTxHash)) - .be.true; + expect( + await this.rpc.chain.containsTransaction({ + transactionHash: `0x${signedDummyTxHash.toString()})` + }) + ).be.true; expect(await this.sdk.rpc.chain.getErrorHint(signedDummyTxHash)).null; - expect(await this.sdk.rpc.chain.getTransaction(signedDummyTxHash)).not - .be.null; + expect( + await this.rpc.chain.getTransaction({ + transactionHash: `0x${signedDummyTxHash.toString()}` + }) + ).not.be.null; return targetTxHash; } @@ -771,7 +838,7 @@ export default class CodeChain { tx: SignedTransaction | (() => Promise), options: { error?: string } = {} ): Promise { - await this.sdk.rpc.devel.stopSealing(); + await this.rpc.devel!.stopSealing(); const blockNumber = await this.getBestBlockNumber(); const signedDummyTxHash = ( @@ -786,23 +853,36 @@ export default class CodeChain { ? await this.sdk.rpc.chain.sendSignedTransaction(tx) : await tx(); - await this.sdk.rpc.devel.startSealing(); + await this.rpc.devel!.startSealing(); await this.waitBlockNumber(blockNumber + 1); - expect(await this.sdk.rpc.chain.containsTransaction(targetTxHash)).be - .false; + expect( + await this.rpc.chain.containsTransaction({ + transactionHash: `0x${targetTxHash.toString()}` + }) + ).be.false; const hint = await this.sdk.rpc.chain.getErrorHint(targetTxHash); expect(hint).not.null; if (options.error != null) { expect(hint).contains(options.error); } - expect(await this.sdk.rpc.chain.getTransaction(targetTxHash)).be.null; + expect( + await this.rpc.chain.getTransaction({ + transactionHash: `0x${targetTxHash.toString()}` + }) + ).be.null; - expect(await this.sdk.rpc.chain.containsTransaction(signedDummyTxHash)) - .be.true; + expect( + await this.rpc.chain.containsTransaction({ + transactionHash: `0x${signedDummyTxHash.toString()}` + }) + ).be.true; expect(await this.sdk.rpc.chain.getErrorHint(signedDummyTxHash)).null; - expect(await this.sdk.rpc.chain.getTransaction(signedDummyTxHash)).not - .be.null; + expect( + await this.rpc.chain.getTransaction({ + transactionHash: `0x${signedDummyTxHash.toString()}` + }) + ).not.be.null; return targetTxHash; } @@ -843,7 +923,11 @@ export default class CodeChain { const containsAll = async () => { const contains = await Promise.all( - hashes.map(hash => this.sdk.rpc.chain.containsTransaction(hash)) + hashes.map(hash => + this.rpc.chain.containsTransaction({ + transactionHash: `0x${hash.toString()}` + }) + ) ); return contains.every(x => x); }; diff --git a/test/yarn.lock b/test/yarn.lock index 470854d02b..05c44b7272 100644 --- a/test/yarn.lock +++ b/test/yarn.lock @@ -68,6 +68,13 @@ dependencies: "@types/node" "*" +"@types/node-fetch@^2.3.4": + version "2.5.4" + resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.4.tgz#5245b6d8841fc3a6208b82291119bc11c4e0ce44" + integrity sha512-Oz6id++2qAOFuOlE1j0ouk1dzl3mmI1+qINPNBhi9nt/gVOz0G+13Ao6qjhdF0Ys+eOkhu6JnFmt38bR3H0POQ== + dependencies: + "@types/node" "*" + "@types/node@*": version "13.7.0" resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.0.tgz#b417deda18cf8400f278733499ad5547ed1abec4" @@ -736,6 +743,13 @@ form-data@~2.3.2: combined-stream "^1.0.6" mime-types "^2.1.12" +"foundry-rpc@git://github.com/CodeChain-io/foundry-rpc-js.git#alpha": + version "2.0.0" + resolved "git://github.com/CodeChain-io/foundry-rpc-js.git#57d8cc595efc1e51c73e7fa1a95b67b4aab3b677" + dependencies: + "@types/node-fetch" "^2.3.4" + node-fetch "^2.6.0" + fs-constants@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad" @@ -1218,7 +1232,7 @@ node-environment-flags@1.0.5: object.getownpropertydescriptors "^2.0.3" semver "^5.7.0" -node-fetch@^2.1.2: +node-fetch@^2.1.2, node-fetch@^2.6.0: version "2.6.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==