Skip to content
This repository was archived by the owner on Mar 3, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion remix-lib/src/execution/txRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class TxRunner {
executionContext.vm().stateManager.checkpoint(() => {})
}

executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) {
executionContext.vm().runTx({block: block, tx: tx, skipBalance: false, skipNonce: false}, function (err, result) {
if (useCall) {
executionContext.vm().stateManager.revert(function () {})
}
Expand Down
14 changes: 8 additions & 6 deletions remix-simulator/src/methods/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ var Accounts = function () {
// TODO: make it random and/or use remix-libs
this.accounts = [this.web3.eth.accounts.create(['abcd']), this.web3.eth.accounts.create(['ef12']), this.web3.eth.accounts.create(['ef34'])]

this.accounts[this.accounts[0].address.toLowerCase()] = this.accounts[0]
this.accounts[this.accounts[1].address.toLowerCase()] = this.accounts[1]
this.accounts[this.accounts[2].address.toLowerCase()] = this.accounts[2]
let setAccounts = (i) => {
const account = this.accounts[i]
this.accounts[account.address.toLowerCase()] = account
this.accounts[account.address.toLowerCase()].privateKey = Buffer.from(this.accounts[account.address.toLowerCase()].privateKey.slice(2), 'hex')
}

this.accounts[this.accounts[0].address.toLowerCase()].privateKey = Buffer.from(this.accounts[this.accounts[0].address.toLowerCase()].privateKey.slice(2), 'hex')
this.accounts[this.accounts[1].address.toLowerCase()].privateKey = Buffer.from(this.accounts[this.accounts[1].address.toLowerCase()].privateKey.slice(2), 'hex')
this.accounts[this.accounts[2].address.toLowerCase()].privateKey = Buffer.from(this.accounts[this.accounts[2].address.toLowerCase()].privateKey.slice(2), 'hex')
setAccounts(0)
setAccounts(1)
setAccounts(2)
}

Accounts.prototype.methods = function () {
Expand Down
32 changes: 31 additions & 1 deletion remix-simulator/src/provider.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const log = require('./utils/logs.js')
const merge = require('merge')
var remixLib = require('remix-lib')

var executionContext = remixLib.execution.executionContext
const Accounts = require('./methods/accounts.js')
const Blocks = require('./methods/blocks.js')
const Misc = require('./methods/misc.js')
Expand All @@ -9,8 +11,9 @@ const Transactions = require('./methods/transactions.js')
const Whisper = require('./methods/whisper.js')

var Provider = function () {
this.Accounts = new Accounts()
executionContext.setContext('vm', null, () => {}, (msg) => { console.log(msg) })

this.Accounts = new Accounts()
this.methods = {}
this.methods = merge(this.methods, this.Accounts.methods())
this.methods = merge(this.methods, (new Blocks()).methods())
Expand All @@ -25,6 +28,7 @@ Provider.prototype.sendAsync = function (payload, callback) {

let method = this.methods[payload.method]
if (method) {
console.log(payload)
return method.call(method, payload, (err, result) => {
if (err) {
return callback(err)
Expand All @@ -44,4 +48,30 @@ Provider.prototype.isConnected = function () {
return true
}

Provider.prototype.init = async function () {
const accounts = this.Accounts.accounts
let setAccounts = (i) => {
return new Promise((resolve, reject) => {
const account = accounts[i]

let stateManager = executionContext.vm().stateManager
const address = account.address
stateManager.getAccount(account.address, (error, account) => {
if (error) return reject(error)
account.balance = '0xf00000000000000001'
console.log('available address : ', address)
stateManager.putAccount(address, account, function cb (error, result) {
console.log('setBalance', address)
if (error) return reject(error)
console.log(result)
resolve()
})
})
})
}
await setAccounts(0)
await setAccounts(1)
await setAccounts(2)
}

module.exports = Provider
6 changes: 4 additions & 2 deletions remix-tests/src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ commander.command('help').description('output usage information').action(functio
// get current version
commander
.option('-v, --verbose <level>', 'run with verbosity', mapVerbosity)
.action(function (filename) {
.action(async function (filename) {
// Console message
console.log(('\n\t👁 :: Running remix-tests - Unit testing for solidity :: 👁\t\n').white)
// set logger verbosity
Expand All @@ -45,7 +45,9 @@ commander
}
let web3 = new Web3()
// web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
web3.setProvider(new Provider())
const provider = new Provider()
await provider.init()
web3.setProvider(provider)
// web3.setProvider(new web3.providers.WebsocketProvider('ws://localhost:8546'))

if (!fs.existsSync(filename)) {
Expand Down
10 changes: 6 additions & 4 deletions remix-tests/src/runTestSources.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ let TestRunner = require('./testRunner.js')
const Web3 = require('web3')
const Provider = require('remix-simulator').Provider

var createWeb3Provider = function () {
var createWeb3Provider = async function () {
let web3 = new Web3()
web3.setProvider(new Provider())
const provider = new Provider()
await provider.init()
web3.setProvider(provider)
return web3
}

const runTestSources = function (contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) {
const runTestSources = async function (contractSources, testCallback, resultCallback, finalCallback, importFileCb, opts) {
opts = opts || {}
let web3 = opts.web3 || createWeb3Provider()
let web3 = opts.web3 || await createWeb3Provider()
let accounts = opts.accounts || null
async.waterfall([
function getAccountList (next) {
Expand Down
6 changes: 4 additions & 2 deletions remix-tests/tests/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ let Deployer = require('../src/deployer.js')
let TestRunner = require('../src/testRunner.js')
const Provider = require('remix-simulator').Provider

function compileAndDeploy (filename, callback) {
async function compileAndDeploy (filename, callback) {
let web3 = new Web3()
web3.setProvider(new Provider())
const provider = new Provider()
await provider.init()
web3.setProvider(provider)
let compilationData
let accounts
async.waterfall([
Expand Down