Merge pull request #1120 from LeviBarnes/master

Allow timestamps to be passed to rawRun
pull/7/head
yann300 6 years ago committed by GitHub
commit db77e93089
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      remix-lib/src/execution/txRunner.js

@ -22,7 +22,11 @@ class TxRunner {
} }
rawRun (args, confirmationCb, gasEstimationForceSend, promptCb, cb) { rawRun (args, confirmationCb, gasEstimationForceSend, promptCb, cb) {
run(this, args, Date.now(), confirmationCb, gasEstimationForceSend, promptCb, cb) var timestamp = Date.now()
if (args.timestamp) {
timestamp = args.timestamp
}
run(this, args, timestamp, confirmationCb, gasEstimationForceSend, promptCb, cb)
} }
_executeTx (tx, gasPrice, api, promptCb, callback) { _executeTx (tx, gasPrice, api, promptCb, callback) {
@ -81,20 +85,21 @@ class TxRunner {
self.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, confirmationCb, gasEstimationForceSend, promptCb, callback) self.runInNode(args.from, args.to, data, args.value, args.gasLimit, args.useCall, confirmationCb, gasEstimationForceSend, promptCb, callback)
} else { } else {
try { try {
self.runInVm(args.from, args.to, data, args.value, args.gasLimit, args.useCall, callback) self.runInVm(args.from, args.to, data, args.value, args.gasLimit, args.useCall, args.timestamp, callback)
} catch (e) { } catch (e) {
callback(e, null) callback(e, null)
} }
} }
} }
runInVm (from, to, data, value, gasLimit, useCall, callback) { runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) {
const self = this const self = this
var account = self.vmaccounts[from] var account = self.vmaccounts[from]
if (!account) { if (!account) {
return callback('Invalid account selected') return callback('Invalid account selected')
} }
var tx = new EthJSTX({ var tx = new EthJSTX({
timestamp: timestamp,
nonce: new BN(account.nonce++), nonce: new BN(account.nonce++),
gasPrice: new BN(1), gasPrice: new BN(1),
gasLimit: new BN(gasLimit, 10), gasLimit: new BN(gasLimit, 10),
@ -108,7 +113,7 @@ class TxRunner {
const difficulties = [ new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10) ] const difficulties = [ new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10) ]
var block = new EthJSBlock({ var block = new EthJSBlock({
header: { header: {
timestamp: new Date().getTime() / 1000 | 0, timestamp: timestamp || (new Date().getTime() / 1000 | 0),
number: self.blockNumber, number: self.blockNumber,
coinbase: coinbases[self.blockNumber % coinbases.length], coinbase: coinbases[self.blockNumber % coinbases.length],
difficulty: difficulties[self.blockNumber % difficulties.length], difficulty: difficulties[self.blockNumber % difficulties.length],

Loading…
Cancel
Save