fix unit test

This commit is contained in:
Solovyov1796 2024-05-09 19:35:16 +08:00 committed by 0g-wh
parent 6b4e8415da
commit 85059d734e
39 changed files with 382 additions and 191 deletions

View File

@ -8,8 +8,8 @@ import (
"net/http/httptest"
"testing"
sdkmath "cosmossdk.io/math"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
abci "github.com/cometbft/cometbft/abci/types"
tmbytes "github.com/cometbft/cometbft/libs/bytes"
@ -62,11 +62,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
bank.MsgSend{
FromAddress: fromAddr,
ToAddress: toAddr,
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e6)),
},
},
Fee: auth.StdFee{
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(5e4))),
Amount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(5e4)),
Gas: 1e6,
},
Memo: "test memo",

View File

@ -68,7 +68,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
chainID,
app.NewFundedGenStateWithSameCoins(
tApp.AppCodec(),
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1e9)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e9)),
testAddresses,
),
newBep3GenStateMulti(tApp.AppCodec(), deputy),
@ -116,7 +116,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
banktypes.NewMsgSend(
tc.address,
testAddresses[0],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1_000_000)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1_000_000)),
),
},
sdk.NewCoins(), // no fee

View File

@ -12,6 +12,7 @@ import (
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/app/ante"
"github.com/0glabs/0g-chain/chaincfg"
)
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
@ -45,7 +46,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100_000_000)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100_000_000)),
),
},
sdk.NewCoins(), // no fee
@ -80,12 +81,12 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
),
banktypes.NewMsgSend(
testAddresses[2],
testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
),
},
sdk.NewCoins(), // no fee
@ -121,7 +122,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
),
},
sdk.NewCoins(), // no fee

View File

@ -16,6 +16,7 @@ import (
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/app/ante"
"github.com/0glabs/0g-chain/chaincfg"
)
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
@ -58,7 +59,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100e6)),
),
},
checkTx: false,
@ -128,7 +129,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
[]sdk.Msg{banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100e6)),
)}),
},
checkTx: false,
@ -161,7 +162,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
banktypes.NewMsgSend(
testAddresses[0],
testAddresses[3],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100e6)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100e6)),
),
&evmtypes.MsgEthereumTx{},
},

View File

@ -34,6 +34,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
@ -156,7 +157,7 @@ func (suite *EIP712TestSuite) SetupTest() {
// Genesis states
evmGs := evmtypes.NewGenesisState(
evmtypes.NewParams(
"neuron", // evmDenom
chaincfg.BaseDenom, // evmDenom
false, // allowedUnprotectedTxs
true, // enableCreate
true, // enableCall
@ -223,10 +224,10 @@ func (suite *EIP712TestSuite) SetupTest() {
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
}
// funds our test accounts with some ua0gi
// funds our test accounts with some auxiliary denom
coinsGenState := app.NewFundedGenStateWithSameCoins(
tApp.AppCodec(),
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1e9)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e9)),
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
)
@ -313,17 +314,17 @@ func (suite *EIP712TestSuite) SetupTest() {
params := evmKeeper.GetParams(suite.ctx)
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
{
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertERC20ToCoin",
MsgTypeUrl: "/zgc.evmutil.v1beta1.MsgConvertERC20ToCoin",
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
ValueTypes: []evmtypes.EIP712MsgAttrType{
{Name: "initiator", Type: "string"},
{Name: "receiver", Type: "string"},
{Name: "0gchain_erc20_address", Type: "string"},
{Name: "zgchain_erc20_address", Type: "string"},
{Name: "amount", Type: "string"},
},
},
{
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertCoinToERC20",
MsgTypeUrl: "/zgc.evmutil.v1beta1.MsgConvertCoinToERC20",
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
ValueTypes: []evmtypes.EIP712MsgAttrType{
{Name: "initiator", Type: "string"},
@ -376,7 +377,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
suite.tApp.FundModuleAccount(
suite.ctx,
evmutiltypes.ModuleName,
sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(0))),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(0)),
)
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
@ -476,7 +477,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, "ua0gi")
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.AuxiliaryDenom)
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
return txBuilder
},
@ -488,7 +489,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
failCheckTx: true,
errMsg: "invalid chain-id",
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(20))
return suite.createTestEIP712CosmosTxBuilder(
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
)
@ -501,7 +502,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
failCheckTx: true,
errMsg: "invalid pubkey",
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(20))
return suite.createTestEIP712CosmosTxBuilder(
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
)
@ -529,7 +530,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
msgs = tc.updateMsgs(msgs)
}
gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(20))
txBuilder := suite.createTestEIP712CosmosTxBuilder(
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
)
@ -603,7 +604,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
}
// deliver deposit msg
gasAmt := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(20)))
gasAmt := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(20))
txBuilder := suite.createTestEIP712CosmosTxBuilder(
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
)

View File

@ -13,6 +13,7 @@ import (
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/app/ante"
"github.com/0glabs/0g-chain/chaincfg"
)
func mustParseDecCoins(value string) sdk.DecCoins {
@ -30,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: "neuron",
EvmDenom: chaincfg.BaseDenom,
})
testCases := []struct {

View File

@ -14,6 +14,7 @@ import (
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/app/ante"
"github.com/0glabs/0g-chain/chaincfg"
)
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
@ -33,7 +34,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
"MsgCreateVestingAccount",
vesting.NewMsgCreateVestingAccount(
testAddresses[0], testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
false,
),
@ -44,7 +45,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
"MsgCreateVestingAccount",
vesting.NewMsgCreatePermanentLockedAccount(
testAddresses[0], testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
),
true,
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
@ -63,7 +64,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
"other messages not affected",
banktypes.NewMsgSend(
testAddresses[0], testAddresses[1],
sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 100)),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100)),
),
false,
"",

View File

@ -159,7 +159,7 @@ func GenesisStateWithSingleValidator(
balances := []banktypes.Balance{
{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(100000000000000))),
Coins: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(100000000000000)),
},
}
@ -222,7 +222,7 @@ func genesisStateWithValSet(
}
// set validators and delegations
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
currentStakingGenesis.Params.BondDenom = "ua0gi"
currentStakingGenesis.Params.BondDenom = chaincfg.AuxiliaryDenom // TODO:
stakingGenesis := stakingtypes.NewGenesisState(
currentStakingGenesis.Params,
@ -242,13 +242,13 @@ func genesisStateWithValSet(
for range delegations {
// add delegated tokens to total supply
totalSupply = totalSupply.Add(sdk.NewCoin("ua0gi", bondAmt))
totalSupply = totalSupply.Add(chaincfg.MakeCoinForAuxiliaryDenom(bondAmt))
}
// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin("ua0gi", bondAmt)},
Coins: sdk.Coins{chaincfg.MakeCoinForAuxiliaryDenom(bondAmt)},
})
bankGenesis := banktypes.NewGenesisState(

57
chaincfg/coin_helper.go Normal file
View File

@ -0,0 +1,57 @@
package chaincfg
import (
"fmt"
"math/big"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/shopspring/decimal"
)
func toBigInt(amount any) *big.Int {
if amount == nil {
return big.NewInt(0)
}
var val *big.Int
switch amount.(type) {
case int:
val = big.NewInt(int64(amount.(int)))
case int32:
val = big.NewInt(int64(amount.(int32)))
case int64:
val = big.NewInt(amount.(int64))
case string:
var ok bool
val, ok = new(big.Int).SetString(amount.(string), 0)
if !ok {
panic(fmt.Sprintf("invalid amount string: %s", amount.(string)))
}
case math.Int:
val = amount.(math.Int).BigInt()
case *big.Int:
val = amount.(*big.Int)
case float64:
val = decimal.NewFromFloat(amount.(float64)).BigInt()
default:
panic(fmt.Sprintf("invalid amount type: %T", amount))
}
return val
}
func MakeCoinForStandardDenom(amount any) sdk.Coin {
return makeCoin(StandardDenom, toBigInt(amount))
}
func MakeCoinForAuxiliaryDenom(amount any) sdk.Coin {
return makeCoin(AuxiliaryDenom, toBigInt(amount))
}
func MakeCoinForBaseDenom(amount any) sdk.Coin {
return makeCoin(BaseDenom, toBigInt(amount))
}
func makeCoin(denom string, amount *big.Int) sdk.Coin {
return sdk.NewCoin(denom, math.NewIntFromBigInt(amount))
}

37
chaincfg/denoms.go Normal file
View File

@ -0,0 +1,37 @@
package chaincfg
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
StandardDenom = "a0gi"
AuxiliaryDenom = "ua0gi"
BaseDenom = "neuron"
BondDenom = BaseDenom
AuxiliaryDenomUnit = 6
BaseDenomUnit = 18
AuxiliaryDenomConversionMultiplier = 1e12
BaseDenomConversionMultiplier = 1e18
)
// RegisterDenoms registers the base and auxiliary 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 {
panic(err)
}
if err := sdk.RegisterDenom(BaseDenom, sdk.NewDecWithPrec(1, BaseDenomUnit)); err != nil {
panic(err)
}
}

80
chaincfg/denoms_test.go Normal file
View File

@ -0,0 +1,80 @@
package chaincfg
import (
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
)
func TestRegisterDenoms(t *testing.T) {
RegisterDenoms()
tests := []struct {
name string
from sdk.Coin
targetDenom string
expCoin sdk.Coin
expErr error
}{
{
"standard to auxiliary",
MakeCoinForStandardDenom(99),
AuxiliaryDenom,
MakeCoinForAuxiliaryDenom(99 * (BaseDenomConversionMultiplier / AuxiliaryDenomConversionMultiplier)),
nil,
},
{
"auxiliary to standard",
MakeCoinForAuxiliaryDenom(5e7),
StandardDenom,
MakeCoinForStandardDenom(50),
nil,
},
{
"standard to base",
MakeCoinForStandardDenom(22),
BaseDenom,
MakeCoinForBaseDenom(22 * BaseDenomConversionMultiplier),
nil,
},
{
"base to standard",
MakeCoinForBaseDenom("97000000000000000000"),
StandardDenom,
MakeCoinForStandardDenom(97),
nil,
},
{
"auxiliary to base",
MakeCoinForAuxiliaryDenom(33),
BaseDenom,
MakeCoinForBaseDenom(33 * AuxiliaryDenomConversionMultiplier),
nil,
},
{
"base to auxiliary",
MakeCoinForBaseDenom("770000000000000"),
AuxiliaryDenom,
MakeCoinForAuxiliaryDenom(770000000000000 / AuxiliaryDenomConversionMultiplier),
nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ret, err := sdk.ConvertCoin(tt.from, tt.targetDenom)
if tt.expErr != nil {
if err == nil {
t.Errorf("expErr is not nil, but got nil")
return
}
} else {
if err != nil {
t.Errorf("expErr is nil, but got %v", err)
return
}
}
assert.Equal(t, tt.expCoin, ret)
})
}
}

View File

@ -73,7 +73,7 @@ func TestKvCLIKeysAddRecover(t *testing.T) {
f.Cleanup()
}
func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
func TestZgChainCLIKeysAddRecoverHDPath(t *testing.T) {
t.Parallel()
f := InitFixtures(t)

View File

@ -76,7 +76,7 @@ func NewRootCmd() *cobra.Command {
return err
}
customAppTemplate, customAppConfig := servercfg.AppConfig("ua0gi")
customAppTemplate, customAppConfig := servercfg.AppConfig(chaincfg.AuxiliaryDenom)
return server.InterceptConfigsPreRunHandler(
cmd,

4
go.sum
View File

@ -963,6 +963,8 @@ github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0U
github.com/linxGnu/grocksdb v1.8.13 h1:X3Id7Obhf8qLY9WPc4LmmtIyabmdDf810XSFDnLlW7E=
github.com/linxGnu/grocksdb v1.8.13/go.mod h1:QYiYypR2d4v63Wj1adOOfzglnoII0gLj3PNh4fZkcFA=
github.com/lucasjones/reggen v0.0.0-20180717132126-cdb49ff09d77/go.mod h1:5ELEyG+X8f+meRWHuqUOewBOhvHkl7M76pdGEansxW4=
github.com/lukehoban/go-outline v0.0.0-20161011150102-e78556874252 h1:D2VNityLQ1srKF+MSllSGQ4NwMci20llMkvVAmU2aCk=
github.com/lukehoban/go-outline v0.0.0-20161011150102-e78556874252/go.mod h1:O9bIJ6BRFBmP3AKTW8cqESVbauSmifSrRB/n9zq6x9Q=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
@ -1196,6 +1198,8 @@ github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfP
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=

View File

@ -5,6 +5,7 @@ import (
"time"
sdkmath "cosmossdk.io/math"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@ -41,7 +42,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
}
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{
@ -64,7 +65,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
}
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{
@ -97,7 +98,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
}
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6)))
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6)))
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
periods := vestingtypes.Periods{
@ -125,25 +126,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
}
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(4e6)))
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, 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("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // +15 days - vesting
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // +30 days - vesting
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
}
@ -159,36 +160,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
expectedPeriods := []vestingtypes.Period{
{
Length: 15 * 24 * 60 * 60, // 15 days
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
{
Length: 15 * 24 * 60 * 60, // 15 days
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
}
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, 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("ua0gi", sdkmath.NewInt(3e6)))
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, 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("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // +15 days - vesting
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
}
@ -198,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("ua0gi", sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
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")
}
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
balance := sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(3e6)))
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, 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("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
vestingtypes.Period{
Length: 15 * 24 * 60 * 60, // +15 days - vesting
Amount: sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))),
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))),
},
}
vacc := createVestingAccount(balance, vestingStartTime, periods)
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(1e6))))
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, 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("ua0gi", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
}

View File

@ -13,7 +13,7 @@ message ConversionPair {
option (gogoproto.goproto_getters) = false;
// ERC20 address of the token on the 0gChain EVM
bytes zgChain_erc20_address = 1 [
bytes zgchain_erc20_address = 1 [
(gogoproto.customname) = "ZgChainERC20Address",
(gogoproto.casttype) = "HexBytes"
];

View File

@ -44,7 +44,7 @@ message MsgConvertERC20ToCoin {
// 0gChain bech32 address that will receive the converted sdk.Coin.
string receiver = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// EVM 0x hex address of the ERC20 contract.
string zgChain_erc20_address = 3 [(gogoproto.customname) = "ZgChainERC20Address"];
string zgchain_erc20_address = 3 [(gogoproto.customname) = "ZgChainERC20Address"];
// ERC20 token amount to convert.
string amount = 4 [
(cosmos_proto.scalar) = "cosmos.Int",

View File

@ -12,6 +12,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/tests/e2e/testutil"
"github.com/0glabs/0g-chain/tests/util"
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
@ -63,7 +64,7 @@ func (suite *IntegrationTestSuite) setupAccountWithCosmosCoinERC20Balance(
tx := util.ZgChainMsgRequest{
Msgs: []sdk.Msg{&msg},
GasLimit: 4e5,
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(400))),
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(400)),
Data: "converting sdk coin to erc20",
}
res := user.SignAndBroadcastZgChainTx(tx)
@ -102,7 +103,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
tx := util.ZgChainMsgRequest{
Msgs: []sdk.Msg{&convertToErc20Msg},
GasLimit: 2e6,
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(2000))),
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(2000)),
Data: "converting sdk coin to erc20",
}
res := user.SignAndBroadcastZgChainTx(tx)
@ -144,7 +145,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
tx = util.ZgChainMsgRequest{
Msgs: []sdk.Msg{&convertFromErc20Msg},
GasLimit: 2e5,
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(200)),
Data: "converting erc20 to cosmos coin",
}
res = user.SignAndBroadcastZgChainTx(tx)
@ -183,7 +184,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
user,
suite.ZgChain,
2e6,
sdk.NewCoins(a0gi(big.NewInt(1e4))),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e4)),
[]sdk.Msg{&convertToErc20Msg},
"this is a memo",
).GetTx()
@ -237,7 +238,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
user,
suite.ZgChain,
2e5,
sdk.NewCoins(a0gi(big.NewInt(200))),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(200)),
[]sdk.Msg{&convertFromErc20Msg},
"",
).GetTx()
@ -331,7 +332,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
"cosmo-coin-converter-complex-alice", initialAliceAmount,
)
gasMoney := sdk.NewCoins(a0gi(big.NewInt(1e5)))
gasMoney := sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e5))
bob := suite.ZgChain.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
amount := big.NewInt(1e3) // test assumes this is half of alice's balance.
@ -412,7 +413,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
convertTx := util.ZgChainMsgRequest{
Msgs: []sdk.Msg{&convertMsg},
GasLimit: 2e5,
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(200)),
Data: "bob converts his new erc20 to an sdk.Coin",
}
convertRes := bob.SignAndBroadcastZgChainTx(convertTx)

View File

@ -11,7 +11,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/tests/e2e/contracts/greeter"
"github.com/0glabs/0g-chain/tests/util"
)
@ -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(a0gi(big.NewInt(1e6))))
user := suite.ZgChain.NewFundedAccount("greeter-contract-user", sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(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(a0gi(big.NewInt(2e4))))
sender := suite.ZgChain.NewFundedAccount("eip712-msgSend", sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(2e4)))
receiver := app.RandomAddress()
// setup message for sending some a0gi to random receiver
// setup message for sending some auxiliary denom to random receiver
msgs := []sdk.Msg{
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(a0gi(big.NewInt(1e3)))),
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1e3))),
}
// create tx
@ -76,7 +76,7 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
sender,
suite.ZgChain,
1e6,
sdk.NewCoins(a0gi(big.NewInt(1e4))),
sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(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 a0gi is transferred.
// check that the message was processed & the auxiliary denom is transferred.
balRes, err := suite.ZgChain.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
Address: receiver.String(),
Denom: "ua0gi",
Denom: chaincfg.AuxiliaryDenom,
})
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(a0gi(big.NewInt(1e5)))
// depositor := suite.ZgChain.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(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(a0gi(big.NewInt(1e4)),
// sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(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(a0gi(big.NewInt(1000)),
// FeeAmount: sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(1000)),
// Data: "withdrawing from mint & converting back to erc20",
// }
// lastRes := depositor.SignAndBroadcastZgChainTx(withdrawAndConvertBack)

View File

@ -13,6 +13,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/tests/util"
)
@ -23,10 +24,10 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
minGasPrices, err := getMinFeeFromAppToml(util.ZgChainHomePath())
suite.NoError(err)
// evm uses neuron, get neuron min fee
evmMinGas := minGasPrices.AmountOf("neuron").TruncateInt().BigInt()
// evm uses base denom, get base denom min fee
evmMinGas := minGasPrices.AmountOf(chaincfg.BaseDenom).TruncateInt().BigInt()
// returns eth_gasPrice, units in a0gi
// returns eth_gasPrice, units in auxiliary denom
gasPrice, err := suite.ZgChain.EvmClient.SuggestGasPrice(context.Background())
suite.NoError(err)
@ -37,13 +38,13 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
suite.SkipIfKvtoolDisabled()
// setup sender & receiver
sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(a0gi(big.NewInt(1e3))))
sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(chaincfg.MakeCoinForAuxiliaryDenom(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("neuron").TruncateInt()
minGasPrice := minFees.AmountOf(chaincfg.BaseDenom).TruncateInt()
// attempt tx with less than min gas price (min fee - 1)
tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt()

View File

@ -19,18 +19,15 @@ import (
emtypes "github.com/evmos/ethermint/types"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/tests/e2e/testutil"
"github.com/0glabs/0g-chain/tests/util"
)
var (
minEvmGasPrice = big.NewInt(1e10) // neuron
minEvmGasPrice = big.NewInt(1e10) // base denom
)
func a0gi(amt *big.Int) sdk.Coin {
return sdk.NewCoin("ua0gi", sdkmath.NewIntFromBigInt(amt))
}
type IntegrationTestSuite struct {
testutil.E2eTestSuite
}
@ -57,7 +54,7 @@ func (suite *IntegrationTestSuite) TestChainID() {
// example test that funds a new account & queries its balance
func (suite *IntegrationTestSuite) TestFundedAccount() {
funds := a0gi(big.NewInt(1e3))
funds := chaincfg.MakeCoinForAuxiliaryDenom(1e3)
acc := suite.ZgChain.NewFundedAccount("example-acc", sdk.NewCoins(funds))
// check that the sdk & evm signers are for the same account
@ -66,21 +63,21 @@ func (suite *IntegrationTestSuite) TestFundedAccount() {
// check balance via SDK query
res, err := suite.ZgChain.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
acc.SdkAddress, "ua0gi",
acc.SdkAddress, chaincfg.AuxiliaryDenom,
))
suite.NoError(err)
suite.Equal(funds, *res.Balance)
// check balance via EVM query
neuronBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
baseDenomBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
suite.NoError(err)
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), neuronBal)
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), baseDenomBal)
}
// example test that signs & broadcasts an EVM tx
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
// fund an account that can perform the transfer
initialFunds := a0gi(big.NewInt(1e6)) // 1 A0GI
initialFunds := chaincfg.MakeCoinForAuxiliaryDenom(1e6) // 1 (auxiliary denom)
acc := suite.ZgChain.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
// get a rando account to send 0gchain to
@ -92,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 a0gi over EVM
a0giToTransfer := big.NewInt(1e17) // .1 A0GI; neuron has 18 decimals.
// transfer auxiliary denom over EVM
AuxiliaryDenomToTransfer := big.NewInt(1e17) // .1 (auxiliary denom); base denom has 18 decimals.
req := util.EvmTxRequest{
Tx: ethtypes.NewTransaction(nonce, to, a0giToTransfer, 1e5, minEvmGasPrice, nil),
Tx: ethtypes.NewTransaction(nonce, to, AuxiliaryDenomToTransfer, 1e5, minEvmGasPrice, nil),
Data: "any ol' data to track this through the system",
}
res := acc.SignAndBroadcastEvmTx(req)
@ -103,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.
a0giUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
AuxiliaryDenomUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)).
QuoRaw(1e12) // convert neuron to a0gi
QuoRaw(1e12) // convert base denom to auxiliary denom
// expect (9 - gas used) A0GI remaining in account.
// expect (9 - gas used) (auxiliary denom) remaining in account.
balance := suite.ZgChain.QuerySdkForBalances(acc.SdkAddress)
suite.Equal(sdkmath.NewInt(9e5).Sub(a0giUsedForGas), balance.AmountOf("ua0gi"))
suite.Equal(sdkmath.NewInt(9e5).Sub(AuxiliaryDenomUsedForGas), balance.AmountOf(chaincfg.AuxiliaryDenom))
}
// TestIbcTransfer transfers A0GI from the primary 0g-chain (suite.ZgChain) to the ibc chain (suite.Ibc).
// TestIbcTransfer transfers (auxiliary 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 := a0gi(big.NewInt(1e5)) // .1 A0GI
funds := chaincfg.MakeCoinForAuxiliaryDenom(1e5) // .1 (auxiliary 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 := a0gi(big.NewInt(200))
fee := chaincfg.MakeCoinForAuxiliaryDenom(200)
fundsToSend := a0gi(big.NewInt(5e4)) // .005 A0GI
fundsToSend := chaincfg.MakeCoinForAuxiliaryDenom(5e4) // .005 (auxiliary denom)
transferMsg := ibctypes.NewMsgTransfer(
testutil.IbcPort,
testutil.IbcChannel,
@ -157,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("ua0gi").Equal(expectedSrcBalance.Amount)
return balance.AmountOf(chaincfg.AuxiliaryDenom).Equal(expectedSrcBalance.Amount)
}, 10*time.Second, 1*time.Second)
// expect the balance to be transferred to the ibc chain!

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/0glabs/0g-chain/chaincfg"
rpchttpclient "github.com/cometbft/cometbft/rpc/client/http"
"github.com/ethereum/go-ethereum/ethclient"
)
@ -73,7 +74,7 @@ var (
EvmRpcUrl: "http://localhost:8545",
ChainId: "0gchainlocalnet_8888-1",
StakingDenom: "ua0gi",
StakingDenom: chaincfg.AuxiliaryDenom,
}
kvtoolIbcChain = ChainDetails{
RpcUrl: "http://localhost:26658",

View File

@ -258,7 +258,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 .001a0gi
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001 auxiliary denom
Data: fmt.Sprintf("sending %s to %s", amount, to),
},
)

View File

@ -106,7 +106,7 @@ func QueryCalcSwapIDCmd(queryRoute string) *cobra.Command {
return &cobra.Command{
Use: "calc-swapid [random-number-hash] [sender] [sender-other-chain]",
Short: "calculate swap ID for the given random number hash, sender, and sender other chain",
Example: "bep3 calc-swapid 0677bd8a303dd981810f34d8e5cc6507f13b391899b84d3c1be6c6045a17d747 kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny bnb1ud3q90r98l3mhd87kswv3h8cgrymzeljct8qn7",
Example: "bep3 calc-swapid 0677bd8a303dd981810f34d8e5cc6507f13b391899b84d3c1be6c6045a17d747 0g1l0xsq2z7gqd7yly0g40y5836g0appumark77ny bnb1ud3q90r98l3mhd87kswv3h8cgrymzeljct8qn7",
Args: cobra.MinimumNArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
@ -220,7 +220,7 @@ func QueryGetAtomicSwapsCmd(queryRoute string) *cobra.Command {
Short: "query atomic swaps with optional filters",
Long: strings.TrimSpace(`Query for all paginated atomic swaps that match optional filters:
Example:
$ kvcli q bep3 swaps --involve=kava1l0xsq2z7gqd7yly0g40y5836g0appumark77ny
$ kvcli q bep3 swaps --involve=0g1l0xsq2z7gqd7yly0g40y5836g0appumark77ny
$ kvcli q bep3 swaps --expiration=280
$ kvcli q bep3 swaps --status=(Open|Completed|Expired)
$ kvcli q bep3 swaps --direction=(Incoming|Outgoing)

View File

@ -12,6 +12,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/x/bep3"
"github.com/0glabs/0g-chain/x/bep3/keeper"
"github.com/0glabs/0g-chain/x/bep3/types"
@ -35,7 +36,7 @@ func (suite *MsgServerTestSuite) SetupTest() {
// Set up genesis state and initialize
_, addrs := app.GeneratePrivKeyAddressPairs(3)
coins := sdk.NewCoins(c("bnb", 10000000000), c("a0gi", 10000))
coins := sdk.NewCoins(c("bnb", 10000000000), c(chaincfg.AuxiliaryDenom, 10000))
authGS := app.NewFundedGenStateWithSameCoins(tApp.AppCodec(), coins, addrs)
tApp.InitializeFromGenesisStates(authGS, NewBep3GenStateMulti(cdc, addrs[0]))

View File

@ -20,7 +20,7 @@ type GenesisTestSuite struct {
}
func (suite *GenesisTestSuite) SetupTest() {
coin := sdk.NewCoin("a0gi", sdk.OneInt())
coin := chaincfg.MakeCoinForAuxiliaryDenom(1)
suite.swaps = atomicSwaps(10)
supply := types.NewAssetSupply(coin, coin, coin, coin, time.Duration(0))

View File

@ -5,12 +5,13 @@ import (
"time"
sdkmath "cosmossdk.io/math"
"github.com/0glabs/0g-chain/chaincfg"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)
func TestAssetSupplyValidate(t *testing.T) {
coin := sdk.NewCoin("a0gi", sdk.OneInt())
coin := chaincfg.MakeCoinForAuxiliaryDenom(1)
invalidCoin := sdk.Coin{Denom: "Invalid Denom", Amount: sdkmath.NewInt(-1)}
testCases := []struct {
msg string

View File

@ -6,12 +6,12 @@ import (
"github.com/stretchr/testify/suite"
sdkmath "cosmossdk.io/math"
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/x/committee/keeper"
"github.com/0glabs/0g-chain/x/committee/types"
)
@ -61,7 +61,7 @@ func (suite *MsgServerTestSuite) SetupTest() {
[]types.Proposal{},
[]types.Vote{},
)
suite.communityPoolAmt = sdk.NewCoins(sdk.NewCoin("neuron", sdkmath.NewInt(1000000000000000)))
suite.communityPoolAmt = sdk.NewCoins(chaincfg.MakeCoinForBaseDenom(1000000000000000))
suite.app.InitializeFromGenesisStates(
app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(testGenesis)},
// TODO: not used?

View File

@ -4,6 +4,7 @@ import (
fmt "fmt"
"time"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -18,7 +19,7 @@ const (
BaseCommitteeType = "0g/BaseCommittee"
MemberCommitteeType = "0g/MemberCommittee" // Committee is composed of member addresses that vote to enact proposals within their permissions
TokenCommitteeType = "0g/TokenCommittee" // Committee is composed of token holders with voting power determined by total token balance
BondDenom = "neuron"
BondDenom = chaincfg.BondDenom
)
// Marshal needed for protobuf compatibility.

View File

@ -171,10 +171,10 @@ func NewVoteCmd() *cobra.Command {
tokens = val.GetTokens()
}
}
// the denom of token is neuron, need to convert to A0GI
a0gi := tokens.Quo(sdk.NewInt(1_000_000_000_000_000_000))
// the denom of token is base denom, need to convert to A0GI
a0giTokenCnt := tokens.Quo(sdk.NewInt(1_000_000_000_000_000_000))
// 1_000 0AGI token / vote
numBallots := a0gi.Quo(sdk.NewInt(1_000)).Uint64()
numBallots := a0giTokenCnt.Quo(sdk.NewInt(1_000)).Uint64()
ballots := make([]*types.Ballot, numBallots)
for i := range ballots {
ballotID := uint64(i)

View File

@ -21,8 +21,8 @@ var (
const (
// Amino names
registerName = "evmos/council/MsgRegister"
voteName = "evmos/council/MsgVote"
registerName = "0g/council/MsgRegister"
voteName = "0g/council/MsgVote"
)
// NOTE: This is required for the GetSignBytes function

View File

@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/x/evmutil/keeper"
"github.com/0glabs/0g-chain/x/evmutil/testutil"
"github.com/0glabs/0g-chain/x/evmutil/types"
@ -49,7 +50,7 @@ func (suite *invariantTestSuite) SetupValidState() {
suite.FundModuleAccountWithZgChain(
types.ModuleName,
sdk.NewCoins(
sdk.NewCoin("ua0gi", sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
),
)

View File

@ -115,7 +115,7 @@ func (k Keeper) SetAccount(ctx sdk.Context, account types.Account) error {
return nil
}
// GetBalance returns the total balance of neuron for a given account by address.
// GetBalance returns the total balance of base 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 neuron for a given account by address.
// SetBalance sets the total balance of base 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 neuron balance from sender addr to recipient addr.
// SendBalance transfers the base 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 neuron: %d", amt)
return fmt.Errorf("cannot send a negative amount of base 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 neuron balance of an address.
// AddBalance increments the base 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 neuron balance of an address.
// RemoveBalance decrements the base 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)

View File

@ -37,6 +37,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/0glabs/0g-chain/app"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/x/evmutil/keeper"
"github.com/0glabs/0g-chain/x/evmutil/types"
)
@ -79,14 +80,14 @@ func (suite *Suite) SetupTest() {
suite.Addrs = addrs
evmGenesis := evmtypes.DefaultGenesisState()
evmGenesis.Params.EvmDenom = keeper.EvmDenom
evmGenesis.Params.EvmDenom = chaincfg.BaseDenom
feemarketGenesis := feemarkettypes.DefaultGenesisState()
feemarketGenesis.Params.EnableHeight = 1
feemarketGenesis.Params.NoBaseFee = false
cdc := suite.App.AppCodec()
coins := sdk.NewCoins(sdk.NewInt64Coin("ua0gi", 1000_000_000_000))
coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.AuxiliaryDenom, 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()),
@ -183,28 +184,28 @@ func (suite *Suite) ModuleBalance(denom string) sdk.Int {
}
func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) {
ua0gi := coins.AmountOf("ua0gi")
if ua0gi.IsPositive() {
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin("ua0gi", ua0gi)))
AuxiliaryDenomAmt := coins.AmountOf(chaincfg.AuxiliaryDenom)
if AuxiliaryDenomAmt.IsPositive() {
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, AuxiliaryDenomAmt)))
suite.Require().NoError(err)
}
neuron := coins.AmountOf("neuron")
if neuron.IsPositive() {
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
baseDenomAmt := coins.AmountOf(chaincfg.BaseDenom)
if baseDenomAmt.IsPositive() {
err := suite.Keeper.SetBalance(suite.Ctx, addr, baseDenomAmt)
suite.Require().NoError(err)
}
}
func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) {
ua0gi := coins.AmountOf("ua0gi")
if ua0gi.IsPositive() {
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin("ua0gi", ua0gi)))
AuxiliaryDenomAmt := coins.AmountOf(chaincfg.AuxiliaryDenom)
if AuxiliaryDenomAmt.IsPositive() {
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, AuxiliaryDenomAmt)))
suite.Require().NoError(err)
}
neuron := coins.AmountOf("neuron")
if neuron.IsPositive() {
baseDenomAmt := coins.AmountOf(chaincfg.BaseDenom)
if baseDenomAmt.IsPositive() {
addr := suite.AccountKeeper.GetModuleAddress(moduleName)
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
err := suite.Keeper.SetBalance(suite.Ctx, addr, baseDenomAmt)
suite.Require().NoError(err)
}
}
@ -215,7 +216,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress {
suite.App.FundModuleAccount(
suite.Ctx,
types.ModuleName,
sdk.NewCoins(sdk.NewCoin("ua0gi", sdkmath.NewInt(0))),
sdk.NewCoins(sdk.NewCoin(chaincfg.AuxiliaryDenom, sdkmath.NewInt(0))),
)
contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18))
@ -316,7 +317,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(
"ua0gi",
chaincfg.AuxiliaryDenom,
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
)))

View File

@ -28,7 +28,7 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// allowed to be converted between ERC20 and sdk.Coin
type ConversionPair struct {
// ERC20 address of the token on the 0gChain EVM
ZgChainERC20Address HexBytes `protobuf:"bytes,1,opt,name=zgChain_erc20_address,json=zgChainErc20Address,proto3,casttype=HexBytes" json:"zgChain_erc20_address,omitempty"`
ZgChainERC20Address HexBytes `protobuf:"bytes,1,opt,name=zgchain_erc20_address,json=zgchainErc20Address,proto3,casttype=HexBytes" json:"zgchain_erc20_address,omitempty"`
// Denom of the corresponding sdk.Coin
Denom string `protobuf:"bytes,2,opt,name=denom,proto3" json:"denom,omitempty"`
}
@ -134,20 +134,20 @@ var fileDescriptor_6bad9d4ffa6874ec = []byte{
0x62, 0xd2, 0xd5, 0xa9, 0x08, 0x67, 0x2c, 0x92, 0x9e, 0x08, 0xed, 0x09, 0xf1, 0x22, 0x6d, 0x12,
0x89, 0x58,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, 0xe5, 0x22, 0x70, 0x84, 0xaf, 0xfe, 0xcd, 0xda,
0x22, 0xa1, 0x06, 0xac, 0xb8, 0x8c, 0x7a, 0x01, 0xf1, 0xa5, 0x5a, 0x6a, 0x81, 0xce, 0xbe, 0xb5,
0xcb, 0xf9, 0x81, 0x06, 0xb7, 0x9b, 0x6f, 0x0c, 0x3e, 0x12, 0x0c, 0x3e, 0x13, 0x0c, 0x56, 0x09,
0x06, 0x9b, 0x04, 0x83, 0xb7, 0x2d, 0x56, 0x56, 0x5b, 0xac, 0x7c, 0x6d, 0xb1, 0x32, 0x3a, 0xe7,
0x5e, 0x3c, 0x9e, 0x3a, 0x1a, 0x15, 0x81, 0x6e, 0x70, 0x9f, 0x38, 0x52, 0x37, 0xf8, 0x45, 0x76,
0x6d, 0x7d, 0xbe, 0xfb, 0xa9, 0x78, 0x31, 0x61, 0xd2, 0x29, 0x67, 0xaf, 0x7d, 0xf9, 0x1b, 0x00,
0x00, 0xff, 0xff, 0xfa, 0x07, 0x29, 0xab, 0xc5, 0x01, 0x00, 0x00,
}
func (this *ConversionPair) VerboseEqual(that interface{}) error {

View File

@ -3,6 +3,7 @@ package types_test
import (
"testing"
"github.com/0glabs/0g-chain/chaincfg"
"github.com/0glabs/0g-chain/x/evmutil/testutil"
"github.com/0glabs/0g-chain/x/evmutil/types"
"github.com/stretchr/testify/require"
@ -142,7 +143,7 @@ func TestConversionPairs_Validate(t *testing.T) {
),
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
"a0gi",
chaincfg.AuxiliaryDenom,
),
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
@ -162,7 +163,7 @@ func TestConversionPairs_Validate(t *testing.T) {
),
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
"a0gi",
chaincfg.AuxiliaryDenom,
),
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
@ -183,16 +184,16 @@ func TestConversionPairs_Validate(t *testing.T) {
),
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
"a0gi",
chaincfg.AuxiliaryDenom,
),
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
"a0gi",
chaincfg.AuxiliaryDenom,
),
),
errArgs{
expectPass: false,
contains: "found duplicate enabled conversion pair denom a0gi",
contains: "found duplicate enabled conversion pair denom " + chaincfg.AuxiliaryDenom,
},
},
{
@ -208,7 +209,7 @@ func TestConversionPairs_Validate(t *testing.T) {
),
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
"a0gi",
chaincfg.AuxiliaryDenom,
),
),
errArgs{
@ -240,12 +241,12 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) {
}{
{
name: "valid token",
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 6),
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 6),
expErr: "",
},
{
name: "valid - highest allowed decimals",
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 255),
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 255),
expErr: "",
},
{
@ -280,7 +281,7 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) {
},
{
name: "invalid - decimals higher than uint8",
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 256),
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 256),
expErr: "decimals must be less than 256",
},
}

View File

@ -107,11 +107,11 @@ func (suite *ParamsTestSuite) TestParams_Validate() {
invalidConversionPairs := types.NewConversionPairs(
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
"a0gi",
chaincfg.AuxiliaryDenom,
),
types.NewConversionPair(
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
"a0gi", // duplicate denom!
chaincfg.AuxiliaryDenom, // duplicate denom!
),
)
validAllowedCosmosDenoms := types.NewAllowedCosmosCoinERC20Tokens(

View File

@ -139,7 +139,7 @@ type MsgConvertERC20ToCoin struct {
// 0gChain bech32 address that will receive the converted sdk.Coin.
Receiver string `protobuf:"bytes,2,opt,name=receiver,proto3" json:"receiver,omitempty"`
// EVM 0x hex address of the ERC20 contract.
ZgChainERC20Address string `protobuf:"bytes,3,opt,name=zgChain_erc20_address,json=zgChainErc20Address,proto3" json:"zgChain_erc20_address,omitempty"`
ZgChainERC20Address string `protobuf:"bytes,3,opt,name=zgchain_erc20_address,json=zgchainErc20Address,proto3" json:"zgchain_erc20_address,omitempty"`
// ERC20 token amount to convert.
Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,4,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"`
}
@ -452,7 +452,7 @@ func init() {
func init() { proto.RegisterFile("zgc/evmutil/v1beta1/tx.proto", fileDescriptor_b60fa1a7a6ac0cc3) }
var fileDescriptor_b60fa1a7a6ac0cc3 = []byte{
// 563 bytes of a gzipped FileDescriptorProto
// 564 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x55, 0xc1, 0x6e, 0xd3, 0x30,
0x18, 0xae, 0xb7, 0x69, 0xa2, 0xe6, 0x96, 0x6e, 0xa2, 0x0b, 0x23, 0x9d, 0x8a, 0x06, 0xd3, 0xa4,
0x26, 0x69, 0x40, 0x08, 0x21, 0x2e, 0xb4, 0x1a, 0xd2, 0x04, 0xbb, 0x84, 0x9e, 0x76, 0xa9, 0x92,
@ -471,24 +471,24 @@ var fileDescriptor_b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 0x42, 0x0d, 0x5c, 0x84, 0x1a,
0xf8, 0x3a, 0xd3, 0x2a, 0x67, 0x33, 0xad, 0xf2, 0x63, 0xa6, 0x55, 0xf6, 0xb7, 0x73, 0x83, 0x6f,
0xe2, 0x43, 0xc7, 0xe5, 0x86, 0x89, 0x5b, 0xf1, 0xc3, 0x61, 0x1c, 0x65, 0x9f, 0x8a, 0xf8, 0x01,
0x70, 0x97, 0xe3, 0x07, 0xfc, 0xc9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2f, 0xc2, 0xb2, 0xda,
0x46, 0x06, 0x00, 0x00,
}
func (this *MsgConvertCoinToERC20) VerboseEqual(that interface{}) error {

View File

@ -3,13 +3,14 @@ package types
import (
"testing"
"github.com/0glabs/0g-chain/chaincfg"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
)
func TestRawPriceKey_Iteration(t *testing.T) {
// An iterator key should only match price keys with the same market
iteratorKey := RawPriceIteratorKey("a0gi:usd")
iteratorKey := RawPriceIteratorKey(chaincfg.AuxiliaryDenom + ":usd")
addr := sdk.AccAddress("test addr")
@ -20,12 +21,12 @@ func TestRawPriceKey_Iteration(t *testing.T) {
}{
{
name: "equal marketID is included in iteration",
priceKey: RawPriceKey("a0gi:usd", addr),
priceKey: RawPriceKey(chaincfg.AuxiliaryDenom+":usd", addr),
expectErr: false,
},
{
name: "prefix overlapping marketID excluded from iteration",
priceKey: RawPriceKey("a0gi:usd:30", addr),
priceKey: RawPriceKey(chaincfg.AuxiliaryDenom+":usd:30", addr),
expectErr: true,
},
}