Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Aug 10, 2017
1 parent a080d45 commit 2189881
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/runCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ module.exports = function (opts, cb) {
return
}

console.log("loading", toAddress);

if (ethUtil.isPrecompiled(toAddress)) {
isCompiled = true
code = self._precompiled[toAddress.toString('hex')]
Expand Down
40 changes: 33 additions & 7 deletions lib/runCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,36 @@ module.exports = function (opts, cb) {
// advance program counter
runState.programCounter++
var argsNum = opInfo.in
var retNum = opInfo.out
console.log(opInfo.name, opInfo.in, opInfo.out)
// pop the stack
var args = argsNum ? runState.stack.splice(-opInfo.in) : []
var args = argsNum ? runState.stack.splice(-argsNum) : []
for (var i = 0; i < argsNum; i++) {
if (!BN.isBN(args[i]))
{
console.log('Not a bn... at ', opInfo.name, i, args[i])
}
}

args.reverse()
args.push(runState)
// create a callback for async opFunc
args.push(function (err, val) {
// save result to the stack
if (val) {
// NOTE: Ensure that every stack item is padded to 256 bits.
// This should be done at every opcode in the future.
val = utils.setLengthLeft(val, 32)
console.log(' -> ', val)

if (retNum != 1) {
runState.vmError = ERROR.INVALID_OPCODE
// return cb()
}
if (!BN.isBN(val)) {
console.log('Not a bn after ', opInfo.name, val)
}
runState.stack.push(val)
} else if (retNum != 0) {
runState.vmError = ERROR.INVALID_OPCODE
// return cb()
}
cb(err)
})
Expand All @@ -191,10 +209,18 @@ module.exports = function (opts, cb) {

// save result to the stack
if (result) {
// NOTE: Ensure that every stack item is padded to 256 bits.
// This should be done at every opcode in the future.
result = utils.setLengthLeft(result, 32)
console.log(' -> ', result)
if (retNum != 1) {
runState.vmError = ERROR.INVALID_OPCODE
// return cb()
}
if (!BN.isBN(result)) {
console.log('Not a bn after ', opInfo.name, result)
}
runState.stack.push(result)
} else if (retNum != 0) {
runState.vmError = ERROR.INVALID_OPCODE
// return cb()
}
// call the callback if opFn was sync
if (opFn.length - argsNum !== 2) {
Expand Down

0 comments on commit 2189881

Please sign in to comment.