Skip to content

Commit

Permalink
refactor: Synchronize MinGasFee
Browse files Browse the repository at this point in the history
  • Loading branch information
howjmay committed Aug 16, 2023
1 parent 821c157 commit 6706234
Show file tree
Hide file tree
Showing 28 changed files with 109 additions and 115 deletions.
17 changes: 7 additions & 10 deletions contracts/wasm/testcore/go/testcoreimpl/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const (

MsgDoNothing = "========== doing nothing"
MsgFailOnPurpose = "failing on purpose"
MsgFullPanic = "========== panic FULL ENTRY POINT ========="
MsgFullPanic = "========== panic FULL ENTRY POINT =========="
MsgJustView = "calling empty view entry point"

MsgViewPanic = "========== panic VIEW ========="
MsgViewPanic = "========== panic VIEW =========="
)

func funcCallOnChain(ctx wasmlib.ScFuncContext, f *CallOnChainContext) {
Expand Down Expand Up @@ -242,13 +242,10 @@ func funcWithdrawFromChain(ctx wasmlib.ScFuncContext, f *WithdrawFromChainContex
transfer := wasmlib.ScTransferFromBalances(ctx.Allowance())
ctx.TransferAllowed(ctx.AccountID(), transfer)

// This is just a test contract, but normally these numbers should
// be parameters because there is no way for the contract to figure
// out the gas fees on the other chain, and it's also silly to run
// the costly calculation to determine storage deposit every time
// unless absolutely necessary. Better to just make sure that the
// storage deposit is large enough, since it will be returned anyway.
const gasFee = wasmlib.MinGasFee
var gasReserveTransferAccountToChain = wasmlib.MinGasFee
if f.Params.GasReserveTransferAccountToChain().Exists() {
gasReserveTransferAccountToChain = f.Params.GasReserveTransferAccountToChain().Value()
}
var gasReserve = wasmlib.MinGasFee
if f.Params.GasReserve().Exists() {
gasReserve = f.Params.GasReserve().Value()
Expand All @@ -261,7 +258,7 @@ func funcWithdrawFromChain(ctx wasmlib.ScFuncContext, f *WithdrawFromChainContex
// NOTE: make sure you READ THE DOCS before calling this function
xfer := coreaccounts.ScFuncs.TransferAccountToChain(ctx)
xfer.Params.GasReserve().SetValue(gasReserve)
xfer.Func.TransferBaseTokens(storageDeposit + gasFee + gasReserve).
xfer.Func.TransferBaseTokens(storageDeposit + gasReserveTransferAccountToChain + gasReserve).
AllowanceBaseTokens(withdrawal + storageDeposit + gasReserve).
PostToChain(targetChain)
}
Expand Down
18 changes: 8 additions & 10 deletions contracts/wasm/testcore/rs/testcoreimpl/src/funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::*;

const CONTRACT_NAME_DEPLOYED: &str = "exampleDeployTR";
const MSG_CORE_ONLY_PANIC: &str = "========== core only =========";
const MSG_FULL_PANIC: &str = "========== panic FULL ENTRY POINT =========";
const MSG_VIEW_PANIC: &str = "========== panic VIEW =========";
const MSG_FULL_PANIC: &str = "========== panic FULL ENTRY POINT ==========";
const MSG_VIEW_PANIC: &str = "========== panic VIEW ==========";

pub fn func_call_on_chain(ctx: &ScFuncContext, f: &CallOnChainContext) {
let param_int = f.params.n().value();
Expand Down Expand Up @@ -255,13 +255,11 @@ pub fn func_withdraw_from_chain(ctx: &ScFuncContext, f: &WithdrawFromChainContex
let transfer = ScTransfer::from_balances(&ctx.allowance());
ctx.transfer_allowed(&ctx.account_id(), &transfer);

// This is just a test contract, but normally these numbers should
// be parameters because there is no way for the contract to figure
// out the gas fees on the other chain, and it's also silly to run
// the costly calculation to determine storage deposit every time
// unless absolutely necessary. Better to just make sure that the
// storage deposit is large enough, since it will be returned anyway.
let gas_fee: u64 = MIN_GAS_FEE;
let mut gas_reserve_transfer_account_to_chain: u64 = MIN_GAS_FEE;
if f.params.gas_reserve_transfer_account_to_chain().exists() {
gas_reserve_transfer_account_to_chain =
f.params.gas_reserve_transfer_account_to_chain().value();
}
let mut gas_reserve: u64 = MIN_GAS_FEE;
if f.params.gas_reserve().exists() {
gas_reserve = f.params.gas_reserve().value();
Expand All @@ -275,7 +273,7 @@ pub fn func_withdraw_from_chain(ctx: &ScFuncContext, f: &WithdrawFromChainContex
let xfer = coreaccounts::ScFuncs::transfer_account_to_chain(ctx);
xfer.params.gas_reserve().set_value(gas_reserve);
xfer.func
.transfer_base_tokens(storage_deposit + gas_fee + gas_reserve)
.transfer_base_tokens(storage_deposit + gas_reserve_transfer_account_to_chain + gas_reserve)
.allowance_base_tokens(withdrawal + storage_deposit + gas_reserve)
.post_to_chain(target_chain);
}
Expand Down
1 change: 1 addition & 0 deletions contracts/wasm/testcore/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ funcs:
chainID: ChainID
baseTokens: Uint64
gasReserve: Uint64?
gasReserveTransferAccountToChain: Uint64?

views:
checkContextFromViewEP:
Expand Down
17 changes: 11 additions & 6 deletions contracts/wasm/testcore/test/2chains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,16 @@ func Test2Chains(t *testing.T) {

// allowance for accounts.transferAccountToChain(): SD + GAS1 + GAS2
xferDeposit := wasmlib.StorageDeposit
xferAllowance := xferDeposit + wasmlib.MinGasFee + wasmlib.MinGasFee
const gasFeeTransferAccountToChain = 10 * wasmlib.MinGasFee
const gasReserve = 10 * wasmlib.MinGasFee
const gasWithdrawFromChain = 10 * wasmlib.MinGasFee
xferAllowance := xferDeposit + gasReserve + gasFeeTransferAccountToChain
f := testcore.ScFuncs.WithdrawFromChain(ctx2.Sign(user))
f.Params.ChainID().SetValue(ctx1.CurrentChainID())
f.Params.BaseTokens().SetValue(withdrawalAmount)
f.Func.TransferBaseTokens(xferAllowance + isc.Million).
f.Params.GasReserve().SetValue(gasReserve)
f.Params.GasReserveTransferAccountToChain().SetValue(gasFeeTransferAccountToChain)
f.Func.TransferBaseTokens(xferAllowance + gasWithdrawFromChain).
AllowanceBaseTokens(xferAllowance).Post()
require.NoError(t, ctx2.Err)

Expand All @@ -153,21 +158,21 @@ func Test2Chains(t *testing.T) {
// chain2.testcore account will be credited with SD+GAS1+GAS2, pay actual GAS1,
// and be debited by SD+GAS2+'withdrawalAmount'
bal1.UpdateFeeBalances(ctxAcc1.GasFee)
bal1.Add(testcore2, xferDeposit+wasmlib.MinGasFee+wasmlib.MinGasFee-ctxAcc1.GasFee-xferDeposit-wasmlib.MinGasFee-withdrawalAmount)
bal1.Add(testcore2, xferDeposit+gasWithdrawFromChain+gasWithdrawFromChain-ctxAcc1.GasFee-xferDeposit-gasReserve-withdrawalAmount)
// verify these changes against the actual chain1 account balances
bal1.VerifyBalances(t)

userL1 -= xferAllowance + isc.Million
userL1 -= xferAllowance + gasWithdrawFromChain
require.Equal(t, userL1, user.Balance())

// The gas fees will be credited to chain1.Originator
bal2.UpdateFeeBalances(withdrawalReceipt.GasFeeCharged)
bal2.UpdateFeeBalances(transferReceipt.GasFeeCharged)
// deduct coretest.WithdrawFromChain() gas fee from user's cool million
bal2.Add(user, isc.Million-withdrawalReceipt.GasFeeCharged)
bal2.Add(user, gasWithdrawFromChain-withdrawalReceipt.GasFeeCharged)
// chain2.accounts1 will be credited with SD+GAS2+'withdrawalAmount', pay actual GAS2,
// and be debited by SD+'withdrawalAmount', leaving zero
bal2.Add(accounts1, xferDeposit+wasmlib.MinGasFee+withdrawalAmount-transferReceipt.GasFeeCharged-xferDeposit-withdrawalAmount)
bal2.Add(accounts1, xferDeposit+gasReserve+withdrawalAmount-transferReceipt.GasFeeCharged-xferDeposit-withdrawalAmount)
// chain2.testcore account receives the withdrawn tokens and storage deposit
bal2.Account += withdrawalAmount + xferDeposit
// verify these changes against the actual chain2 account balances
Expand Down
17 changes: 7 additions & 10 deletions contracts/wasm/testcore/ts/testcoreimpl/funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import * as sc from "../testcore/index";

const CONTRACT_NAME_DEPLOYED = "exampleDeployTR";
const MSG_CORE_ONLY_PANIC = "========== core only =========";
const MSG_FULL_PANIC = "========== panic FULL ENTRY POINT =========";
const MSG_VIEW_PANIC = "========== panic VIEW =========";
const MSG_FULL_PANIC = "========== panic FULL ENTRY POINT ==========";
const MSG_VIEW_PANIC = "========== panic VIEW ==========";

export function funcCallOnChain(ctx: wasmlib.ScFuncContext, f: sc.CallOnChainContext): void {
let paramInt = f.params.n().value();
Expand Down Expand Up @@ -228,13 +228,10 @@ export function funcWithdrawFromChain(ctx: wasmlib.ScFuncContext, f: sc.Withdraw
const transfer = wasmlib.ScTransfer.fromBalances(ctx.allowance());
ctx.transferAllowed(ctx.accountID(), transfer);

// This is just a test contract, but normally these numbers should
// be parameters because there is no way for the contract to figure
// out the gas fees on the other chain, and it's also silly to run
// the costly calculation to determine storage deposit every time
// unless absolutely necessary. Better to just make sure that the
// storage deposit is large enough, since it will be returned anyway.
const gasFee: u64 = wasmlib.MinGasFee;
let gasReserveTransferAccountToChain: u64 = wasmlib.MinGasFee;
if (f.params.gasReserveTransferAccountToChain().exists()) {
gasReserveTransferAccountToChain = f.params.gasReserveTransferAccountToChain().value();
}
let gasReserve: u64 = wasmlib.MinGasFee;
if (f.params.gasReserve().exists()) {
gasReserve = f.params.gasReserve().value();
Expand All @@ -247,7 +244,7 @@ export function funcWithdrawFromChain(ctx: wasmlib.ScFuncContext, f: sc.Withdraw
// NOTE: make sure you READ THE DOCS before calling this function
const xfer = coreaccounts.ScFuncs.transferAccountToChain(ctx);
xfer.params.gasReserve().setValue(gasReserve);
xfer.func.transferBaseTokens(storageDeposit + gasFee + gasReserve)
xfer.func.transferBaseTokens(storageDeposit + gasReserveTransferAccountToChain + gasReserve)
.allowanceBaseTokens(withdrawal + storageDeposit + gasReserve)
.postToChain(targetChain);
}
Expand Down
5 changes: 2 additions & 3 deletions packages/chain/cons/cons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
"github.com/iotaledger/wasp/packages/vm/core/accounts"
"github.com/iotaledger/wasp/packages/vm/core/coreprocessors"
"github.com/iotaledger/wasp/packages/vm/core/migrations/allmigrations"
"github.com/iotaledger/wasp/packages/vm/gas"
"github.com/iotaledger/wasp/packages/vm/processors"
"github.com/iotaledger/wasp/packages/vm/vmimpl"
"github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib"
)

// Here we run a single consensus instance, step by step with
Expand Down Expand Up @@ -347,8 +347,7 @@ func testChained(t *testing.T, n, f, b int) {
inccounter.FuncIncCounter.Hname(),
dict.New(),
uint64(i*reqPerBlock+ii),
// FIXME may user other MinGasFee instead of wasmlib.MinGasFee
wasmlib.MinGasFee,
gas.LimitsDefault.MinGasPerRequest,
).Sign(scClient)
reqs = append(reqs, scRequest)
incTotal++
Expand Down
3 changes: 2 additions & 1 deletion packages/solo/ledgerl1l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ func (fp *foundryParams) CreateFoundry() (uint32, iotago.NativeTokenID, error) {
user = fp.user
}
req := CallParamsFromDict(accounts.Contract.Name, accounts.FuncFoundryCreateNew.Name, par).
WithAllowance(isc.NewAssetsBaseTokens(allowanceForFoundryStorageDeposit))
WithAllowance(isc.NewAssetsBaseTokens(allowanceForFoundryStorageDeposit)).
AddBaseTokens(allowanceForFoundryStorageDeposit)

gas, _, err := fp.ch.EstimateGasOnLedger(req, user, true)
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions packages/testutil/testchain/test_chain_ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/iotaledger/wasp/packages/vm/core/migrations/allmigrations"
"github.com/iotaledger/wasp/packages/vm/core/root"
"github.com/iotaledger/wasp/packages/vm/gas"
"github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib"
)

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -87,8 +86,7 @@ func (tcl *TestChainLedger) MakeTxAccountsDeposit(account *cryptolib.KeyPair) []
Metadata: &isc.SendMetadata{
TargetContract: accounts.Contract.Hname(),
EntryPoint: accounts.FuncDeposit.Hname(),
// FIXME may user other MinGasFee instead of wasmlib.MinGasFee
GasBudget: wasmlib.MinGasFee,
GasBudget: 2 * gas.LimitsDefault.MinGasPerRequest,
},
},
},
Expand Down Expand Up @@ -119,8 +117,7 @@ func (tcl *TestChainLedger) MakeTxDeployIncCounterContract() []isc.Request {
root.ParamName: inccounter.Contract.Name,
inccounter.VarCounter: 0,
}),
// FIXME may user other MinGasFee instead of wasmlib.MinGasFee
GasBudget: wasmlib.MinGasFee,
GasBudget: 2 * gas.LimitsDefault.MinGasPerRequest,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/vm/core/accounts/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/iotaledger/wasp/packages/util"
"github.com/iotaledger/wasp/packages/vm"
"github.com/iotaledger/wasp/packages/vm/core/errors/coreerrors"
"github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib"
"github.com/iotaledger/wasp/packages/vm/gas"
)

func CommonAccount() isc.AgentID {
Expand Down Expand Up @@ -176,7 +176,7 @@ func transferAccountToChain(ctx isc.Sandbox) dict.Dict {
assets := allowance.Clone()

// deduct the gas reserve GAS2 from the allowance, if possible
gasReserve := ctx.Params().MustGetUint64(ParamGasReserve, wasmlib.MinGasFee)
gasReserve := ctx.Params().MustGetUint64(ParamGasReserve, gas.LimitsDefault.MinGasPerRequest)
if allowance.BaseTokens < gasReserve {
panic(ErrNotEnoughAllowance)
}
Expand Down
7 changes: 3 additions & 4 deletions packages/vm/core/evm/evmimpl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/iotaledger/wasp/packages/vm/core/evm/iscmagic"
"github.com/iotaledger/wasp/packages/vm/core/governance"
"github.com/iotaledger/wasp/packages/vm/gas"
"github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib"
)

var Processor = evm.Contract.Processor(nil,
Expand Down Expand Up @@ -254,14 +253,14 @@ func registerERC20NativeTokenOnRemoteChain(ctx isc.Sandbox) dict.Dict {
evm.FieldFoundryTokenScheme: codec.EncodeTokenScheme(tokenScheme),
},
// FIXME why does this gas budget is higher than the allowance below
GasBudget: 5 * wasmlib.MinGasFee,
GasBudget: 50 * gas.LimitsDefault.MinGasPerRequest,
},
}
sd := ctx.EstimateRequiredStorageDeposit(req)
// this request is sent by contract account,
// so we move enough allowance for the gas fee below in the req.Assets.AddBaseTokens() function call
ctx.TransferAllowedFunds(ctx.AccountID(), isc.NewAssetsBaseTokens(sd+wasmlib.MinGasFee))
req.Assets.AddBaseTokens(sd + wasmlib.MinGasFee)
ctx.TransferAllowedFunds(ctx.AccountID(), isc.NewAssetsBaseTokens(sd+10*gas.LimitsDefault.MinGasPerRequest))
req.Assets.AddBaseTokens(sd + 10*gas.LimitsDefault.MinGasPerRequest)
ctx.Send(req)

return nil
Expand Down
6 changes: 2 additions & 4 deletions packages/vm/core/evm/evmtest/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/iotaledger/wasp/packages/vm/core/evm/iscmagic"
"github.com/iotaledger/wasp/packages/vm/core/governance"
"github.com/iotaledger/wasp/packages/vm/gas"
"github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib"
)

type soloChainEnv struct {
Expand Down Expand Up @@ -373,9 +372,8 @@ func (e *soloChainEnv) registerERC20ExternalNativeToken(
evm.FieldTargetAddress: codec.EncodeAddress(e.soloChain.ChainID.AsAddress()),
}).
// to cover sd and gas fee for the 'FuncRegisterERC20ExternalNativeToken' func call in 'FuncRegisterERC20NativeTokenOnRemoteChain'
WithAllowance(isc.NewAssetsBaseTokens(2*wasmlib.MinGasFee)).
// FIXME why this gas budget is less than the gas budget of the indirect call FuncRegisterERC20ExternalNativeToken
WithGasBudget(wasmlib.MinGasFee),
WithAllowance(isc.NewAssetsBaseTokens(20*gas.LimitsDefault.MinGasPerRequest)).
WithGasBudget(10*gas.LimitsDefault.MinGasPerRequest),
fromChain.OriginatorPrivateKey)
if err != nil {
return ret, err
Expand Down
12 changes: 7 additions & 5 deletions packages/vm/core/testcore/custom_onledger_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/iotaledger/wasp/packages/testutil/testmisc"
"github.com/iotaledger/wasp/packages/transaction"
"github.com/iotaledger/wasp/packages/vm/core/accounts"
"github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib"
"github.com/iotaledger/wasp/packages/vm/gas"
)

func TestNoSenderFeature(t *testing.T) {
Expand All @@ -28,7 +28,9 @@ func TestNoSenderFeature(t *testing.T) {
// ----------------------------------------------------------------

// mint some NTs and withdraw them
err := ch.DepositAssetsToL2(isc.NewAssetsBaseTokens(10*isc.Million), wallet)
gasFee := 10 * gas.LimitsDefault.MinGasPerRequest
withdrawAmount := 3 * gas.LimitsDefault.MinGasPerRequest
err := ch.DepositAssetsToL2(isc.NewAssetsBaseTokens(withdrawAmount+gasFee), wallet)
require.NoError(t, err)
nativeTokenAmount := big.NewInt(123)
sn, nativeTokenID, err := ch.NewFoundryParams(1234).
Expand All @@ -40,8 +42,8 @@ func TestNoSenderFeature(t *testing.T) {
require.NoError(t, err)

// withdraw native tokens to L1
allowance := 5 * isc.Million
baseTokensToSend := allowance + wasmlib.MinGasFee
allowance := withdrawAmount
baseTokensToSend := allowance + gasFee
_, err = ch.PostRequestOffLedger(solo.NewCallParams(
accounts.Contract.Name, accounts.FuncWithdraw.Name,
).
Expand All @@ -51,7 +53,7 @@ func TestNoSenderFeature(t *testing.T) {
ID: nativeTokenID,
Amount: nativeTokenAmount,
}).
WithGasBudget(wasmlib.MinGasFee),
WithGasBudget(gasFee),
wallet)
require.NoError(t, err)

Expand Down
16 changes: 10 additions & 6 deletions packages/vm/core/testcore/sbtests/2chains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/iotaledger/wasp/packages/vm/core/accounts"
"github.com/iotaledger/wasp/packages/vm/core/corecontracts"
"github.com/iotaledger/wasp/packages/vm/core/testcore/sbtests/sbtestsc"
"github.com/iotaledger/wasp/packages/vm/gas"
"github.com/iotaledger/wasp/packages/wasmvm/wasmlib/go/wasmlib"
)

Expand Down Expand Up @@ -64,7 +65,7 @@ func test2Chains(t *testing.T, w bool) {

// send base tokens to contractAgentID2 (that is an entity of chain2) on chain1
const baseTokensCreditedToScOnChain1 = 10 * isc.Million
const creditBaseTokensToSend = baseTokensCreditedToScOnChain1 + wasmlib.MinGasFee
creditBaseTokensToSend := baseTokensCreditedToScOnChain1 + gas.LimitsDefault.MinGasPerRequest
_, err = chain1.PostRequestSync(solo.NewCallParams(
accounts.Contract.Name, accounts.FuncTransferAllowanceTo.Name,
accounts.ParamAgentID, contractAgentID2,
Expand Down Expand Up @@ -97,10 +98,10 @@ func test2Chains(t *testing.T, w bool) {
// make chain2 send a call to chain1 to withdraw base tokens
baseTokensToWithdrawFromChain1 := baseTokensCreditedToScOnChain1

const gasFee1 = wasmlib.MinGasFee
gasFeeTransferAccountToChain := 10 * gas.LimitsDefault.MinGasPerRequest
// gas reserve for the 'TransferAllowanceTo' func call in 'TransferAccountToChain' func call
const gasReserve = wasmlib.MinGasFee
const withdrawFeeGas = wasmlib.MinGasFee
gasReserve := 10 * gas.LimitsDefault.MinGasPerRequest
withdrawFeeGas := 10 * gas.LimitsDefault.MinGasPerRequest
const storageDeposit = wasmlib.StorageDeposit

// NOTE: make sure you READ THE DOCS for accounts.transferAccountToChain()
Expand All @@ -111,7 +112,7 @@ func test2Chains(t *testing.T, w bool) {
// the gas fees for the chain2.accounts.transferAccountToChain() request and the
// chain1.accounts.transferAllowanceTo() request.
// note that the storage deposit will be returned in the end
withdrawReqAllowance := storageDeposit + gasFee1 + gasReserve
withdrawReqAllowance := storageDeposit + gasFeeTransferAccountToChain + gasReserve

// also cover gas fee for `FuncWithdrawFromChain` on chain2
withdrawBaseTokensToSend := withdrawReqAllowance + withdrawFeeGas
Expand All @@ -121,6 +122,7 @@ func test2Chains(t *testing.T, w bool) {
sbtestsc.ParamChainID, chain1.ChainID,
sbtestsc.ParamBaseTokens, baseTokensToWithdrawFromChain1,
sbtestsc.ParamGasReserve, gasReserve,
sbtestsc.ParamGasReserveTransferAccountToChain, gasFeeTransferAccountToChain,
).
AddBaseTokens(withdrawBaseTokensToSend).
WithAllowance(isc.NewAssetsBaseTokens(withdrawReqAllowance)).
Expand Down Expand Up @@ -165,9 +167,11 @@ func test2Chains(t *testing.T, w bool) {
env.AssertL1BaseTokens(userAddress, utxodb.FundsFromFaucetAmount-creditBaseTokensToSend-withdrawBaseTokensToSend)
// on chain1 user only made the first transaction, so it is the same as its balance before 'WithdrawFromChain' function call
chain1.AssertL2BaseTokens(userAgentID, creditBaseTokensToSend-baseTokensCreditedToScOnChain1-chain1TransferAllowanceGas)
// gasFeeTransferAccountToChain is is used for paying the gas fee of the 'TransferAccountToChain' func call
// in 'WithdrawFromChain' func call
// gasReserve is used for paying the gas fee of the 'TransferAllowanceTo' func call in 'TransferAccountToChain' func call
// So the token left in contractAgentID2 on chain1 is the unused gas fee
chain1.AssertL2BaseTokens(contractAgentID2, gasReserve-chain1TransferAccountToChainGas)
chain1.AssertL2BaseTokens(contractAgentID2, gasFeeTransferAccountToChain-chain1TransferAccountToChainGas)
// tokens in 'withdrawBaseTokensToSend' amount are moved with the request from L1 to L2
// 'withdrawReqAllowance' is is the amount moved from chain1 to chain2 with the request
// 'baseTokensToWithdrawFromChain1' is the amount we assigned to withdraw in 'WithdrawFromChain' func call
Expand Down
Loading

0 comments on commit 6706234

Please sign in to comment.