Skip to content

Commit

Permalink
fix: call _request with wrong wrapResult within sendAsync (trustwalle…
Browse files Browse the repository at this point in the history
…t#228)

* fix: call _request with wrong wrapResult within sendAsync

* test: add test for batched sendAsync
  • Loading branch information
ibufu authored Mar 21, 2022
1 parent 380569d commit 9533db0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class TrustWeb3Provider extends EventEmitter {
that = window.ethereum;
}
if (Array.isArray(payload)) {
Promise.all(payload.map(that._request.bind(that)))
Promise.all(payload.map((_payload) => that._request(_payload)))
.then((data) => callback(null, data))
.catch((error) => callback(error, null));
} else {
Expand Down
15 changes: 14 additions & 1 deletion src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"eslint": "^8.7.0",
"ethereumjs-util": "^7.0.5",
"jest": "^27.4.7",
"uglify-js": "^3.15.0"
"uglify-js": "^3.15.0",
"whatwg-fetch": "^3.6.2"
},
"jest": {
"verbose": true,
Expand Down
30 changes: 29 additions & 1 deletion src/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

var ethUtil = require("ethereumjs-util");
require("../index");
require("whatwg-fetch");
const Web3 = require("web3");
const trustwallet = window.trustwallet;

Expand All @@ -26,7 +27,7 @@ const ropsten = {
const bsc = {
address: "0x9d8A62f656a8d1615C1294fd71e9CFb3E4855A4F",
chainId: 56,
rpcUrl: "https://bsc-dataseed1.binance.orge",
rpcUrl: "https://bsc-dataseed1.binance.org",
};

describe("TrustWeb3Provider constructor tests", () => {
Expand Down Expand Up @@ -178,4 +179,31 @@ describe("TrustWeb3Provider constructor tests", () => {
done();
});
});

test("test batched sendAsync", (done) => {
const provider = new trustwallet.Provider(bsc);
const web3 = new Web3(provider);
const request = [
{jsonrpc: "2.0", id: 11, method: "eth_call", params: [{data: "0x06fdde03", to: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}, "latest"]},
{jsonrpc: "2.0", id: 12, method: "eth_call", params: [{data: "0x313ce567", to: "0xe9e7cea3dedca5984780bafc599bd69add087d56"}, "latest"]}
];
const expectedResult = [
{
jsonrpc: "2.0",
id: 11,
result: "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a4255534420546f6b656e00000000000000000000000000000000000000000000"
},
{
jsonrpc: "2.0",
id: 12,
result: "0x0000000000000000000000000000000000000000000000000000000000000012"
}
];
web3.currentProvider.sendAsync(request,
(error, result) => {
expect(result).toEqual(expectedResult);
done();
}
);
});
}); // end of top describe()

0 comments on commit 9533db0

Please sign in to comment.