diff --git a/package-lock.json b/package-lock.json index bbc60d60..ca7e3aba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5167,7 +5167,6 @@ }, "node_modules/npm/node_modules/lodash._baseindexof": { "version": "3.1.0", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -5183,19 +5182,16 @@ }, "node_modules/npm/node_modules/lodash._bindcallback": { "version": "3.0.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, "node_modules/npm/node_modules/lodash._cacheindexof": { "version": "3.0.2", - "extraneous": true, "inBundle": true, "license": "MIT" }, "node_modules/npm/node_modules/lodash._createcache": { "version": "3.1.2", - "extraneous": true, "inBundle": true, "license": "MIT", "dependencies": { @@ -5210,7 +5206,6 @@ }, "node_modules/npm/node_modules/lodash._getnative": { "version": "3.9.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -5228,7 +5223,6 @@ }, "node_modules/npm/node_modules/lodash.restparam": { "version": "3.6.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -12213,8 +12207,7 @@ }, "lodash._baseindexof": { "version": "3.1.0", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._baseuniq": { "version": "4.6.0", @@ -12227,18 +12220,15 @@ }, "lodash._bindcallback": { "version": "3.0.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._cacheindexof": { "version": "3.0.2", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._createcache": { "version": "3.1.2", "bundled": true, - "extraneous": true, "requires": { "lodash._getnative": "^3.0.0" } @@ -12250,8 +12240,7 @@ }, "lodash._getnative": { "version": "3.9.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._root": { "version": "3.0.1", @@ -12265,8 +12254,7 @@ }, "lodash.restparam": { "version": "3.6.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash.union": { "version": "4.6.0", diff --git a/vm-mock/vm.js b/vm-mock/vm.js index 50d1b547..cc3cd4d3 100644 --- a/vm-mock/vm.js +++ b/vm-mock/vm.js @@ -9,8 +9,10 @@ import sha3 from 'js-sha3'; */ // Those both addresses have been randomly generated -let defaultCallerAddress = 'AU12UBnqTHDQALpocVBnkPNy7y5CndUJQTLutaVDDFgMJcq5kQiKq'; -let defaultContractAddress = 'AS12BqZEQ6sByhRLyEuf0YbQmcF2PsDdkNNG1akBJu9XcjZA1eT'; +let defaultCallerAddress = + 'AU12UBnqTHDQALpocVBnkPNy7y5CndUJQTLutaVDDFgMJcq5kQiKq'; +let defaultContractAddress = + 'AS12BqZEQ6sByhRLyEuf0YbQmcF2PsDdkNNG1akBJu9XcjZA1eT'; let mockedOriginOpId = ''; @@ -134,7 +136,11 @@ function getCallee() { * */ function getCalleeBalance() { - return BigInt(ledger.get(getCallee()).balance) + callCoins - spentCoins; + let calleeBalance = 0n; + if (ledger.has(getCallee())) { + calleeBalance = BigInt(ledger.get(getCallee()).balance); + } + return calleeBalance + callCoins - spentCoins; } /** @@ -489,8 +495,10 @@ export default function createMockedABI( assembly_script_call(_address, method, _param, coins) { if (scCallMockStack.length) { - if(BigInt(coins) > getCalleeBalance()) { - ERROR('Not enough balance to pay the call to ' + ptrToString(method)); + if (BigInt(coins) > getCalleeBalance()) { + ERROR( + 'Not enough balance to pay the call to ' + ptrToString(method), + ); } spentCoins += BigInt(coins); return newArrayBuffer(scCallMockStack.shift()); @@ -512,7 +520,7 @@ export default function createMockedABI( assembly_script_set_deploy_context(addrPtr) { adminContext = true; let caller = getCaller(); - if(addrPtr) { + if (addrPtr) { caller = ptrToString(addrPtr); if (!ledger.has(caller)) { // add the new address to the ledger @@ -623,22 +631,25 @@ export default function createMockedABI( }, assembly_script_set_call_coins(coinAmount) { - const amount = BigInt(coinAmount); - if(amount == 0n) { + const amount = BigInt(coinAmount); + if (amount == 0n) { callCoins = 0n; return; } const caller = ledger.get(getCaller()); if (!caller) { - ERROR(`Unable to add coins for contract call. Address ${getCaller()} does not exists in ledger.`); + ERROR( + `Unable to add coins for contract call. Address ${getCaller()} does not exists in ledger.`, + ); } if (caller.balance < amount) { - ERROR(`${getCaller()} has not enough balance to pay ${amount.toString()} coins.`); + ERROR( + `${getCaller()} has not enough balance to pay ${amount.toString()} coins.`, + ); } callCoins = amount; caller.balance -= callCoins; - }, assembly_script_get_call_coins() { @@ -807,7 +818,7 @@ export default function createMockedABI( const addr = ptrToString(aPtr); if (!ledger.has(addr)) return 0n; - if(addr === getCallee()) { + if (addr === getCallee()) { return getCalleeBalance(); } return ledger.get(addr).balance;