Skip to content

Commit 1394a2e

Browse files
authored
Merge pull request ethereumjs#272 from ethereumjs/update-tests
[WIP] update to latest testing repo
2 parents 4f1d427 + ed4022e commit 1394a2e

File tree

5 files changed

+76
-43
lines changed

5 files changed

+76
-43
lines changed

lib/precompiled/05-modexp.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ function multComplexity (x) {
2525
}
2626

2727
function getAdjustedExponentLength (data) {
28-
var baseLen = new BN(data.slice(0, 32)).toNumber()
28+
var expBytesStart
29+
try {
30+
var baseLen = new BN(data.slice(0, 32)).toNumber()
31+
expBytesStart = 96 + baseLen // 96 for base length, then exponent length, and modulus length, then baseLen for the base data, then exponent bytes start
32+
} catch (e) {
33+
expBytesStart = Number.MAX_SAFE_INTEGER - 32
34+
}
2935
var expLen = new BN(data.slice(32, 64))
30-
var expBytesStart = 96 + baseLen // 96 for base length, then exponent length, and modulus length, then baseLen for the base data, then exponent bytes start
3136
var firstExpBytes = Buffer.from(data.slice(expBytesStart, expBytesStart + 32)) // first word of the exponent data
3237
firstExpBytes = utils.setLengthRight(firstExpBytes, 32) // reading past the data reads virtual zeros
3338
firstExpBytes = new BN(firstExpBytes)
@@ -105,7 +110,7 @@ module.exports = function (opts) {
105110
}
106111

107112
if (mLen.isZero()) {
108-
results.return = Buffer.from([0])
113+
results.return = Buffer.alloc(0)
109114
results.exception = 1
110115
return results
111116
}

lib/runCall.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,16 @@ module.exports = function (opts, cb) {
7070
txData = undefined
7171
var newNonce = new BN(account.nonce).subn(1)
7272
createdAddress = toAddress = ethUtil.generateAddress(caller, newNonce.toArray())
73-
stateManager.getAccount(createdAddress, function (err, account) {
74-
toAccount = account
75-
const NONCE_OFFSET = 1
76-
toAccount.nonce = new BN(toAccount.nonce).addn(NONCE_OFFSET).toArrayLike(Buffer)
77-
done(err)
73+
stateManager.clearContractStorage(createdAddress, function (err) {
74+
if (err) {
75+
done(err)
76+
}
77+
78+
stateManager.getAccount(createdAddress, function (err, account) {
79+
toAccount = account
80+
toAccount.nonce = new BN(1).toArrayLike(Buffer)
81+
done(err)
82+
})
7883
})
7984
} else {
8085
// else load the `to` account

lib/stateManager.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,21 +160,14 @@ proto.getContractStorage = function (address, key, cb) {
160160
})
161161
}
162162

163-
proto.putContractStorage = function (address, key, value, cb) {
163+
proto._modifyContractStorage = function (address, modifyTrie, cb) {
164164
var self = this
165165
self._getStorageTrie(address, function (err, storageTrie) {
166166
if (err) {
167167
return cb(err)
168168
}
169169

170-
if (value && value.length) {
171-
// format input
172-
var encodedValue = rlp.encode(value)
173-
storageTrie.put(key, encodedValue, finalize)
174-
} else {
175-
// deleting a value
176-
storageTrie.del(key, finalize)
177-
}
170+
modifyTrie(storageTrie, finalize)
178171

179172
function finalize (err) {
180173
if (err) return cb(err)
@@ -189,6 +182,28 @@ proto.putContractStorage = function (address, key, value, cb) {
189182
})
190183
}
191184

185+
proto.putContractStorage = function (address, key, value, cb) {
186+
var self = this
187+
self._modifyContractStorage(address, function (storageTrie, done) {
188+
if (value && value.length) {
189+
// format input
190+
var encodedValue = rlp.encode(value)
191+
storageTrie.put(key, encodedValue, done)
192+
} else {
193+
// deleting a value
194+
storageTrie.del(key, done)
195+
}
196+
}, cb)
197+
}
198+
199+
proto.clearContractStorage = function (address, cb) {
200+
var self = this
201+
self._modifyContractStorage(address, function (storageTrie, done) {
202+
storageTrie.root = storageTrie.EMPTY_TRIE_ROOT
203+
done()
204+
}, cb)
205+
}
206+
192207
proto.commitContracts = function (cb) {
193208
var self = this
194209
async.each(Object.keys(self._storageTries), function (address, cb) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"babel-preset-env": "^1.6.1",
4949
"coveralls": "^3.0.0",
5050
"ethereumjs-blockchain": "~2.1.0",
51-
"ethereumjs-testing": "https://github.com/ethereumjs/ethereumjs-testing",
51+
"ethereumjs-testing": "git+https://github.com/ethereumjs/ethereumjs-testing.git#v1.1.1",
5252
"ethereumjs-tx": "1.3.3",
5353
"istanbul": "^0.4.5",
5454
"level": "^1.4.0",

tests/GeneralStateTestsRunner.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,34 @@ const ethUtil = require('ethereumjs-util')
55
const BN = ethUtil.BN
66

77
function parseTestCases (forkConfig, testData, data, gasLimit, value) {
8-
let testCases = testData['post'][forkConfig].map(testCase => {
9-
let testIndexes = testCase['indexes']
10-
let tx = Object.assign({}, testData.transaction)
11-
if (data !== undefined && testIndexes['data'] !== data) {
12-
return null
13-
}
8+
let testCases = []
9+
if (testData['post'][forkConfig]) {
10+
testCases = testData['post'][forkConfig].map(testCase => {
11+
let testIndexes = testCase['indexes']
12+
let tx = Object.assign({}, testData.transaction)
13+
if (data !== undefined && testIndexes['data'] !== data) {
14+
return null
15+
}
1416

15-
if (value !== undefined && testIndexes['value'] !== value) {
16-
return null
17-
}
17+
if (value !== undefined && testIndexes['value'] !== value) {
18+
return null
19+
}
1820

19-
if (gasLimit !== undefined && testIndexes['gas'] !== gasLimit) {
20-
return null
21-
}
21+
if (gasLimit !== undefined && testIndexes['gas'] !== gasLimit) {
22+
return null
23+
}
2224

23-
tx.data = testData.transaction.data[testIndexes['data']]
24-
tx.gasLimit = testData.transaction.gasLimit[testIndexes['gas']]
25-
tx.value = testData.transaction.value[testIndexes['value']]
26-
return {
27-
'transaction': tx,
28-
'postStateRoot': testCase['hash'],
29-
'env': testData['env'],
30-
'pre': testData['pre']
31-
}
32-
})
25+
tx.data = testData.transaction.data[testIndexes['data']]
26+
tx.gasLimit = testData.transaction.gasLimit[testIndexes['gas']]
27+
tx.value = testData.transaction.value[testIndexes['value']]
28+
return {
29+
'transaction': tx,
30+
'postStateRoot': testCase['hash'],
31+
'env': testData['env'],
32+
'pre': testData['pre']
33+
}
34+
})
35+
}
3336

3437
testCases = testCases.filter(testCase => {
3538
return testCase != null
@@ -123,9 +126,14 @@ function runTestCase (options, testData, t, cb) {
123126
module.exports = function runStateTest (options, testData, t, cb) {
124127
try {
125128
const testCases = parseTestCases(options.forkConfig, testData, options.data, options.gasLimit, options.value)
126-
async.eachSeries(testCases,
127-
(testCase, done) => runTestCase(options, testCase, t, done),
128-
cb)
129+
if (testCases.length > 0) {
130+
async.eachSeries(testCases,
131+
(testCase, done) => runTestCase(options, testCase, t, done),
132+
cb)
133+
} else {
134+
t.comment(`No ${options.forkConfig} post state defined, skip test`)
135+
cb()
136+
}
129137
} catch (e) {
130138
t.fail('error running test case for fork: ' + options.forkConfig)
131139
console.log('error:', e)

0 commit comments

Comments
 (0)