mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 16:25:21 +00:00
rename denoms
This commit is contained in:
parent
19dd651fe8
commit
849335487e
2
Makefile
2
Makefile
@ -78,7 +78,7 @@ print-machine-info:
|
||||
BUILD_DIR := build# build files
|
||||
BIN_DIR := $(BUILD_DIR)/bin# for binary dev dependencies
|
||||
BUILD_CACHE_DIR := $(BUILD_DIR)/.cache# caching for non-artifact outputs
|
||||
OUT_DIR := out# for artifact intermediates and outputs
|
||||
OUT_DIR := ./.build# for artifact intermediates and outputs
|
||||
|
||||
ROOT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))# absolute path to root
|
||||
export PATH := $(ROOT_DIR)/$(BIN_DIR):$(PATH)# add local bin first in path
|
||||
|
@ -62,11 +62,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||
bank.MsgSend{
|
||||
FromAddress: fromAddr,
|
||||
ToAddress: toAddr,
|
||||
Amount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e6)),
|
||||
Amount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e6)),
|
||||
},
|
||||
},
|
||||
Fee: auth.StdFee{
|
||||
Amount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(5e4)),
|
||||
Amount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(5e4)),
|
||||
Gas: 1e6,
|
||||
},
|
||||
Memo: "test memo",
|
||||
|
@ -68,7 +68,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
chainID,
|
||||
app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e9)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e9)),
|
||||
testAddresses,
|
||||
),
|
||||
newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
||||
@ -116,7 +116,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
tc.address,
|
||||
testAddresses[0],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1_000_000)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
|
@ -46,7 +46,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100_000_000)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -81,12 +81,12 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||
),
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[2],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -122,7 +122,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
|
@ -59,7 +59,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100e6)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)),
|
||||
),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -129,7 +129,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
[]sdk.Msg{banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100e6)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)),
|
||||
)}),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -162,7 +162,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100e6)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100e6)),
|
||||
),
|
||||
&evmtypes.MsgEthereumTx{},
|
||||
},
|
||||
|
@ -157,7 +157,7 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
// Genesis states
|
||||
evmGs := evmtypes.NewGenesisState(
|
||||
evmtypes.NewParams(
|
||||
chaincfg.BaseDenom, // evmDenom
|
||||
chaincfg.EvmDenom, // evmDenom
|
||||
false, // allowedUnprotectedTxs
|
||||
true, // enableCreate
|
||||
true, // enableCall
|
||||
@ -223,10 +223,10 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||
}
|
||||
|
||||
// funds our test accounts with some auxiliary denom
|
||||
// funds our test accounts with some gas denom
|
||||
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e9)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e9)),
|
||||
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
||||
)
|
||||
|
||||
@ -376,7 +376,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
|
||||
suite.tApp.FundModuleAccount(
|
||||
suite.ctx,
|
||||
evmutiltypes.ModuleName,
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(0)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(0)),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
||||
@ -476,7 +476,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
errMsg: "insufficient funds",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
bk := suite.tApp.GetBankKeeper()
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.AuxiliaryDenom)
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.GasDenom)
|
||||
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
||||
return txBuilder
|
||||
},
|
||||
@ -488,7 +488,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx: true,
|
||||
errMsg: "invalid chain-id",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(20))
|
||||
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -501,7 +501,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx: true,
|
||||
errMsg: "invalid pubkey",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(20))
|
||||
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -529,7 +529,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
msgs = tc.updateMsgs(msgs)
|
||||
}
|
||||
|
||||
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(20))
|
||||
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -603,7 +603,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
||||
}
|
||||
|
||||
// deliver deposit msg
|
||||
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(20))
|
||||
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(20))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
||||
)
|
||||
|
@ -31,7 +31,7 @@ func TestEvmMinGasFilter(t *testing.T) {
|
||||
|
||||
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
||||
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
||||
EvmDenom: chaincfg.BaseDenom,
|
||||
EvmDenom: chaincfg.EvmDenom,
|
||||
})
|
||||
|
||||
testCases := []struct {
|
||||
|
@ -34,7 +34,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreateVestingAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||
false,
|
||||
),
|
||||
@ -45,7 +45,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreatePermanentLockedAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||
),
|
||||
true,
|
||||
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||
@ -64,7 +64,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"other messages not affected",
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100)),
|
||||
),
|
||||
false,
|
||||
"",
|
||||
|
@ -153,7 +153,7 @@ func GenesisStateWithSingleValidator(
|
||||
balances := []banktypes.Balance{
|
||||
{
|
||||
Address: acc.GetAddress().String(),
|
||||
Coins: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100000000000000)),
|
||||
Coins: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(100000000000000)),
|
||||
},
|
||||
}
|
||||
|
||||
@ -216,7 +216,7 @@ func genesisStateWithValSet(
|
||||
}
|
||||
// set validators and delegations
|
||||
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
||||
currentStakingGenesis.Params.BondDenom = chaincfg.AuxiliaryDenom // TODO:
|
||||
currentStakingGenesis.Params.BondDenom = chaincfg.GasDenom // TODO:
|
||||
|
||||
stakingGenesis := stakingtypes.NewGenesisState(
|
||||
currentStakingGenesis.Params,
|
||||
@ -236,13 +236,13 @@ func genesisStateWithValSet(
|
||||
|
||||
for range delegations {
|
||||
// add delegated tokens to total supply
|
||||
totalSupply = totalSupply.Add(chaincfg.MakeCoinForAuxiliaryDenom(bondAmt))
|
||||
totalSupply = totalSupply.Add(chaincfg.MakeCoinForGasDenom(bondAmt))
|
||||
}
|
||||
|
||||
// add bonded amount to bonded pool module account
|
||||
balances = append(balances, banktypes.Balance{
|
||||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
||||
Coins: sdk.Coins{chaincfg.MakeCoinForAuxiliaryDenom(bondAmt)},
|
||||
Coins: sdk.Coins{chaincfg.MakeCoinForGasDenom(bondAmt)},
|
||||
})
|
||||
|
||||
bankGenesis := banktypes.NewGenesisState(
|
||||
|
@ -44,12 +44,12 @@ func MakeCoinForStandardDenom(amount any) sdk.Coin {
|
||||
return makeCoin(StandardDenom, toBigInt(amount))
|
||||
}
|
||||
|
||||
func MakeCoinForAuxiliaryDenom(amount any) sdk.Coin {
|
||||
return makeCoin(AuxiliaryDenom, toBigInt(amount))
|
||||
func MakeCoinForGasDenom(amount any) sdk.Coin {
|
||||
return makeCoin(GasDenom, toBigInt(amount))
|
||||
}
|
||||
|
||||
func MakeCoinForBaseDenom(amount any) sdk.Coin {
|
||||
return makeCoin(BaseDenom, toBigInt(amount))
|
||||
func MakeCoinForEvmDenom(amount any) sdk.Coin {
|
||||
return makeCoin(EvmDenom, toBigInt(amount))
|
||||
}
|
||||
|
||||
func makeCoin(denom string, amount *big.Int) sdk.Coin {
|
||||
|
@ -7,31 +7,31 @@ import (
|
||||
const (
|
||||
StandardDenom = "a0gi"
|
||||
|
||||
AuxiliaryDenom = "ua0gi"
|
||||
GasDenom = "ua0gi"
|
||||
|
||||
BaseDenom = "neuron"
|
||||
EvmDenom = "neuron"
|
||||
|
||||
BondDenom = BaseDenom
|
||||
BondDenom = EvmDenom
|
||||
|
||||
AuxiliaryDenomUnit = 6
|
||||
GasDenomUnit = 6
|
||||
|
||||
BaseDenomUnit = 18
|
||||
EvmDenomUnit = 18
|
||||
|
||||
AuxiliaryDenomConversionMultiplier = 1e12
|
||||
BaseDenomConversionMultiplier = 1e18
|
||||
GasDenomConversionMultiplier = 1e12
|
||||
EvmDenomConversionMultiplier = 1e18
|
||||
)
|
||||
|
||||
// RegisterDenoms registers the base and auxiliary denominations to the SDK.
|
||||
// RegisterDenoms registers the base and gas denominations to the SDK.
|
||||
func RegisterDenoms() {
|
||||
if err := sdk.RegisterDenom(StandardDenom, sdk.OneDec()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := sdk.RegisterDenom(AuxiliaryDenom, sdk.NewDecWithPrec(1, AuxiliaryDenomUnit)); err != nil {
|
||||
if err := sdk.RegisterDenom(GasDenom, sdk.NewDecWithPrec(1, GasDenomUnit)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := sdk.RegisterDenom(BaseDenom, sdk.NewDecWithPrec(1, BaseDenomUnit)); err != nil {
|
||||
if err := sdk.RegisterDenom(EvmDenom, sdk.NewDecWithPrec(1, EvmDenomUnit)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -17,15 +17,15 @@ func TestRegisterDenoms(t *testing.T) {
|
||||
expErr error
|
||||
}{
|
||||
{
|
||||
"standard to auxiliary",
|
||||
"standard to gas",
|
||||
MakeCoinForStandardDenom(99),
|
||||
AuxiliaryDenom,
|
||||
MakeCoinForAuxiliaryDenom(99 * (BaseDenomConversionMultiplier / AuxiliaryDenomConversionMultiplier)),
|
||||
GasDenom,
|
||||
MakeCoinForGasDenom(99 * (EvmDenomConversionMultiplier / GasDenomConversionMultiplier)),
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"auxiliary to standard",
|
||||
MakeCoinForAuxiliaryDenom(5e7),
|
||||
"gas to standard",
|
||||
MakeCoinForGasDenom(5e7),
|
||||
StandardDenom,
|
||||
MakeCoinForStandardDenom(50),
|
||||
nil,
|
||||
@ -33,29 +33,29 @@ func TestRegisterDenoms(t *testing.T) {
|
||||
{
|
||||
"standard to base",
|
||||
MakeCoinForStandardDenom(22),
|
||||
BaseDenom,
|
||||
MakeCoinForBaseDenom(22 * BaseDenomConversionMultiplier),
|
||||
EvmDenom,
|
||||
MakeCoinForEvmDenom(22 * EvmDenomConversionMultiplier),
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"base to standard",
|
||||
MakeCoinForBaseDenom("97000000000000000000"),
|
||||
MakeCoinForEvmDenom("97000000000000000000"),
|
||||
StandardDenom,
|
||||
MakeCoinForStandardDenom(97),
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"auxiliary to base",
|
||||
MakeCoinForAuxiliaryDenom(33),
|
||||
BaseDenom,
|
||||
MakeCoinForBaseDenom(33 * AuxiliaryDenomConversionMultiplier),
|
||||
"gas to base",
|
||||
MakeCoinForGasDenom(33),
|
||||
EvmDenom,
|
||||
MakeCoinForEvmDenom(33 * GasDenomConversionMultiplier),
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"base to auxiliary",
|
||||
MakeCoinForBaseDenom("770000000000000"),
|
||||
AuxiliaryDenom,
|
||||
MakeCoinForAuxiliaryDenom(770000000000000 / AuxiliaryDenomConversionMultiplier),
|
||||
"base to gas",
|
||||
MakeCoinForEvmDenom("770000000000000"),
|
||||
GasDenom,
|
||||
MakeCoinForGasDenom(770000000000000 / GasDenomConversionMultiplier),
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
@ -3580,7 +3580,7 @@ paths:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit
|
||||
base represents the evm denom (should be the DenomUnit
|
||||
with exponent = 0).
|
||||
display:
|
||||
type: string
|
||||
@ -3787,7 +3787,7 @@ paths:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit
|
||||
base represents the evm denom (should be the DenomUnit
|
||||
with exponent = 0).
|
||||
display:
|
||||
type: string
|
||||
@ -38218,7 +38218,7 @@ definitions:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit with exponent
|
||||
base represents the evm denom (should be the DenomUnit with exponent
|
||||
= 0).
|
||||
display:
|
||||
type: string
|
||||
@ -38397,7 +38397,7 @@ definitions:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit with
|
||||
base represents the evm denom (should be the DenomUnit with
|
||||
exponent = 0).
|
||||
display:
|
||||
type: string
|
||||
@ -38553,7 +38553,7 @@ definitions:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit with
|
||||
base represents the evm denom (should be the DenomUnit with
|
||||
exponent = 0).
|
||||
display:
|
||||
type: string
|
||||
|
@ -129,9 +129,9 @@ paths:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible
|
||||
DenomTrace contains the evm denomination for ICS20 fungible
|
||||
tokens and the
|
||||
|
||||
source tracing information path.
|
||||
@ -263,9 +263,9 @@ paths:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible
|
||||
DenomTrace contains the evm denomination for ICS20 fungible
|
||||
tokens and the
|
||||
|
||||
source tracing information path.
|
||||
@ -13640,9 +13640,9 @@ definitions:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible tokens and
|
||||
DenomTrace contains the evm denomination for ICS20 fungible tokens and
|
||||
the
|
||||
|
||||
source tracing information path.
|
||||
@ -13696,9 +13696,9 @@ definitions:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible tokens
|
||||
DenomTrace contains the evm denomination for ICS20 fungible tokens
|
||||
and the
|
||||
|
||||
source tracing information path.
|
||||
@ -13722,9 +13722,9 @@ definitions:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible tokens
|
||||
DenomTrace contains the evm denomination for ICS20 fungible tokens
|
||||
and the
|
||||
|
||||
source tracing information path.
|
||||
|
@ -16793,7 +16793,7 @@ paths:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit
|
||||
base represents the evm denom (should be the DenomUnit
|
||||
with exponent = 0).
|
||||
display:
|
||||
type: string
|
||||
@ -17000,7 +17000,7 @@ paths:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit
|
||||
base represents the evm denom (should be the DenomUnit
|
||||
with exponent = 0).
|
||||
display:
|
||||
type: string
|
||||
@ -41400,9 +41400,9 @@ paths:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible
|
||||
DenomTrace contains the evm denomination for ICS20 fungible
|
||||
tokens and the
|
||||
|
||||
source tracing information path.
|
||||
@ -41534,9 +41534,9 @@ paths:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible
|
||||
DenomTrace contains the evm denomination for ICS20 fungible
|
||||
tokens and the
|
||||
|
||||
source tracing information path.
|
||||
@ -60533,7 +60533,7 @@ definitions:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit with exponent
|
||||
base represents the evm denom (should be the DenomUnit with exponent
|
||||
= 0).
|
||||
display:
|
||||
type: string
|
||||
@ -60712,7 +60712,7 @@ definitions:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit with
|
||||
base represents the evm denom (should be the DenomUnit with
|
||||
exponent = 0).
|
||||
display:
|
||||
type: string
|
||||
@ -60868,7 +60868,7 @@ definitions:
|
||||
base:
|
||||
type: string
|
||||
description: >-
|
||||
base represents the base denom (should be the DenomUnit with
|
||||
base represents the evm denom (should be the DenomUnit with
|
||||
exponent = 0).
|
||||
display:
|
||||
type: string
|
||||
@ -84451,9 +84451,9 @@ definitions:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible tokens and
|
||||
DenomTrace contains the evm denomination for ICS20 fungible tokens and
|
||||
the
|
||||
|
||||
source tracing information path.
|
||||
@ -84507,9 +84507,9 @@ definitions:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible tokens
|
||||
DenomTrace contains the evm denomination for ICS20 fungible tokens
|
||||
and the
|
||||
|
||||
source tracing information path.
|
||||
@ -84533,9 +84533,9 @@ definitions:
|
||||
source of the fungible token.
|
||||
base_denom:
|
||||
type: string
|
||||
description: base denomination of the relayed fungible token.
|
||||
description: evm denomination of the relayed fungible token.
|
||||
description: >-
|
||||
DenomTrace contains the base denomination for ICS20 fungible tokens
|
||||
DenomTrace contains the evm denomination for ICS20 fungible tokens
|
||||
and the
|
||||
|
||||
source tracing information path.
|
||||
|
@ -81,7 +81,7 @@ func NewRootCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.AuxiliaryDenom)
|
||||
customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.GasDenom)
|
||||
|
||||
return server.InterceptConfigsPreRunHandler(
|
||||
cmd,
|
||||
@ -137,7 +137,7 @@ func addSubCmds(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, de
|
||||
ac.addStartCmdFlags,
|
||||
)
|
||||
|
||||
// add keybase, auxiliary RPC, query, and tx child commands
|
||||
// add keybase, gas RPC, query, and tx child commands
|
||||
rootCmd.AddCommand(
|
||||
newQueryCmd(),
|
||||
newTxCmd(),
|
||||
|
@ -24,7 +24,7 @@ DATA=~/.0gchain
|
||||
# remove any old state and config
|
||||
rm -rf $DATA
|
||||
|
||||
BINARY=0gchaind
|
||||
BINARY=./.build/0gchaind
|
||||
|
||||
# Create new data directory, overwriting any that alread existed
|
||||
chainID="zgchain_8888-1"
|
||||
|
@ -42,7 +42,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -65,7 +65,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -98,7 +98,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -126,25 +126,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(4e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(4e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +30 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -160,36 +160,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
expectedPeriods := []vestingtypes.Period{
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated")
|
||||
assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period")
|
||||
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(3e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(3e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -199,35 +199,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(3e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(3e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
vacc := createVestingAccount(balance, vestingStartTime, periods)
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))))
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))))
|
||||
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func (suite *IntegrationTestSuite) setupAccountWithCosmosCoinERC20Balance(
|
||||
tx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&msg},
|
||||
GasLimit: 4e5,
|
||||
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(400)),
|
||||
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(400)),
|
||||
Data: "converting sdk coin to erc20",
|
||||
}
|
||||
res := user.SignAndBroadcastZgChainTx(tx)
|
||||
@ -103,7 +103,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
tx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertToErc20Msg},
|
||||
GasLimit: 2e6,
|
||||
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(2000)),
|
||||
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(2000)),
|
||||
Data: "converting sdk coin to erc20",
|
||||
}
|
||||
res := user.SignAndBroadcastZgChainTx(tx)
|
||||
@ -145,7 +145,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
tx = util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertFromErc20Msg},
|
||||
GasLimit: 2e5,
|
||||
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(200)),
|
||||
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(200)),
|
||||
Data: "converting erc20 to cosmos coin",
|
||||
}
|
||||
res = user.SignAndBroadcastZgChainTx(tx)
|
||||
@ -184,7 +184,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
user,
|
||||
suite.ZgChain,
|
||||
2e6,
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e4)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e4)),
|
||||
[]sdk.Msg{&convertToErc20Msg},
|
||||
"this is a memo",
|
||||
).GetTx()
|
||||
@ -238,7 +238,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
user,
|
||||
suite.ZgChain,
|
||||
2e5,
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(200)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(200)),
|
||||
[]sdk.Msg{&convertFromErc20Msg},
|
||||
"",
|
||||
).GetTx()
|
||||
@ -332,7 +332,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
"cosmo-coin-converter-complex-alice", initialAliceAmount,
|
||||
)
|
||||
|
||||
gasMoney := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e5))
|
||||
gasMoney := sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e5))
|
||||
bob := suite.ZgChain.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
||||
amount := big.NewInt(1e3) // test assumes this is half of alice's balance.
|
||||
|
||||
@ -413,7 +413,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
convertTx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertMsg},
|
||||
GasLimit: 2e5,
|
||||
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(200)),
|
||||
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(200)),
|
||||
Data: "bob converts his new erc20 to an sdk.Coin",
|
||||
}
|
||||
convertRes := bob.SignAndBroadcastZgChainTx(convertTx)
|
||||
|
@ -20,7 +20,7 @@ func (suite *IntegrationTestSuite) TestEthCallToGreeterContract() {
|
||||
// this test manipulates state of the Greeter contract which means other tests shouldn't use it.
|
||||
|
||||
// setup funded account to interact with contract
|
||||
user := suite.ZgChain.NewFundedAccount("greeter-contract-user", sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e6)))
|
||||
user := suite.ZgChain.NewFundedAccount("greeter-contract-user", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e6)))
|
||||
|
||||
greeterAddr := suite.ZgChain.ContractAddrs["greeter"]
|
||||
contract, err := greeter.NewGreeter(greeterAddr, suite.ZgChain.EvmClient)
|
||||
@ -63,12 +63,12 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
||||
|
||||
func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// create new funded account
|
||||
sender := suite.ZgChain.NewFundedAccount("eip712-msgSend", sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(2e4)))
|
||||
sender := suite.ZgChain.NewFundedAccount("eip712-msgSend", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(2e4)))
|
||||
receiver := app.RandomAddress()
|
||||
|
||||
// setup message for sending some auxiliary denom to random receiver
|
||||
// setup message for sending some gas denom to random receiver
|
||||
msgs := []sdk.Msg{
|
||||
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e3))),
|
||||
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e3))),
|
||||
}
|
||||
|
||||
// create tx
|
||||
@ -76,7 +76,7 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
sender,
|
||||
suite.ZgChain,
|
||||
1e6,
|
||||
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e4)),
|
||||
sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e4)),
|
||||
msgs,
|
||||
"this is a memo",
|
||||
).GetTx()
|
||||
@ -95,10 +95,10 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
suite.NoError(err)
|
||||
|
||||
// check that the message was processed & the auxiliary denom is transferred.
|
||||
// check that the message was processed & the gas denom is transferred.
|
||||
balRes, err := suite.ZgChain.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
Address: receiver.String(),
|
||||
Denom: chaincfg.AuxiliaryDenom,
|
||||
Denom: chaincfg.GasDenom,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdk.NewInt(1e3), balRes.Balance.Amount)
|
||||
@ -113,7 +113,7 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// sdkDenom := suite.DeployedErc20.CosmosDenom
|
||||
|
||||
// // create new funded account
|
||||
// depositor := suite.ZgChain.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e5)))
|
||||
// depositor := suite.ZgChain.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e5)))
|
||||
// // give them erc20 balance to deposit
|
||||
// fundRes := suite.FundZgChainErc20Balance(depositor.EvmAddress, amount.BigInt())
|
||||
// suite.NoError(fundRes.Err)
|
||||
@ -143,7 +143,7 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// depositor,
|
||||
// suite.ZgChain,
|
||||
// 1e6,
|
||||
// sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e4)),
|
||||
// sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e4)),
|
||||
// msgs,
|
||||
// "doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit",
|
||||
// ).GetTx()
|
||||
@ -189,7 +189,7 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// withdrawAndConvertBack := util.ZgChainMsgRequest{
|
||||
// Msgs: []sdk.Msg{&withdraw, &convertBack},
|
||||
// GasLimit: 1e6,
|
||||
// FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1000)),
|
||||
// FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1000)),
|
||||
// Data: "withdrawing from mint & converting back to erc20",
|
||||
// }
|
||||
// lastRes := depositor.SignAndBroadcastZgChainTx(withdrawAndConvertBack)
|
||||
|
@ -24,10 +24,10 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
|
||||
minGasPrices, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||
suite.NoError(err)
|
||||
|
||||
// evm uses base denom, get base denom min fee
|
||||
evmMinGas := minGasPrices.AmountOf(chaincfg.BaseDenom).TruncateInt().BigInt()
|
||||
// evm uses evm denom, get evm denom min fee
|
||||
evmMinGas := minGasPrices.AmountOf(chaincfg.EvmDenom).TruncateInt().BigInt()
|
||||
|
||||
// returns eth_gasPrice, units in auxiliary denom
|
||||
// returns eth_gasPrice, units in gas denom
|
||||
gasPrice, err := suite.ZgChain.EvmClient.SuggestGasPrice(context.Background())
|
||||
suite.NoError(err)
|
||||
|
||||
@ -38,13 +38,13 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
||||
suite.SkipIfKvtoolDisabled()
|
||||
|
||||
// setup sender & receiver
|
||||
sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e3)))
|
||||
sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(chaincfg.MakeCoinForGasDenom(1e3)))
|
||||
randoReceiver := util.SdkToEvmAddress(app.RandomAddress())
|
||||
|
||||
// get min gas price for evm (from app.toml)
|
||||
minFees, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||
suite.NoError(err)
|
||||
minGasPrice := minFees.AmountOf(chaincfg.BaseDenom).TruncateInt()
|
||||
minGasPrice := minFees.AmountOf(chaincfg.EvmDenom).TruncateInt()
|
||||
|
||||
// attempt tx with less than min gas price (min fee - 1)
|
||||
tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt()
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
minEvmGasPrice = big.NewInt(1e10) // base denom
|
||||
minEvmGasPrice = big.NewInt(1e10) // evm denom
|
||||
)
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
@ -54,7 +54,7 @@ func (suite *IntegrationTestSuite) TestChainID() {
|
||||
|
||||
// example test that funds a new account & queries its balance
|
||||
func (suite *IntegrationTestSuite) TestFundedAccount() {
|
||||
funds := chaincfg.MakeCoinForAuxiliaryDenom(1e3)
|
||||
funds := chaincfg.MakeCoinForGasDenom(1e3)
|
||||
acc := suite.ZgChain.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
||||
|
||||
// check that the sdk & evm signers are for the same account
|
||||
@ -63,21 +63,21 @@ func (suite *IntegrationTestSuite) TestFundedAccount() {
|
||||
|
||||
// check balance via SDK query
|
||||
res, err := suite.ZgChain.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
||||
acc.SdkAddress, chaincfg.AuxiliaryDenom,
|
||||
acc.SdkAddress, chaincfg.GasDenom,
|
||||
))
|
||||
suite.NoError(err)
|
||||
suite.Equal(funds, *res.Balance)
|
||||
|
||||
// check balance via EVM query
|
||||
baseDenomBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
|
||||
evmDenomBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
|
||||
suite.NoError(err)
|
||||
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), baseDenomBal)
|
||||
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), evmDenomBal)
|
||||
}
|
||||
|
||||
// example test that signs & broadcasts an EVM tx
|
||||
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||
// fund an account that can perform the transfer
|
||||
initialFunds := chaincfg.MakeCoinForAuxiliaryDenom(1e6) // 1 (auxiliary denom)
|
||||
initialFunds := chaincfg.MakeCoinForGasDenom(1e6) // 1 (gas denom)
|
||||
acc := suite.ZgChain.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
|
||||
|
||||
// get a rando account to send 0gchain to
|
||||
@ -89,10 +89,10 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||
suite.NoError(err)
|
||||
suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs
|
||||
|
||||
// transfer auxiliary denom over EVM
|
||||
AuxiliaryDenomToTransfer := big.NewInt(1e17) // .1 (auxiliary denom); base denom has 18 decimals.
|
||||
// transfer gas denom over EVM
|
||||
GasDenomToTransfer := big.NewInt(1e17) // .1 (gas denom); evm denom has 18 decimals.
|
||||
req := util.EvmTxRequest{
|
||||
Tx: ethtypes.NewTransaction(nonce, to, AuxiliaryDenomToTransfer, 1e5, minEvmGasPrice, nil),
|
||||
Tx: ethtypes.NewTransaction(nonce, to, GasDenomToTransfer, 1e5, minEvmGasPrice, nil),
|
||||
Data: "any ol' data to track this through the system",
|
||||
}
|
||||
res := acc.SignAndBroadcastEvmTx(req)
|
||||
@ -100,31 +100,31 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||
suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status)
|
||||
|
||||
// evm txs refund unused gas. so to know the expected balance we need to know how much gas was used.
|
||||
AuxiliaryDenomUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
|
||||
GasDenomUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
|
||||
Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)).
|
||||
QuoRaw(1e12) // convert base denom to auxiliary denom
|
||||
QuoRaw(1e12) // convert evm denom to gas denom
|
||||
|
||||
// expect (9 - gas used) (auxiliary denom) remaining in account.
|
||||
// expect (9 - gas used) (gas denom) remaining in account.
|
||||
balance := suite.ZgChain.QuerySdkForBalances(acc.SdkAddress)
|
||||
suite.Equal(sdkmath.NewInt(9e5).Sub(AuxiliaryDenomUsedForGas), balance.AmountOf(chaincfg.AuxiliaryDenom))
|
||||
suite.Equal(sdkmath.NewInt(9e5).Sub(GasDenomUsedForGas), balance.AmountOf(chaincfg.GasDenom))
|
||||
}
|
||||
|
||||
// TestIbcTransfer transfers (auxiliary denom) from the primary 0g-chain (suite.ZgChain) to the ibc chain (suite.Ibc).
|
||||
// TestIbcTransfer transfers (gas denom) from the primary 0g-chain (suite.ZgChain) to the ibc chain (suite.Ibc).
|
||||
// Note that because the IBC chain also runs 0g-chain's binary, this tests both the sending & receiving.
|
||||
func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
||||
suite.SkipIfIbcDisabled()
|
||||
|
||||
// ARRANGE
|
||||
// setup 0g-chain account
|
||||
funds := chaincfg.MakeCoinForAuxiliaryDenom(1e5) // .1 (auxiliary denom)
|
||||
funds := chaincfg.MakeCoinForGasDenom(1e5) // .1 (gas denom)
|
||||
zgChainAcc := suite.ZgChain.NewFundedAccount("ibc-transfer-0g-side", sdk.NewCoins(funds))
|
||||
// setup ibc account
|
||||
ibcAcc := suite.Ibc.NewFundedAccount("ibc-transfer-ibc-side", sdk.NewCoins())
|
||||
|
||||
gasLimit := int64(2e5)
|
||||
fee := chaincfg.MakeCoinForAuxiliaryDenom(200)
|
||||
fee := chaincfg.MakeCoinForGasDenom(200)
|
||||
|
||||
fundsToSend := chaincfg.MakeCoinForAuxiliaryDenom(5e4) // .005 (auxiliary denom)
|
||||
fundsToSend := chaincfg.MakeCoinForGasDenom(5e4) // .005 (gas denom)
|
||||
transferMsg := ibctypes.NewMsgTransfer(
|
||||
testutil.IbcPort,
|
||||
testutil.IbcChannel,
|
||||
@ -154,7 +154,7 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
||||
// the balance should be deducted from 0g-chain account
|
||||
suite.Eventually(func() bool {
|
||||
balance := suite.ZgChain.QuerySdkForBalances(zgChainAcc.SdkAddress)
|
||||
return balance.AmountOf(chaincfg.AuxiliaryDenom).Equal(expectedSrcBalance.Amount)
|
||||
return balance.AmountOf(chaincfg.GasDenom).Equal(expectedSrcBalance.Amount)
|
||||
}, 10*time.Second, 1*time.Second)
|
||||
|
||||
// expect the balance to be transferred to the ibc chain!
|
||||
|
@ -101,13 +101,13 @@ func (suite *IntegrationTestSuite) TestModuleAccountGovTransfers() {
|
||||
name: "transfer from community to kavadist for incentive rewards",
|
||||
sender: communityAcc,
|
||||
receiver: zgChainDistAcc,
|
||||
amount: chaincfg.MakeCoinForAuxiliaryDenom(100),
|
||||
amount: chaincfg.MakeCoinForGasDenom(100),
|
||||
},
|
||||
{
|
||||
name: "transfer from kavadist to community",
|
||||
sender: zgChainDistAcc,
|
||||
receiver: communityAcc,
|
||||
amount: chaincfg.MakeCoinForAuxiliaryDenom(50),
|
||||
amount: chaincfg.MakeCoinForGasDenom(50),
|
||||
},
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ func (suite *IntegrationTestSuite) submitAndPassProposal(msgs []sdk.Msg) int64 {
|
||||
suite.NoError(err)
|
||||
|
||||
gasLimit := 1e6
|
||||
fee := chaincfg.MakeCoinForBaseDenom(1e15)
|
||||
fee := chaincfg.MakeCoinForEvmDenom(1e15)
|
||||
|
||||
req := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{proposalMsg},
|
||||
|
@ -74,7 +74,7 @@ var (
|
||||
EvmRpcUrl: "http://localhost:8545",
|
||||
|
||||
ChainId: "0gchainlocalnet_8888-1",
|
||||
StakingDenom: chaincfg.AuxiliaryDenom,
|
||||
StakingDenom: chaincfg.GasDenom,
|
||||
}
|
||||
kvtoolIbcChain = ChainDetails{
|
||||
RpcUrl: "http://localhost:26658",
|
||||
|
@ -262,7 +262,7 @@ func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.ZgCh
|
||||
util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)},
|
||||
GasLimit: 2e5, // 200,000 gas
|
||||
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001 auxiliary denom
|
||||
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001 gas denom
|
||||
Data: fmt.Sprintf("sending %s to %s", amount, to),
|
||||
},
|
||||
)
|
||||
|
@ -98,7 +98,7 @@ message Metadata {
|
||||
string description = 1;
|
||||
// denom_units represents the list of DenomUnit's for a given coin
|
||||
repeated DenomUnit denom_units = 2;
|
||||
// base represents the base denom (should be the DenomUnit with exponent = 0).
|
||||
// base represents the evm denom (should be the DenomUnit with exponent = 0).
|
||||
string base = 3;
|
||||
// display indicates the suggested denom that should be
|
||||
// displayed in clients.
|
||||
|
6
third_party/proto/cosmos/tx/v1beta1/tx.proto
vendored
6
third_party/proto/cosmos/tx/v1beta1/tx.proto
vendored
@ -234,18 +234,18 @@ message Tip {
|
||||
string tipper = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
}
|
||||
|
||||
// AuxSignerData is the intermediary format that an auxiliary signer (e.g. a
|
||||
// AuxSignerData is the intermediary format that an gas signer (e.g. a
|
||||
// tipper) builds and sends to the fee payer (who will build and broadcast the
|
||||
// actual tx). AuxSignerData is not a valid tx in itself, and will be rejected
|
||||
// by the node if sent directly as-is.
|
||||
//
|
||||
// Since: cosmos-sdk 0.46
|
||||
message AuxSignerData {
|
||||
// address is the bech32-encoded address of the auxiliary signer. If using
|
||||
// address is the bech32-encoded address of the gas signer. If using
|
||||
// AuxSignerData across different chains, the bech32 prefix of the target
|
||||
// chain (where the final transaction is broadcasted) should be used.
|
||||
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
|
||||
// sign_doc is the SIGN_MODE_DIRECT_AUX sign doc that the auxiliary signer
|
||||
// sign_doc is the SIGN_MODE_DIRECT_AUX sign doc that the gas signer
|
||||
// signs. Note: we use the same sign doc even if we're signing with
|
||||
// LEGACY_AMINO_JSON.
|
||||
SignDocDirectAux sign_doc = 2;
|
||||
|
@ -6,13 +6,13 @@ option go_package = "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types";
|
||||
|
||||
import "gogoproto/gogo.proto";
|
||||
|
||||
// DenomTrace contains the base denomination for ICS20 fungible tokens and the
|
||||
// DenomTrace contains the evm denomination for ICS20 fungible tokens and the
|
||||
// source tracing information path.
|
||||
message DenomTrace {
|
||||
// path defines the chain of port/channel identifiers used for tracing the
|
||||
// source of the fungible token.
|
||||
string path = 1;
|
||||
// base denomination of the relayed fungible token.
|
||||
// evm denomination of the relayed fungible token.
|
||||
string base_denom = 2;
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ func (suite *MsgServerTestSuite) SetupTest() {
|
||||
|
||||
// Set up genesis state and initialize
|
||||
_, addrs := app.GeneratePrivKeyAddressPairs(3)
|
||||
coins := sdk.NewCoins(c("bnb", 10000000000), c(chaincfg.AuxiliaryDenom, 10000))
|
||||
coins := sdk.NewCoins(c("bnb", 10000000000), c(chaincfg.GasDenom, 10000))
|
||||
authGS := app.NewFundedGenStateWithSameCoins(tApp.AppCodec(), coins, addrs)
|
||||
tApp.InitializeFromGenesisStates(authGS, NewBep3GenStateMulti(cdc, addrs[0]))
|
||||
|
||||
|
@ -20,7 +20,7 @@ type GenesisTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *GenesisTestSuite) SetupTest() {
|
||||
coin := chaincfg.MakeCoinForAuxiliaryDenom(1)
|
||||
coin := chaincfg.MakeCoinForGasDenom(1)
|
||||
suite.swaps = atomicSwaps(10)
|
||||
|
||||
supply := types.NewAssetSupply(coin, coin, coin, coin, time.Duration(0))
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
)
|
||||
|
||||
func TestAssetSupplyValidate(t *testing.T) {
|
||||
coin := chaincfg.MakeCoinForAuxiliaryDenom(1)
|
||||
coin := chaincfg.MakeCoinForGasDenom(1)
|
||||
invalidCoin := sdk.Coin{Denom: "Invalid Denom", Amount: sdkmath.NewInt(-1)}
|
||||
testCases := []struct {
|
||||
msg string
|
||||
|
@ -61,7 +61,7 @@ func (suite *MsgServerTestSuite) SetupTest() {
|
||||
[]types.Proposal{},
|
||||
[]types.Vote{},
|
||||
)
|
||||
suite.communityPoolAmt = sdk.NewCoins(chaincfg.MakeCoinForBaseDenom(1000000000000000))
|
||||
suite.communityPoolAmt = sdk.NewCoins(chaincfg.MakeCoinForEvmDenom(1000000000000000))
|
||||
suite.app.InitializeFromGenesisStates(
|
||||
app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(testGenesis)},
|
||||
// TODO: not used?
|
||||
|
@ -171,7 +171,7 @@ func NewVoteCmd() *cobra.Command {
|
||||
tokens = val.GetTokens()
|
||||
}
|
||||
}
|
||||
// the denom of token is base denom, need to convert to A0GI
|
||||
// the denom of token is evm denom, need to convert to A0GI
|
||||
a0giTokenCnt := tokens.Quo(sdk.NewInt(1_000_000_000_000_000_000))
|
||||
// 1_000 0AGI token / vote
|
||||
numBallots := a0giTokenCnt.Quo(sdk.NewInt(1_000)).Uint64()
|
||||
|
@ -13,53 +13,53 @@ import (
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
// ConversionMultiplier is the conversion multiplier between base denom and auxiliary denom
|
||||
var ConversionMultiplier = sdkmath.NewInt(chaincfg.AuxiliaryDenomConversionMultiplier)
|
||||
// ConversionMultiplier is the conversion multiplier between evm denom and gas denom
|
||||
var ConversionMultiplier = sdkmath.NewInt(chaincfg.GasDenomConversionMultiplier)
|
||||
|
||||
var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
||||
|
||||
// EvmBankKeeper is a BankKeeper wrapper for the x/evm module to allow the use
|
||||
// of the 18 decimal base denom coin on the evm.
|
||||
// x/evm consumes gas and send coins by minting and burning base denom coins in its module
|
||||
// of the 18 decimal evm denom coin on the evm.
|
||||
// x/evm consumes gas and send coins by minting and burning evm denom coins in its module
|
||||
// account and then sending the funds to the target account.
|
||||
// This keeper uses both the auxiliary denom coin and a separate base denom balance to manage the
|
||||
// This keeper uses both the gas denom coin and a separate evm denom balance to manage the
|
||||
// extra percision needed by the evm.
|
||||
type EvmBankKeeper struct {
|
||||
baseDenomKeeper Keeper
|
||||
evmDenomKeeper Keeper
|
||||
bk types.BankKeeper
|
||||
ak types.AccountKeeper
|
||||
}
|
||||
|
||||
func NewEvmBankKeeper(baseKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
||||
return EvmBankKeeper{
|
||||
baseDenomKeeper: baseKeeper,
|
||||
evmDenomKeeper: baseKeeper,
|
||||
bk: bk,
|
||||
ak: ak,
|
||||
}
|
||||
}
|
||||
|
||||
// GetBalance returns the total **spendable** balance of base denom for a given account by address.
|
||||
// GetBalance returns the total **spendable** balance of evm denom for a given account by address.
|
||||
func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
||||
if denom != chaincfg.BaseDenom {
|
||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.BaseDenom))
|
||||
if denom != chaincfg.EvmDenom {
|
||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.EvmDenom))
|
||||
}
|
||||
|
||||
spendableCoins := k.bk.SpendableCoins(ctx, addr)
|
||||
auxiliaryDenomFromBank := spendableCoins.AmountOf(chaincfg.AuxiliaryDenom)
|
||||
baseDenomFromBank := spendableCoins.AmountOf(chaincfg.BaseDenom)
|
||||
baseDenomFromEvmBank := k.baseDenomKeeper.GetBalance(ctx, addr)
|
||||
gasDenomFromBank := spendableCoins.AmountOf(chaincfg.GasDenom)
|
||||
evmDenomFromBank := spendableCoins.AmountOf(chaincfg.EvmDenom)
|
||||
evmDenomFromEvmBank := k.evmDenomKeeper.GetBalance(ctx, addr)
|
||||
|
||||
var total sdkmath.Int
|
||||
|
||||
if auxiliaryDenomFromBank.IsPositive() {
|
||||
total = auxiliaryDenomFromBank.Mul(ConversionMultiplier).Add(baseDenomFromBank).Add(baseDenomFromEvmBank)
|
||||
if gasDenomFromBank.IsPositive() {
|
||||
total = gasDenomFromBank.Mul(ConversionMultiplier).Add(evmDenomFromBank).Add(evmDenomFromEvmBank)
|
||||
} else {
|
||||
total = baseDenomFromBank.Add(baseDenomFromEvmBank)
|
||||
total = evmDenomFromBank.Add(evmDenomFromEvmBank)
|
||||
}
|
||||
return sdk.NewCoin(chaincfg.BaseDenom, total)
|
||||
return sdk.NewCoin(chaincfg.EvmDenom, total)
|
||||
}
|
||||
|
||||
// SendCoins transfers base denom coins from a AccAddress to an AccAddress.
|
||||
// SendCoins transfers evm denom coins from a AccAddress to an AccAddress.
|
||||
func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
||||
// SendCoins method is not used by the evm module, but is required by the
|
||||
// evmtypes.BankKeeper interface. This must be updated if the evm module
|
||||
@ -67,148 +67,148 @@ func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, rec
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// SendCoinsFromModuleToAccount transfers base denom coins from a ModuleAccount to an AccAddress.
|
||||
// SendCoinsFromModuleToAccount transfers evm denom coins from a ModuleAccount to an AccAddress.
|
||||
// It will panic if the module account does not exist. An error is returned if the recipient
|
||||
// address is black-listed or if sending the tokens fails.
|
||||
func (k EvmBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
||||
auxiliaryDenomCoin, baseDemonCnt, err := SplitBaseDenomCoins(amt)
|
||||
gasDenomCoin, baseDemonCnt, err := SplitEvmDenomCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if auxiliaryDenomCoin.Amount.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(auxiliaryDenomCoin)); err != nil {
|
||||
if gasDenomCoin.Amount.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(gasDenomCoin)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
senderAddr := k.GetModuleAddress(senderModule)
|
||||
if err := k.ConvertOneAuxiliaryDenomToBaseDenomIfNeeded(ctx, senderAddr, baseDemonCnt); err != nil {
|
||||
if err := k.ConvertOneGasDenomToEvmDenomIfNeeded(ctx, senderAddr, baseDemonCnt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := k.baseDenomKeeper.SendBalance(ctx, senderAddr, recipientAddr, baseDemonCnt); err != nil {
|
||||
if err := k.evmDenomKeeper.SendBalance(ctx, senderAddr, recipientAddr, baseDemonCnt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertBaseDenomToAuxiliaryDenom(ctx, recipientAddr)
|
||||
return k.ConvertEvmDenomToGasDenom(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// SendCoinsFromAccountToModule transfers base denom coins from an AccAddress to a ModuleAccount.
|
||||
// SendCoinsFromAccountToModule transfers evm denom coins from an AccAddress to a ModuleAccount.
|
||||
// It will panic if the module account does not exist.
|
||||
func (k EvmBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error {
|
||||
auxiliaryDenomCoin, baseDenomCnt, err := SplitBaseDenomCoins(amt)
|
||||
gasDenomCoin, evmDenomCnt, err := SplitEvmDenomCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if auxiliaryDenomCoin.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(auxiliaryDenomCoin)); err != nil {
|
||||
if gasDenomCoin.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(gasDenomCoin)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := k.ConvertOneAuxiliaryDenomToBaseDenomIfNeeded(ctx, senderAddr, baseDenomCnt); err != nil {
|
||||
if err := k.ConvertOneGasDenomToEvmDenomIfNeeded(ctx, senderAddr, evmDenomCnt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
recipientAddr := k.GetModuleAddress(recipientModule)
|
||||
if err := k.baseDenomKeeper.SendBalance(ctx, senderAddr, recipientAddr, baseDenomCnt); err != nil {
|
||||
if err := k.evmDenomKeeper.SendBalance(ctx, senderAddr, recipientAddr, evmDenomCnt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertBaseDenomToAuxiliaryDenom(ctx, recipientAddr)
|
||||
return k.ConvertEvmDenomToGasDenom(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// MintCoins mints base denom coins by minting the equivalent auxiliary denom coins and any remaining base denom coins.
|
||||
// MintCoins mints evm denom coins by minting the equivalent gas denom coins and any remaining evm denom coins.
|
||||
// It will panic if the module account does not exist or is unauthorized.
|
||||
func (k EvmBankKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
||||
auxiliaryDenomCoin, baseDemonCnt, err := SplitBaseDenomCoins(amt)
|
||||
gasDenomCoin, baseDemonCnt, err := SplitEvmDenomCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if auxiliaryDenomCoin.IsPositive() {
|
||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(auxiliaryDenomCoin)); err != nil {
|
||||
if gasDenomCoin.IsPositive() {
|
||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(gasDenomCoin)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
recipientAddr := k.GetModuleAddress(moduleName)
|
||||
if err := k.baseDenomKeeper.AddBalance(ctx, recipientAddr, baseDemonCnt); err != nil {
|
||||
if err := k.evmDenomKeeper.AddBalance(ctx, recipientAddr, baseDemonCnt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertBaseDenomToAuxiliaryDenom(ctx, recipientAddr)
|
||||
return k.ConvertEvmDenomToGasDenom(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// BurnCoins burns base denom coins by burning the equivalent auxiliary denom coins and any remaining base denom coins.
|
||||
// BurnCoins burns evm denom coins by burning the equivalent gas denom coins and any remaining evm denom coins.
|
||||
// It will panic if the module account does not exist or is unauthorized.
|
||||
func (k EvmBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
||||
auxiliaryDenomCoin, baseDemonCnt, err := SplitBaseDenomCoins(amt)
|
||||
gasDenomCoin, baseDemonCnt, err := SplitEvmDenomCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if auxiliaryDenomCoin.IsPositive() {
|
||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(auxiliaryDenomCoin)); err != nil {
|
||||
if gasDenomCoin.IsPositive() {
|
||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(gasDenomCoin)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
moduleAddr := k.GetModuleAddress(moduleName)
|
||||
if err := k.ConvertOneAuxiliaryDenomToBaseDenomIfNeeded(ctx, moduleAddr, baseDemonCnt); err != nil {
|
||||
if err := k.ConvertOneGasDenomToEvmDenomIfNeeded(ctx, moduleAddr, baseDemonCnt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.baseDenomKeeper.RemoveBalance(ctx, moduleAddr, baseDemonCnt)
|
||||
return k.evmDenomKeeper.RemoveBalance(ctx, moduleAddr, baseDemonCnt)
|
||||
}
|
||||
|
||||
// ConvertOneauxiliaryDenomToBaseDenomIfNeeded converts 1 auxiliary denom to base denom for an address if
|
||||
// its base denom balance is smaller than the baseDenomCnt amount.
|
||||
func (k EvmBankKeeper) ConvertOneAuxiliaryDenomToBaseDenomIfNeeded(ctx sdk.Context, addr sdk.AccAddress, baseDenomCnt sdkmath.Int) error {
|
||||
baseDenomBal := k.baseDenomKeeper.GetBalance(ctx, addr)
|
||||
if baseDenomBal.GTE(baseDenomCnt) {
|
||||
// ConvertOnegasDenomToEvmDenomIfNeeded converts 1 gas denom to evm denom for an address if
|
||||
// its evm denom balance is smaller than the evmDenomCnt amount.
|
||||
func (k EvmBankKeeper) ConvertOneGasDenomToEvmDenomIfNeeded(ctx sdk.Context, addr sdk.AccAddress, evmDenomCnt sdkmath.Int) error {
|
||||
evmDenomBal := k.evmDenomKeeper.GetBalance(ctx, addr)
|
||||
if evmDenomBal.GTE(evmDenomCnt) {
|
||||
return nil
|
||||
}
|
||||
|
||||
auxiliaryDenomToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdk.OneInt()))
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, auxiliaryDenomToStore); err != nil {
|
||||
gasDenomToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdk.OneInt()))
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, gasDenomToStore); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add 1 auxiliary denom equivalent of base denom to addr
|
||||
baseDenomToReceive := ConversionMultiplier
|
||||
if err := k.baseDenomKeeper.AddBalance(ctx, addr, baseDenomToReceive); err != nil {
|
||||
// add 1 gas denom equivalent of evm denom to addr
|
||||
evmDenomToReceive := ConversionMultiplier
|
||||
if err := k.evmDenomKeeper.AddBalance(ctx, addr, evmDenomToReceive); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConvertBaseDenomToauxiliaryDenom converts all available base denom to auxiliary denom for a given AccAddress.
|
||||
func (k EvmBankKeeper) ConvertBaseDenomToAuxiliaryDenom(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||
totalBaseDenom := k.baseDenomKeeper.GetBalance(ctx, addr)
|
||||
auxiliaryDenomCoin, _, err := SplitBaseDenomCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, totalBaseDenom)))
|
||||
// ConvertEvmDenomTogasDenom converts all available evm denom to gas denom for a given AccAddress.
|
||||
func (k EvmBankKeeper) ConvertEvmDenomToGasDenom(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||
totalEvmDenom := k.evmDenomKeeper.GetBalance(ctx, addr)
|
||||
gasDenomCoin, _, err := SplitEvmDenomCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.EvmDenom, totalEvmDenom)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// do nothing if account does not have enough base denom for a single auxiliary denom
|
||||
auxiliaryDenomToReceive := auxiliaryDenomCoin.Amount
|
||||
if !auxiliaryDenomToReceive.IsPositive() {
|
||||
// do nothing if account does not have enough evm denom for a single gas denom
|
||||
gasDenomToReceive := gasDenomCoin.Amount
|
||||
if !gasDenomToReceive.IsPositive() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// remove base denom used for converting to auxiliary denom
|
||||
baseDenomToBurn := auxiliaryDenomToReceive.Mul(ConversionMultiplier)
|
||||
finalBal := totalBaseDenom.Sub(baseDenomToBurn)
|
||||
if err := k.baseDenomKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||
// remove evm denom used for converting to gas denom
|
||||
evmDenomToBurn := gasDenomToReceive.Mul(ConversionMultiplier)
|
||||
finalBal := totalEvmDenom.Sub(evmDenomToBurn)
|
||||
if err := k.evmDenomKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fromAddr := k.GetModuleAddress(types.ModuleName)
|
||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(auxiliaryDenomCoin)); err != nil {
|
||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(gasDenomCoin)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -223,18 +223,18 @@ func (k EvmBankKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
|
||||
return addr
|
||||
}
|
||||
|
||||
// SplitBaseDenomCoins splits base denom coins to the equivalent auxiliary denom coins and any remaining base denom balance.
|
||||
// An error will be returned if the coins are not valid or if the coins are not the base denom.
|
||||
func SplitBaseDenomCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
// SplitEvmDenomCoins splits evm denom coins to the equivalent gas denom coins and any remaining evm denom balance.
|
||||
// An error will be returned if the coins are not valid or if the coins are not the evm denom.
|
||||
func SplitEvmDenomCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
baseDemonCnt := sdk.ZeroInt()
|
||||
auxiliaryDenomAmt := sdk.NewCoin(chaincfg.AuxiliaryDenom, sdk.ZeroInt())
|
||||
gasDenomAmt := sdk.NewCoin(chaincfg.GasDenom, sdk.ZeroInt())
|
||||
|
||||
if len(coins) == 0 {
|
||||
return auxiliaryDenomAmt, baseDemonCnt, nil
|
||||
return gasDenomAmt, baseDemonCnt, nil
|
||||
}
|
||||
|
||||
if err := ValidateEvmCoins(coins); err != nil {
|
||||
return auxiliaryDenomAmt, baseDemonCnt, err
|
||||
return gasDenomAmt, baseDemonCnt, err
|
||||
}
|
||||
|
||||
// note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate.
|
||||
@ -243,15 +243,15 @@ func SplitBaseDenomCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
if remainingBalance.IsPositive() {
|
||||
baseDemonCnt = remainingBalance
|
||||
}
|
||||
auxiliaryDenomAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||
if auxiliaryDenomAmount.IsPositive() {
|
||||
auxiliaryDenomAmt = sdk.NewCoin(chaincfg.AuxiliaryDenom, auxiliaryDenomAmount)
|
||||
gasDenomAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||
if gasDenomAmount.IsPositive() {
|
||||
gasDenomAmt = sdk.NewCoin(chaincfg.GasDenom, gasDenomAmount)
|
||||
}
|
||||
|
||||
return auxiliaryDenomAmt, baseDemonCnt, nil
|
||||
return gasDenomAmt, baseDemonCnt, nil
|
||||
}
|
||||
|
||||
// ValidateEvmCoins validates the coins from evm is valid and is the base denom.
|
||||
// ValidateEvmCoins validates the coins from evm is valid and is the evm denom.
|
||||
func ValidateEvmCoins(coins sdk.Coins) error {
|
||||
if len(coins) == 0 {
|
||||
return nil
|
||||
@ -262,9 +262,9 @@ func ValidateEvmCoins(coins sdk.Coins) error {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
|
||||
}
|
||||
|
||||
// validate that coin denom is base denom
|
||||
if len(coins) != 1 || coins[0].Denom != chaincfg.BaseDenom {
|
||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.BaseDenom)
|
||||
// validate that coin denom is evm denom
|
||||
if len(coins) != 1 || coins[0].Denom != chaincfg.EvmDenom {
|
||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.EvmDenom)
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
|
||||
}
|
||||
|
||||
|
@ -35,8 +35,8 @@ func (suite *evmBankKeeperTestSuite) SetupTest() {
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
||||
startingCoins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10))
|
||||
startingBaseDenom := sdkmath.NewInt(100)
|
||||
startingCoins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10))
|
||||
startingEvmDenom := sdkmath.NewInt(100)
|
||||
|
||||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
@ -46,20 +46,20 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
||||
|
||||
err := suite.App.FundAccount(suite.Ctx, suite.Addrs[0], startingCoins)
|
||||
suite.Require().NoError(err)
|
||||
err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingBaseDenom)
|
||||
err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingEvmDenom)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
suite.Require().Equal(startingBaseDenom, coin.Amount)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.EvmDenom)
|
||||
suite.Require().Equal(startingEvmDenom, coin.Amount)
|
||||
|
||||
ctx := suite.Ctx.WithBlockTime(now.Add(12 * time.Hour))
|
||||
coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], chaincfg.EvmDenom)
|
||||
suite.Require().Equal(sdkmath.NewIntFromUint64(5_000_000_000_100), coin.Amount)
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_NotEvmDenom() {
|
||||
suite.Require().Panics(func() {
|
||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.AuxiliaryDenom)
|
||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom)
|
||||
})
|
||||
suite.Require().Panics(func() {
|
||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "busd")
|
||||
@ -73,39 +73,39 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
expAmount sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"auxiliary denom with base denom",
|
||||
"gas denom with evm denom",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 10),
|
||||
),
|
||||
sdkmath.NewInt(10_000_000_000_100),
|
||||
},
|
||||
{
|
||||
"just base denom",
|
||||
"just evm denom",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 100),
|
||||
sdk.NewInt64Coin("busd", 100),
|
||||
),
|
||||
sdkmath.NewInt(100),
|
||||
},
|
||||
{
|
||||
"just auxiliary denom",
|
||||
"just gas denom",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 10),
|
||||
sdk.NewInt64Coin("busd", 100),
|
||||
),
|
||||
sdkmath.NewInt(10_000_000_000_000),
|
||||
},
|
||||
{
|
||||
"no auxiliary denom or base denom",
|
||||
"no gas denom or evm denom",
|
||||
sdk.NewCoins(),
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"with avaka that is more than 1 auxiliary denom",
|
||||
"with avaka that is more than 1 gas denom",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 20_000_000_000_220),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 11),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 20_000_000_000_220),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 11),
|
||||
),
|
||||
sdkmath.NewInt(31_000_000_000_220),
|
||||
},
|
||||
@ -116,7 +116,7 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
suite.SetupTest()
|
||||
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAmount)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.EvmDenom)
|
||||
suite.Require().Equal(tt.expAmount, coin.Amount)
|
||||
})
|
||||
}
|
||||
@ -124,8 +124,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
startingModuleCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 100),
|
||||
)
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -135,102 +135,102 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
hasErr bool
|
||||
}{
|
||||
{
|
||||
"send more than 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||
"send more than 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_010)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 10),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 12),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 10),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 12),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send less than 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
"send less than 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 122)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 122),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 0),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 122),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 0),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send an exact amount of auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
"send an exact amount of gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 98_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 0o0),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 98),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 0o0),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 98),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send no base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
"send no evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 0)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 0),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 0),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 0),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 0),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"errors if sending other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough total base denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||
"errors if not enough total evm denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_001_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough auxiliary denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
"errors if not enough gas denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"converts receiver's base denom to auxiliary denom if there's enough base denom after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_000_200)),
|
||||
"converts receiver's evm denom to gas denom if there's enough evm denom after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 99_000_000_000_200)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 999_999_999_900),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 1),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 999_999_999_900),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 101),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 101),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts all of receiver's base denom to auxiliary denom even if somehow receiver has more than 1 auxiliary denom of base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_100)),
|
||||
"converts all of receiver's evm denom to gas denom even if somehow receiver has more than 1 gas denom of evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_100)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 5_999_999_999_990),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 1),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 5_999_999_999_990),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 90),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 19),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 90),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 19),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"swap 1 auxiliary denom for base denom if module account doesn't have enough base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_001_000)),
|
||||
"swap 1 gas denom for evm denom if module account doesn't have enough evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 99_000_000_001_000)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 1),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 1200),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 1200),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 100),
|
||||
),
|
||||
false,
|
||||
},
|
||||
@ -243,8 +243,8 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAccBal)
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||
|
||||
// fund our module with some auxiliary denom to account for converting extra base denom back to auxiliary denom
|
||||
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10)))
|
||||
// fund our module with some gas denom to account for converting extra evm denom back to gas denom
|
||||
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10)))
|
||||
|
||||
err := suite.EvmBankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, evmtypes.ModuleName, suite.Addrs[0], tt.sendCoins)
|
||||
if tt.hasErr {
|
||||
@ -254,24 +254,24 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check auxiliary denom
|
||||
AuxiliaryDenomSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.AuxiliaryDenom)
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.AuxiliaryDenom).Int64(), AuxiliaryDenomSender.Amount.Int64())
|
||||
// check gas denom
|
||||
GasDenomSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom)
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.GasDenom).Int64(), GasDenomSender.Amount.Int64())
|
||||
|
||||
// check base denom
|
||||
actualBaseDenom := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.BaseDenom).Int64(), actualBaseDenom.Int64())
|
||||
// check evm denom
|
||||
actualEvmDenom := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.EvmDenom).Int64(), actualEvmDenom.Int64())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
startingAccCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.GasDenom, 100),
|
||||
)
|
||||
startingModuleCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_000),
|
||||
)
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -281,36 +281,36 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
hasErr bool
|
||||
}{
|
||||
{
|
||||
"send more than 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 190), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 88)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_010), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 12)),
|
||||
"send more than 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_010)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 190), sdk.NewInt64Coin(chaincfg.GasDenom, 88)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_010), sdk.NewInt64Coin(chaincfg.GasDenom, 12)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send less than 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 78), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_122), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 0)),
|
||||
"send less than 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 122)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 78), sdk.NewInt64Coin(chaincfg.GasDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_122), sdk.NewInt64Coin(chaincfg.GasDenom, 0)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send an exact amount of auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 2)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 98)),
|
||||
"send an exact amount of gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 98_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200), sdk.NewInt64Coin(chaincfg.GasDenom, 2)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.GasDenom, 98)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send no base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 0)),
|
||||
"send no evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200), sdk.NewInt64Coin(chaincfg.GasDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.GasDenom, 0)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"errors if sending other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
@ -318,39 +318,39 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 2_000_000_000_000),
|
||||
},
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough total base denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||
"errors if not enough total evm denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_001_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough auxiliary denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
"errors if not enough gas denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"converts 1 auxiliary denom to base denom if not enough base denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_001_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 999_000_000_200), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 101_000_000_000), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 99)),
|
||||
"converts 1 gas denom to evm denom if not enough evm denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 99_001_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 999_000_000_200), sdk.NewInt64Coin(chaincfg.GasDenom, 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 101_000_000_000), sdk.NewInt64Coin(chaincfg.GasDenom, 99)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts receiver's base denom to auxiliary denom if there's enough base denom after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_900_000_000_200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 94)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 6)),
|
||||
"converts receiver's evm denom to gas denom if there's enough evm denom after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 5_900_000_000_200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.GasDenom, 94)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200), sdk.NewInt64Coin(chaincfg.GasDenom, 6)),
|
||||
false,
|
||||
},
|
||||
}
|
||||
@ -370,67 +370,67 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
}
|
||||
|
||||
// check sender balance
|
||||
AuxiliaryDenomSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.AuxiliaryDenom)
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.AuxiliaryDenom).Int64(), AuxiliaryDenomSender.Amount.Int64())
|
||||
actualBaseDenom := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualBaseDenom.Int64())
|
||||
GasDenomSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom)
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.GasDenom).Int64(), GasDenomSender.Amount.Int64())
|
||||
actualEvmDenom := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.EvmDenom).Int64(), actualEvmDenom.Int64())
|
||||
|
||||
// check module balance
|
||||
moduleAddr := suite.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
|
||||
AuxiliaryDenomSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, chaincfg.AuxiliaryDenom)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.AuxiliaryDenom).Int64(), AuxiliaryDenomSender.Amount.Int64())
|
||||
actualBaseDenom = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualBaseDenom.Int64())
|
||||
GasDenomSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, chaincfg.GasDenom)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.GasDenom).Int64(), GasDenomSender.Amount.Int64())
|
||||
actualEvmDenom = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.EvmDenom).Int64(), actualEvmDenom.Int64())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
startingAuxiliaryDenom := sdkmath.NewInt(100)
|
||||
startingGasDenom := sdkmath.NewInt(100)
|
||||
tests := []struct {
|
||||
name string
|
||||
burnCoins sdk.Coins
|
||||
expAuxiliaryDenom sdkmath.Int
|
||||
expBaseDenom sdkmath.Int
|
||||
expGasDenom sdkmath.Int
|
||||
expEvmDenom sdkmath.Int
|
||||
hasErr bool
|
||||
baseDenomStart sdkmath.Int
|
||||
evmDenomStart sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"burn more than 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
"burn more than 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(88),
|
||||
sdkmath.NewInt(100_000_000_000),
|
||||
false,
|
||||
sdkmath.NewInt(121_000_000_002),
|
||||
},
|
||||
{
|
||||
"burn less than 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
"burn less than 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 122)),
|
||||
sdkmath.NewInt(100),
|
||||
sdkmath.NewInt(878),
|
||||
false,
|
||||
sdkmath.NewInt(1000),
|
||||
},
|
||||
{
|
||||
"burn an exact amount of auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
"burn an exact amount of gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 98_000_000_000_000)),
|
||||
sdkmath.NewInt(2),
|
||||
sdkmath.NewInt(10),
|
||||
false,
|
||||
sdkmath.NewInt(10),
|
||||
},
|
||||
{
|
||||
"burn no base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
startingAuxiliaryDenom,
|
||||
"burn no evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 0)),
|
||||
startingGasDenom,
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"errors if burning other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
startingAuxiliaryDenom,
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
startingGasDenom,
|
||||
sdkmath.NewInt(100),
|
||||
true,
|
||||
sdkmath.NewInt(100),
|
||||
@ -438,41 +438,41 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 2_000_000_000_000),
|
||||
},
|
||||
startingAuxiliaryDenom,
|
||||
startingGasDenom,
|
||||
sdk.ZeroInt(),
|
||||
true,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"errors if burn amount is negative",
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||
startingAuxiliaryDenom,
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.EvmDenom, Amount: sdkmath.NewInt(-100)}},
|
||||
startingGasDenom,
|
||||
sdkmath.NewInt(50),
|
||||
true,
|
||||
sdkmath.NewInt(50),
|
||||
},
|
||||
{
|
||||
"errors if not enough base denom to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_999_000_000_000)),
|
||||
"errors if not enough evm denom to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100_999_000_000_000)),
|
||||
sdkmath.NewInt(0),
|
||||
sdkmath.NewInt(99_000_000_000),
|
||||
true,
|
||||
sdkmath.NewInt(99_000_000_000),
|
||||
},
|
||||
{
|
||||
"errors if not enough auxiliary denom to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
"errors if not enough gas denom to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 200_000_000_000_000)),
|
||||
sdkmath.NewInt(100),
|
||||
sdk.ZeroInt(),
|
||||
true,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"converts 1 auxiliary denom to base denom if not enough base denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
"converts 1 gas denom to evm denom if not enough evm denom to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(87),
|
||||
sdkmath.NewInt(980_000_000_000),
|
||||
false,
|
||||
@ -484,8 +484,8 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
startingCoins := sdk.NewCoins(
|
||||
sdk.NewCoin(chaincfg.AuxiliaryDenom, startingAuxiliaryDenom),
|
||||
sdk.NewCoin(chaincfg.BaseDenom, tt.baseDenomStart),
|
||||
sdk.NewCoin(chaincfg.GasDenom, startingGasDenom),
|
||||
sdk.NewCoin(chaincfg.EvmDenom, tt.evmDenomStart),
|
||||
)
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingCoins)
|
||||
|
||||
@ -497,13 +497,13 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check auxiliary denom
|
||||
AuxiliaryDenomActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.AuxiliaryDenom)
|
||||
suite.Require().Equal(tt.expAuxiliaryDenom, AuxiliaryDenomActual.Amount)
|
||||
// check gas denom
|
||||
GasDenomActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.GasDenom)
|
||||
suite.Require().Equal(tt.expGasDenom, GasDenomActual.Amount)
|
||||
|
||||
// check base denom
|
||||
baseDenomActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.expBaseDenom, baseDenomActual)
|
||||
// check evm denom
|
||||
evmDenomActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.expEvmDenom, evmDenomActual)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -512,38 +512,38 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
tests := []struct {
|
||||
name string
|
||||
mintCoins sdk.Coins
|
||||
AuxiliaryDenomCnt sdkmath.Int
|
||||
baseDenomCnt sdkmath.Int
|
||||
GasDenomCnt sdkmath.Int
|
||||
evmDenomCnt sdkmath.Int
|
||||
hasErr bool
|
||||
baseDenomStart sdkmath.Int
|
||||
evmDenomStart sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"mint more than 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
"mint more than 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(21_000_000_002),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint less than 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 901_000_000_001)),
|
||||
"mint less than 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 901_000_000_001)),
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(901_000_000_001),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint an exact amount of auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 123_000_000_000_000_000)),
|
||||
"mint an exact amount of gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 123_000_000_000_000_000)),
|
||||
sdkmath.NewInt(123_000),
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint no base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
"mint no evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 0)),
|
||||
sdk.ZeroInt(),
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
@ -551,7 +551,7 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
},
|
||||
{
|
||||
"errors if minting other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(100),
|
||||
true,
|
||||
@ -560,8 +560,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.EvmDenom, 2_000_000_000_000),
|
||||
},
|
||||
sdk.ZeroInt(),
|
||||
sdk.ZeroInt(),
|
||||
@ -570,23 +570,23 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
},
|
||||
{
|
||||
"errors if mint amount is negative",
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.EvmDenom, Amount: sdkmath.NewInt(-100)}},
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(50),
|
||||
true,
|
||||
sdkmath.NewInt(50),
|
||||
},
|
||||
{
|
||||
"adds to existing base denom balance",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
"adds to existing evm denom balance",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(21_000_000_102),
|
||||
false,
|
||||
sdkmath.NewInt(100),
|
||||
},
|
||||
{
|
||||
"convert base denom balance to auxiliary denom if it exceeds 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_999_000_000_000)),
|
||||
"convert evm denom balance to gas denom if it exceeds 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 10_999_000_000_000)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(1_200_000_001),
|
||||
false,
|
||||
@ -597,8 +597,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10)))
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, tt.baseDenomStart)))
|
||||
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10)))
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(chaincfg.EvmDenom, tt.evmDenomStart)))
|
||||
|
||||
err := suite.EvmBankKeeper.MintCoins(suite.Ctx, evmtypes.ModuleName, tt.mintCoins)
|
||||
if tt.hasErr {
|
||||
@ -608,13 +608,13 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check auxiliary denom
|
||||
AuxiliaryDenomActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.AuxiliaryDenom)
|
||||
suite.Require().Equal(tt.AuxiliaryDenomCnt, AuxiliaryDenomActual.Amount)
|
||||
// check gas denom
|
||||
GasDenomActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.GasDenom)
|
||||
suite.Require().Equal(tt.GasDenomCnt, GasDenomActual.Amount)
|
||||
|
||||
// check base denom
|
||||
baseDenomActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.baseDenomCnt, baseDenomActual)
|
||||
// check evm denom
|
||||
evmDenomActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.evmDenomCnt, evmDenomActual)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -627,22 +627,22 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
||||
}{
|
||||
{
|
||||
"valid coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 500)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"dup coins",
|
||||
sdk.Coins{sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin(chaincfg.BaseDenom, 500)},
|
||||
sdk.Coins{sdk.NewInt64Coin(chaincfg.EvmDenom, 500), sdk.NewInt64Coin(chaincfg.EvmDenom, 500)},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"not evm coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 500)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"negative coins",
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-500)}},
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.EvmDenom, Amount: sdkmath.NewInt(-500)}},
|
||||
true,
|
||||
},
|
||||
}
|
||||
@ -658,8 +658,8 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertOneAuxiliaryDenomToBaseDenomIfNeeded() {
|
||||
baseDenomNeeded := sdkmath.NewInt(200)
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertOneGasDenomToEvmDenomIfNeeded() {
|
||||
evmDenomNeeded := sdkmath.NewInt(200)
|
||||
tests := []struct {
|
||||
name string
|
||||
startingCoins sdk.Coins
|
||||
@ -667,21 +667,21 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneAuxiliaryDenomToBaseDenomIfNe
|
||||
success bool
|
||||
}{
|
||||
{
|
||||
"not enough auxiliary denom for conversion",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
"not enough gas denom for conversion",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts 1 auxiliary denom to base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 9), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_100)),
|
||||
"converts 1 gas denom to evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 9), sdk.NewInt64Coin(chaincfg.EvmDenom, 1_000_000_000_100)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"conversion not needed",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 200)),
|
||||
true,
|
||||
},
|
||||
}
|
||||
@ -690,11 +690,11 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneAuxiliaryDenomToBaseDenomIfNe
|
||||
suite.SetupTest()
|
||||
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||
err := suite.EvmBankKeeper.ConvertOneAuxiliaryDenomToBaseDenomIfNeeded(suite.Ctx, suite.Addrs[0], baseDenomNeeded)
|
||||
moduleZgChain := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), chaincfg.AuxiliaryDenom)
|
||||
err := suite.EvmBankKeeper.ConvertOneGasDenomToEvmDenomIfNeeded(suite.Ctx, suite.Addrs[0], evmDenomNeeded)
|
||||
moduleZgChain := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), chaincfg.GasDenom)
|
||||
if tt.success {
|
||||
suite.Require().NoError(err)
|
||||
if tt.startingCoins.AmountOf(chaincfg.BaseDenom).LT(baseDenomNeeded) {
|
||||
if tt.startingCoins.AmountOf(chaincfg.EvmDenom).LT(evmDenomNeeded) {
|
||||
suite.Require().Equal(sdk.OneInt(), moduleZgChain.Amount)
|
||||
}
|
||||
} else {
|
||||
@ -702,54 +702,54 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneAuxiliaryDenomToBaseDenomIfNe
|
||||
suite.Require().Equal(sdk.ZeroInt(), moduleZgChain.Amount)
|
||||
}
|
||||
|
||||
baseDenomCnt := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), baseDenomCnt)
|
||||
AuxiliaryDenomCoin := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.AuxiliaryDenom)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.AuxiliaryDenom), AuxiliaryDenomCoin.Amount)
|
||||
evmDenomCnt := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.EvmDenom), evmDenomCnt)
|
||||
GasDenomCoin := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.GasDenom), GasDenomCoin.Amount)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertBaseDenomToAuxiliaryDenom() {
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertEvmDenomToGasDenom() {
|
||||
tests := []struct {
|
||||
name string
|
||||
startingCoins sdk.Coins
|
||||
expectedCoins sdk.Coins
|
||||
}{
|
||||
{
|
||||
"not enough auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100), sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 0)),
|
||||
"not enough gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 100), sdk.NewInt64Coin(chaincfg.GasDenom, 0)),
|
||||
},
|
||||
{
|
||||
"converts base denom for 1 auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_003)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 11), sdk.NewInt64Coin(chaincfg.BaseDenom, 3)),
|
||||
"converts evm denom for 1 gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 1_000_000_000_003)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 11), sdk.NewInt64Coin(chaincfg.EvmDenom, 3)),
|
||||
},
|
||||
{
|
||||
"converts more than 1 auxiliary denom of base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 18), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||
"converts more than 1 gas denom of evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10), sdk.NewInt64Coin(chaincfg.EvmDenom, 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 18), sdk.NewInt64Coin(chaincfg.EvmDenom, 123)),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 10)))
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 10)))
|
||||
suite.Require().NoError(err)
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||
err = suite.EvmBankKeeper.ConvertBaseDenomToAuxiliaryDenom(suite.Ctx, suite.Addrs[0])
|
||||
err = suite.EvmBankKeeper.ConvertEvmDenomToGasDenom(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().NoError(err)
|
||||
baseDenomCnt := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), baseDenomCnt)
|
||||
AuxiliaryDenomCoin := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.AuxiliaryDenom)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.AuxiliaryDenom), AuxiliaryDenomCoin.Amount)
|
||||
evmDenomCnt := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.EvmDenom), evmDenomCnt)
|
||||
GasDenomCoin := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.GasDenom)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.GasDenom), GasDenomCoin.Amount)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSplitBaseDenomCoins() {
|
||||
func (suite *evmBankKeeperTestSuite) TestSplitEvmDenomCoins() {
|
||||
tests := []struct {
|
||||
name string
|
||||
coins sdk.Coins
|
||||
@ -758,7 +758,7 @@ func (suite *evmBankKeeperTestSuite) TestSplitBaseDenomCoins() {
|
||||
}{
|
||||
{
|
||||
"invalid coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 500)),
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
@ -769,33 +769,33 @@ func (suite *evmBankKeeperTestSuite) TestSplitBaseDenomCoins() {
|
||||
false,
|
||||
},
|
||||
{
|
||||
"auxiliary denom & base denom coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 8), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||
"gas denom & evm denom coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 8), sdk.NewInt64Coin(chaincfg.EvmDenom, 123)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"only base denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||
"only evm denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 10_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 10_123)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"only auxiliary denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 5)),
|
||||
"only gas denom",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.EvmDenom, 5_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 5)),
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
AuxiliaryDenomCoin, baseDenomCnt, err := keeper.SplitBaseDenomCoins(tt.coins)
|
||||
GasDenomCoin, evmDenomCnt, err := keeper.SplitEvmDenomCoins(tt.coins)
|
||||
if tt.shouldErr {
|
||||
suite.Require().Error(err)
|
||||
} else {
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.AuxiliaryDenom), AuxiliaryDenomCoin.Amount)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), baseDenomCnt)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.GasDenom), GasDenomCoin.Amount)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.EvmDenom), evmDenomCnt)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant {
|
||||
})
|
||||
|
||||
bankAddr := authtypes.NewModuleAddress(types.ModuleName)
|
||||
bankBalance := bankK.GetBalance(ctx, bankAddr, chaincfg.AuxiliaryDenom).Amount.Mul(ConversionMultiplier)
|
||||
bankBalance := bankK.GetBalance(ctx, bankAddr, chaincfg.GasDenom).Amount.Mul(ConversionMultiplier)
|
||||
|
||||
broken = totalMinorBalances.GT(bankBalance)
|
||||
|
||||
|
@ -50,7 +50,7 @@ func (suite *invariantTestSuite) SetupValidState() {
|
||||
suite.FundModuleAccountWithZgChain(
|
||||
types.ModuleName,
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||
sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||
),
|
||||
)
|
||||
|
||||
@ -160,8 +160,8 @@ func (suite *invariantTestSuite) TestSmallBalances() {
|
||||
|
||||
// increase minor balance at least above conversion multiplier
|
||||
suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], keeper.ConversionMultiplier)
|
||||
// add same number of auxiliary denom to avoid breaking other invariants
|
||||
amt := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 1))
|
||||
// add same number of gas denom to avoid breaking other invariants
|
||||
amt := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 1))
|
||||
suite.Require().NoError(
|
||||
suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, amt),
|
||||
)
|
||||
|
@ -115,7 +115,7 @@ func (k Keeper) SetAccount(ctx sdk.Context, account types.Account) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBalance returns the total balance of base denom for a given account by address.
|
||||
// GetBalance returns the total balance of evm denom for a given account by address.
|
||||
func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
||||
account := k.GetAccount(ctx, addr)
|
||||
if account == nil {
|
||||
@ -124,7 +124,7 @@ func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
||||
return account.Balance
|
||||
}
|
||||
|
||||
// SetBalance sets the total balance of base denom for a given account by address.
|
||||
// SetBalance sets the total balance of evm denom for a given account by address.
|
||||
func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int) error {
|
||||
account := k.GetAccount(ctx, addr)
|
||||
if account == nil {
|
||||
@ -140,10 +140,10 @@ func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int
|
||||
return k.SetAccount(ctx, *account)
|
||||
}
|
||||
|
||||
// SendBalance transfers the base denom balance from sender addr to recipient addr.
|
||||
// SendBalance transfers the evm denom balance from sender addr to recipient addr.
|
||||
func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdkmath.Int) error {
|
||||
if amt.IsNegative() {
|
||||
return fmt.Errorf("cannot send a negative amount of base denom: %d", amt)
|
||||
return fmt.Errorf("cannot send a negative amount of evm denom: %d", amt)
|
||||
}
|
||||
|
||||
if amt.IsZero() {
|
||||
@ -162,13 +162,13 @@ func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipien
|
||||
return k.SetBalance(ctx, recipientAddr, receiverBal)
|
||||
}
|
||||
|
||||
// AddBalance increments the base denom balance of an address.
|
||||
// AddBalance increments the evm denom balance of an address.
|
||||
func (k Keeper) AddBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
||||
bal := k.GetBalance(ctx, addr)
|
||||
return k.SetBalance(ctx, addr, amt.Add(bal))
|
||||
}
|
||||
|
||||
// RemoveBalance decrements the base denom balance of an address.
|
||||
// RemoveBalance decrements the evm denom balance of an address.
|
||||
func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
||||
if amt.IsNegative() {
|
||||
return fmt.Errorf("cannot remove a negative amount from balance: %d", amt)
|
||||
|
@ -82,14 +82,14 @@ func (suite *Suite) SetupTest() {
|
||||
suite.Addrs = addrs
|
||||
|
||||
evmGenesis := evmtypes.DefaultGenesisState()
|
||||
evmGenesis.Params.EvmDenom = chaincfg.BaseDenom
|
||||
evmGenesis.Params.EvmDenom = chaincfg.EvmDenom
|
||||
|
||||
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
||||
feemarketGenesis.Params.EnableHeight = 1
|
||||
feemarketGenesis.Params.NoBaseFee = false
|
||||
|
||||
cdc := suite.App.AppCodec()
|
||||
coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 1000_000_000_000_000_000))
|
||||
coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.GasDenom, 1000_000_000_000_000_000))
|
||||
authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{
|
||||
sdk.AccAddress(suite.Key1.PubKey().Address()),
|
||||
sdk.AccAddress(suite.Key2.PubKey().Address()),
|
||||
@ -186,28 +186,28 @@ func (suite *Suite) ModuleBalance(denom string) sdk.Int {
|
||||
}
|
||||
|
||||
func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) {
|
||||
AuxiliaryDenomAmt := coins.AmountOf(chaincfg.AuxiliaryDenom)
|
||||
if AuxiliaryDenomAmt.IsPositive() {
|
||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, AuxiliaryDenomAmt)))
|
||||
GasDenomAmt := coins.AmountOf(chaincfg.GasDenom)
|
||||
if GasDenomAmt.IsPositive() {
|
||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, GasDenomAmt)))
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
baseDenomAmt := coins.AmountOf(chaincfg.BaseDenom)
|
||||
if baseDenomAmt.IsPositive() {
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, baseDenomAmt)
|
||||
evmDenomAmt := coins.AmountOf(chaincfg.EvmDenom)
|
||||
if evmDenomAmt.IsPositive() {
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, evmDenomAmt)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) {
|
||||
AuxiliaryDenomAmt := coins.AmountOf(chaincfg.AuxiliaryDenom)
|
||||
if AuxiliaryDenomAmt.IsPositive() {
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, AuxiliaryDenomAmt)))
|
||||
GasDenomAmt := coins.AmountOf(chaincfg.GasDenom)
|
||||
if GasDenomAmt.IsPositive() {
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, GasDenomAmt)))
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
baseDenomAmt := coins.AmountOf(chaincfg.BaseDenom)
|
||||
if baseDenomAmt.IsPositive() {
|
||||
evmDenomAmt := coins.AmountOf(chaincfg.EvmDenom)
|
||||
if evmDenomAmt.IsPositive() {
|
||||
addr := suite.AccountKeeper.GetModuleAddress(moduleName)
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, baseDenomAmt)
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, evmDenomAmt)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
}
|
||||
@ -218,7 +218,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress {
|
||||
suite.App.FundModuleAccount(
|
||||
suite.Ctx,
|
||||
types.ModuleName,
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(0))),
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.GasDenom, sdkmath.NewInt(0))),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18))
|
||||
@ -319,7 +319,7 @@ func (suite *Suite) SendTx(
|
||||
// Mint the max gas to the FeeCollector to ensure balance in case of refund
|
||||
suite.MintFeeCollector(sdk.NewCoins(
|
||||
sdk.NewCoin(
|
||||
chaincfg.AuxiliaryDenom,
|
||||
chaincfg.GasDenom,
|
||||
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
|
||||
)))
|
||||
|
||||
|
@ -143,7 +143,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||
chaincfg.AuxiliaryDenom,
|
||||
chaincfg.GasDenom,
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
@ -163,7 +163,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
||||
chaincfg.AuxiliaryDenom,
|
||||
chaincfg.GasDenom,
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
@ -184,16 +184,16 @@ func TestConversionPairs_Validate(t *testing.T) {
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||
chaincfg.AuxiliaryDenom,
|
||||
chaincfg.GasDenom,
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
chaincfg.AuxiliaryDenom,
|
||||
chaincfg.GasDenom,
|
||||
),
|
||||
),
|
||||
errArgs{
|
||||
expectPass: false,
|
||||
contains: "found duplicate enabled conversion pair denom " + chaincfg.AuxiliaryDenom,
|
||||
contains: "found duplicate enabled conversion pair denom " + chaincfg.GasDenom,
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -209,7 +209,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
chaincfg.AuxiliaryDenom,
|
||||
chaincfg.GasDenom,
|
||||
),
|
||||
),
|
||||
errArgs{
|
||||
|
@ -107,11 +107,11 @@ func (suite *ParamsTestSuite) TestParams_Validate() {
|
||||
invalidConversionPairs := types.NewConversionPairs(
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||
chaincfg.AuxiliaryDenom,
|
||||
chaincfg.GasDenom,
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
chaincfg.AuxiliaryDenom, // duplicate denom!
|
||||
chaincfg.GasDenom, // duplicate denom!
|
||||
),
|
||||
)
|
||||
validAllowedCosmosDenoms := types.NewAllowedCosmosCoinERC20Tokens(
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func TestRawPriceKey_Iteration(t *testing.T) {
|
||||
// An iterator key should only match price keys with the same market
|
||||
iteratorKey := RawPriceIteratorKey(chaincfg.AuxiliaryDenom + ":usd")
|
||||
iteratorKey := RawPriceIteratorKey(chaincfg.GasDenom + ":usd")
|
||||
|
||||
addr := sdk.AccAddress("test addr")
|
||||
|
||||
@ -21,12 +21,12 @@ func TestRawPriceKey_Iteration(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "equal marketID is included in iteration",
|
||||
priceKey: RawPriceKey(chaincfg.AuxiliaryDenom+":usd", addr),
|
||||
priceKey: RawPriceKey(chaincfg.GasDenom+":usd", addr),
|
||||
expectErr: false,
|
||||
},
|
||||
{
|
||||
name: "prefix overlapping marketID excluded from iteration",
|
||||
priceKey: RawPriceKey(chaincfg.AuxiliaryDenom+":usd:30", addr),
|
||||
priceKey: RawPriceKey(chaincfg.GasDenom+":usd:30", addr),
|
||||
expectErr: true,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user