diff --git a/packages/vm/gas/evm.go b/packages/vm/gas/evm.go index c590bcd1f9..8d902c2867 100644 --- a/packages/vm/gas/evm.go +++ b/packages/vm/gas/evm.go @@ -7,16 +7,25 @@ var DefaultEVMGasRatio = util.Ratio32{A: 1, B: 1} func ISCGasBudgetToEVM(iscGasBudget uint64, gasRatio *util.Ratio32) uint64 { // EVM gas budget = floor(ISC gas budget * B / A) + if gasRatio.A == 0 { + return 0 + } return gasRatio.YFloor64(iscGasBudget) } func ISCGasBurnedToEVM(iscGasBurned uint64, gasRatio *util.Ratio32) uint64 { // estimated EVM gas = ceil(ISC gas burned * B / A) + if gasRatio.A == 0 { + return 0 + } return gasRatio.YCeil64(iscGasBurned) } func EVMGasToISC(evmGas uint64, gasRatio *util.Ratio32) uint64 { // ISC gas burned = ceil(EVM gas * A / B) + if gasRatio.A == 0 { + return 0 + } return gasRatio.XCeil64(evmGas) } diff --git a/tools/cluster/tests/legacy_migration_test.go b/tools/cluster/tests/legacy_migration_test.go index 5d8560d49e..b18600e9b7 100644 --- a/tools/cluster/tests/legacy_migration_test.go +++ b/tools/cluster/tests/legacy_migration_test.go @@ -22,7 +22,9 @@ import ( "github.com/iotaledger/wasp/packages/kv" "github.com/iotaledger/wasp/packages/kv/codec" "github.com/iotaledger/wasp/packages/legacymigration" + "github.com/iotaledger/wasp/packages/vm/core/accounts" "github.com/iotaledger/wasp/packages/vm/core/evm/iscmagic" + "github.com/iotaledger/wasp/packages/vm/core/governance" "github.com/iotaledger/wasp/tools/cluster/templates" ) @@ -71,11 +73,44 @@ func TestMigrationAndBurn(t *testing.T) { require.NoError(t, err) migrationEnv := newChainEnv(t, migrationCluster, migrationChain) + // set gas fee to 0x000000 + migrationOriginatorClient := migrationChain.Client(migrationEnv.Clu.OriginatorKeyPair) + req, err := migrationOriginatorClient.PostOffLedgerRequest( + context.Background(), + governance.Contract.Hname(), + governance.FuncSetFeePolicy.Hname(), + chainclient.PostRequestParams{ + Args: map[kv.Key][]byte{ + governance.ParamFeePolicyBytes: lo.Must(iotago.DecodeHex("0x0000000000000000000000000000000000")), + }, + }, + ) + require.NoError(t, err) + _, err = migrationChain.AllNodesMultiClient().WaitUntilRequestProcessedSuccessfully(migrationChain.ChainID, req.ID(), false, 30*time.Second) + require.NoError(t, err) + // fill the migration contract with funds someWallet, _, err := migrationCluster.NewKeyPairWithFunds() require.NoError(t, err) + // deposit with transfer == allowance + someWalletMigratorChainClient := migrationChain.Client(someWallet) + transfer := isc.NewAssetsBaseTokens(100 * isc.Million) migrationContractAgentID := isc.NewContractAgentID(migrationChain.ChainID, legacymigration.Contract.Hname()) - depositToAgentID(t, migrationChain, 100*isc.Million, migrationContractAgentID, someWallet) + tx, err := someWalletMigratorChainClient.Post1Request( + accounts.Contract.Hname(), + accounts.FuncTransferAllowanceTo.Hname(), + chainclient.PostRequestParams{ + Transfer: transfer, + Args: map[kv.Key][]byte{ + accounts.ParamAgentID: codec.EncodeAgentID(migrationContractAgentID), + }, + Allowance: transfer, + }, + ) + require.NoError(t, err) + _, err = migrationChain.AllNodesMultiClient().WaitUntilAllRequestsProcessedSuccessfully(migrationChain.ChainID, tx, false, 30*time.Second) + require.NoError(t, err) + migBalance := migrationEnv.getBalanceOnChain(migrationContractAgentID, isc.BaseTokenID) require.Positive(t, migBalance)