diff --git a/EVMimports.js b/EVMimports.js index 2e30a7b..3f26564 100644 --- a/EVMimports.js +++ b/EVMimports.js @@ -124,7 +124,7 @@ module.exports = class Interface { * @param {integer} addressOffset the memory offset to laod the address * @param {integer} resultOffset */ - getBalance (addressOffset, offset, cbIndex) { + getBalance (addressOffset, resultOffset, cbIndex) { log.debug('EVMImports.js getBalance') this.takeGas(20) @@ -137,7 +137,7 @@ module.exports = class Interface { const opPromise = Promise.resolve(balanceU256) this.kernel.pushOpsQueue(opPromise, cbIndex, balance => { - this.setMemory(offset, U128_SIZE_BYTES, balance.toMemory(U128_SIZE_BYTES)) + this.setMemory(resultOffset, U128_SIZE_BYTES, balance.toMemory(U128_SIZE_BYTES).reverse()) }) } diff --git a/tests/interface/balance.json b/tests/interface/balance.json index e818b77..c03d78a 100644 --- a/tests/interface/balance.json +++ b/tests/interface/balance.json @@ -3,7 +3,7 @@ "callData": "0x00", "state": { "0x5d48c1018904a172886829bbbd9c6f4a2d06c47b": { - "balance": "0x056bc75e2d63100000", + "balance": "0xde0b6b3a7640000", "code": "0x00", "nonce": "0x00" } diff --git a/tests/interface/balance.wasm b/tests/interface/balance.wasm index 1f94431..6d09822 100644 Binary files a/tests/interface/balance.wasm and b/tests/interface/balance.wasm differ diff --git a/tests/interface/balance.wast b/tests/interface/balance.wast index 9a5e6b7..7f59a6a 100644 --- a/tests/interface/balance.wast +++ b/tests/interface/balance.wast @@ -1,4 +1,4 @@ -;; address of 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 0x056bc75e2d63100000 (100 ETH) +;; address 5d48c1018904a172886829bbbd9c6f4a2d06c47b has a balance of 0xde0b6b3a7640000 (1 ETH) (module (import "ethereum" "getBalance" (func $balance (param i32 i32 i32))) (memory 1 ) @@ -8,16 +8,15 @@ (export "1" (func $callback)) (func $main - (call $balance (i32.const 0) (i32.const 0) (i32.const 1)) + (call $balance (i32.const 0) (i32.const 64) (i32.const 1)) ) - + (func $callback (block - (if (i64.eq (i64.load (i32.const 0)) (i64.const 0x0500000000000000)) + (if (i64.eq (i64.load (i32.const 64)) (i64.const 0xde0b6b3a7640000)) (return) ) (unreachable) ) ) ) -