Skip to content

Commit

Permalink
Replace Object.assign calls and fix type errors (#529)
Browse files Browse the repository at this point in the history
* Replace Object.assign calls and fix type errors

* Make LoopResult#runState optional again

* Fix type error
  • Loading branch information
alcuadrado authored and s1na committed May 31, 2019
1 parent c2a5cec commit 5d4fa87
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/evm/eei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export default class EEI {
}

async _baseCall(msg: Message): Promise<BN> {
const selfdestruct = Object.assign({}, this._result.selfdestruct)
const selfdestruct = { ...this._result.selfdestruct }
msg.selfdestruct = selfdestruct

// empty the return data buffer
Expand Down Expand Up @@ -520,7 +520,7 @@ export default class EEI {
* @param {Buffer} data
*/
async create(gasLimit: BN, value: BN, data: Buffer, salt: Buffer | null = null): Promise<BN> {
const selfdestruct = Object.assign({}, this._result.selfdestruct)
const selfdestruct = { ...this._result.selfdestruct }
const msg = new Message({
caller: this._env.address,
gasLimit: gasLimit,
Expand Down
24 changes: 15 additions & 9 deletions lib/evm/interpreter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export default class Interpreter {
) {
result.gasUsed = totalGas
} else {
Object.assign(result, OOGResult(message.gasLimit))
result = { ...result, ...OOGResult(message.gasLimit) }
}

// Save code if a new contract was created
Expand Down Expand Up @@ -276,22 +276,28 @@ export default class Interpreter {
gasUsed = message.gasLimit
}

// remove any logs on error
result = Object.assign({}, result, {
// Clear the result on error
result = {
...result,
logs: [],
gasRefund: null,
selfdestruct: null,
})
gasRefund: new BN(0),
selfdestruct: {},
}
}

return Object.assign({}, result, {
runState: Object.assign({}, loopRes.runState, result, eei._env),
return {
...result,
runState: {
...loopRes.runState!,
...result,
...eei._env,
},
exception: loopRes.exception,
exceptionError: loopRes.exceptionError,
gas: eei._gasLeft,
gasUsed,
return: result.returnValue ? result.returnValue : Buffer.alloc(0),
})
}
}

/**
Expand Down
8 changes: 3 additions & 5 deletions lib/evm/loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@ export default class Loop {
}

async run(code: Buffer, opts: RunOpts = {}): Promise<LoopResult> {
Object.assign(this._runState, {
code: code,
programCounter: opts.pc || this._runState.programCounter,
validJumps: this._getValidJumpDests(code),
})
this._runState.code = code
this._runState.programCounter = opts.pc || this._runState.programCounter
this._runState.validJumps = this._getValidJumpDests(code)

// Check that the programCounter is in range
const pc = this._runState.programCounter
Expand Down
2 changes: 1 addition & 1 deletion tests/GeneralStateTestsRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function parseTestCases (forkConfig, testData, data, gasLimit, value) {
if (testData['post'][forkConfig]) {
testCases = testData['post'][forkConfig].map(testCase => {
let testIndexes = testCase['indexes']
let tx = Object.assign({}, testData.transaction)
let tx = { ...testData.transaction }
if (data !== undefined && testIndexes['data'] !== data) {
return null
}
Expand Down

0 comments on commit 5d4fa87

Please sign in to comment.