Created
July 7, 2020 14:25
-
-
Save nakajo2011/942d470427f932a9534c113eb3aa46df to your computer and use it in GitHub Desktop.
arround freeze sendTransaction.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pify = require('pify') | |
async function queueTransaction(from, to, value, nonce, gasLimit, data) { | |
const response = await pify(web3.currentProvider.send)({ | |
jsonrpc: "2.0", | |
method: "eth_sendTransaction", | |
id: new Date().getTime(), | |
params: [ | |
{ | |
from: from, | |
to: to, | |
gas: gasLimit, | |
value: value, | |
nonce: nonce, | |
data: data | |
} | |
] | |
}); | |
if (response.error) { | |
throw new Error(response.error.message); | |
} | |
return response.result; | |
} | |
it('multi transfer in same block', async () => { | |
web3.extend({property: 'mine', methods: [{ name: 'start', call: 'miner_start', params:0}]}) | |
web3.extend({property: 'mine', methods: [{ name: 'stop', call: 'miner_stop', params:0}]}) | |
const instance = await MyERC20Token.new() | |
const beforeBlock = await web3.eth.getBlockNumber() | |
const nonce = await web3.eth.getTransactionCount(accounts[0]) | |
await web3.mine.stop() | |
const tx1_data = instance.contract.methods.transfer(accounts[1], 100).encodeABI() | |
const tx2_data = instance.contract.methods.transfer(accounts[2], 100).encodeABI() | |
// queued tx1 | |
await queueTransaction(owner, Instance.address, 0, nonce, gas, tx1_data) | |
// queued tx2 | |
await queueTransaction(owner, Instance.address, 0, nonce+1, gas, tx2_data) | |
await web3.mine.start() | |
const afterBlock = await web3.eth.getBlockNumber(); | |
assert.equal(beforeBlock+1, afterBlock) // block increase just +1. | |
assert.equal(await Instance.balanceOf(accounts[1]), 100) | |
assert.equal(await Instance.balanceOf(accounts[2]), 100) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment