git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 8ef09c67f032b90950cba23e30ffcc14c0b47078

Merge pull request #38 from ewasm/endian-cleanup-testfixes

these changes fix the tests in evm2wasm
Alex 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.jschanged
environment.jschanged
interface.jschanged
transaction.jschanged
block.jsView
@@ -25,7 +25,7 @@
2525 return ethUtil.bufferToInt(this.header.timestamp)
2626 }
2727
2828 get coinbase () {
29- return new Address('0x' + this.header.coinbase.toString('hex'))
29+ return new Address(this.header.coinbase)
3030 }
3131 }
environment.jsView
@@ -41,13 +41,23 @@
4141 this.state.set(address.toString(), account)
4242 }
4343
4444 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+ }
4651 }
4752
4853 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+ }
5060 }
5161
5262 getBlockHash (height) {
5363 return this.blockchain.getBlock(height).hash()
interface.jsView
@@ -157,9 +157,9 @@
157157 * @param {integer} dataOffset the offset in the input data
158158 * @param {integer} length the length of data to copy
159159 */
160160 callDataCopy (offset, dataOffset, length) {
161- this.takeGas(3 + ((length / 32) * 3))
161+ this.takeGas(3 + Math.ceil(length / 32) * 3)
162162
163163 const callData = this.environment.callData.slice(dataOffset, dataOffset + length)
164164 this.setMemory(offset, length, callData)
165165 }
@@ -192,9 +192,9 @@
192192 * @param {integer} codeOffset the code offset
193193 * @param {integer} length the length of code to copy
194194 */
195195 codeCopy (resultOffset, codeOffset, length) {
196- this.takeGas(3 + ((length / 32) * 3))
196+ this.takeGas(3 + Math.ceil(length / 32) * 3)
197197
198198 const code = new Uint8Array(this.environment.code, codeOffset, length)
199199 this.setMemory(resultOffset, length, code)
200200 }
@@ -219,9 +219,9 @@
219219 * @param {integer} codeOffset the code offset
220220 * @param {integer} length the length of code to copy
221221 */
222222 externalCodeCopy (addressOffset, resultOffset, codeOffset, length) {
223- this.takeGas(20 + ((length / 32) * 3))
223+ this.takeGas(20 + Math.ceil(length / 32) * 3)
224224
225225 const address = Address.fromMemory(this.getMemory(addressOffset, constants.ADDRESS_SIZE_BYTES))
226226 let code = this.environment.getCode(address)
227227 code = new Uint8Array(code, codeOffset, length)
transaction.jsView
@@ -36,16 +36,16 @@
3636 return Uint8Array.from(this._tx.data)
3737 }
3838
3939 get from () {
40- return new Address('0x' + this._tx.getSenderAddress().toString('hex'))
40+ return new Address(this._tx.getSenderAddress())
4141 }
4242
4343 get to () {
4444 if (this._tx.to.length === 0) {
4545 return new Address('0x0000000000000000000000000000000000000000')
4646 }
47- return new Address('0x' + this._tx.to.toString('hex'))
47+ return new Address(this._tx.to)
4848 }
4949
5050 get isSend () {
5151 }

Built with git-ssb-web