Commit 8ef09c67f032b90950cba23e30ffcc14c0b47078
Merge pull request #38 from ewasm/endian-cleanup-testfixes
these changes fix the tests in evm2wasmAlex Beregszaszi authored on 8/25/2016, 2:38:24 AM
GitHub committed on 8/25/2016, 2:38:24 AM
Parent: fe80685fa3f7f75e6bcb2fb0e4278298822b4a3e
Parent: 51b309693ae24e58fef5c9a30f63e30aca8a24aa
Files changed
block.js | changed |
environment.js | changed |
interface.js | changed |
transaction.js | changed |
block.js | ||
---|---|---|
@@ -25,7 +25,7 @@ | ||
25 | 25 | return ethUtil.bufferToInt(this.header.timestamp) |
26 | 26 | } |
27 | 27 | |
28 | 28 | get coinbase () { |
29 | - return new Address('0x' + this.header.coinbase.toString('hex')) | |
29 | + return new Address(this.header.coinbase) | |
30 | 30 | } |
31 | 31 | } |
environment.js | ||
---|---|---|
@@ -41,13 +41,23 @@ | ||
41 | 41 | this.state.set(address.toString(), account) |
42 | 42 | } |
43 | 43 | |
44 | 44 | getBalance (address) { |
45 | - return this.state.get(address.toString())['balance'] | |
45 | + const account = this.state.get(address.toString()) | |
46 | + if (account) { | |
47 | + return account['balance'] | |
48 | + } else { | |
49 | + return new U256() | |
50 | + } | |
46 | 51 | } |
47 | 52 | |
48 | 53 | getCode (address) { |
49 | - return this.state.get(address.toString())['code'] | |
54 | + const account = this.state.get(address.toString()) | |
55 | + if (account) { | |
56 | + return account['code'] | |
57 | + } else { | |
58 | + return Uint8Array.from(new Buffer([])) | |
59 | + } | |
50 | 60 | } |
51 | 61 | |
52 | 62 | getBlockHash (height) { |
53 | 63 | return this.blockchain.getBlock(height).hash() |
interface.js | ||
---|---|---|
@@ -157,9 +157,9 @@ | ||
157 | 157 | * @param {integer} dataOffset the offset in the input data |
158 | 158 | * @param {integer} length the length of data to copy |
159 | 159 | */ |
160 | 160 | callDataCopy (offset, dataOffset, length) { |
161 | - this.takeGas(3 + ((length / 32) * 3)) | |
161 | + this.takeGas(3 + Math.ceil(length / 32) * 3) | |
162 | 162 | |
163 | 163 | const callData = this.environment.callData.slice(dataOffset, dataOffset + length) |
164 | 164 | this.setMemory(offset, length, callData) |
165 | 165 | } |
@@ -192,9 +192,9 @@ | ||
192 | 192 | * @param {integer} codeOffset the code offset |
193 | 193 | * @param {integer} length the length of code to copy |
194 | 194 | */ |
195 | 195 | codeCopy (resultOffset, codeOffset, length) { |
196 | - this.takeGas(3 + ((length / 32) * 3)) | |
196 | + this.takeGas(3 + Math.ceil(length / 32) * 3) | |
197 | 197 | |
198 | 198 | const code = new Uint8Array(this.environment.code, codeOffset, length) |
199 | 199 | this.setMemory(resultOffset, length, code) |
200 | 200 | } |
@@ -219,9 +219,9 @@ | ||
219 | 219 | * @param {integer} codeOffset the code offset |
220 | 220 | * @param {integer} length the length of code to copy |
221 | 221 | */ |
222 | 222 | externalCodeCopy (addressOffset, resultOffset, codeOffset, length) { |
223 | - this.takeGas(20 + ((length / 32) * 3)) | |
223 | + this.takeGas(20 + Math.ceil(length / 32) * 3) | |
224 | 224 | |
225 | 225 | const address = Address.fromMemory(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES)) |
226 | 226 | let code = this.environment.getCode(address) |
227 | 227 | code = new Uint8Array(code, codeOffset, length) |
transaction.js | ||
---|---|---|
@@ -36,16 +36,16 @@ | ||
36 | 36 | return Uint8Array.from(this._tx.data) |
37 | 37 | } |
38 | 38 | |
39 | 39 | get from () { |
40 | - return new Address('0x' + this._tx.getSenderAddress().toString('hex')) | |
40 | + return new Address(this._tx.getSenderAddress()) | |
41 | 41 | } |
42 | 42 | |
43 | 43 | get to () { |
44 | 44 | if (this._tx.to.length === 0) { |
45 | 45 | return new Address('0x0000000000000000000000000000000000000000') |
46 | 46 | } |
47 | - return new Address('0x' + this._tx.to.toString('hex')) | |
47 | + return new Address(this._tx.to) | |
48 | 48 | } |
49 | 49 | |
50 | 50 | get isSend () { |
51 | 51 | } |
Built with git-ssb-web