mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-26 00:05:18 +00:00
rename kava
This commit is contained in:
parent
4acb96258f
commit
ea69805f89
@ -11,6 +11,7 @@ import (
|
||||
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"
|
||||
ctypes "github.com/cometbft/cometbft/rpc/core/types"
|
||||
@ -52,9 +53,9 @@ func (suite *SimulateRequestTestSuite) TearDownTest() {
|
||||
}
|
||||
|
||||
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||
fromAddr, err := sdk.AccAddressFromBech32("kava1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||
fromAddr, err := sdk.AccAddressFromBech32("0g1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||
suite.Require().NoError(err)
|
||||
toAddr, err := sdk.AccAddressFromBech32("kava1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||
toAddr, err := sdk.AccAddressFromBech32("0g1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
simRequest := app.SimulateRequest{
|
||||
@ -62,11 +63,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||
bank.MsgSend{
|
||||
FromAddress: fromAddr,
|
||||
ToAddress: toAddr,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
},
|
||||
Fee: auth.StdFee{
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(5e4))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(5e4))),
|
||||
Gas: 1e6,
|
||||
},
|
||||
Memo: "test memo",
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
tmdb "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
@ -28,7 +30,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@ -53,7 +55,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
App: *app.NewApp(
|
||||
log.NewNopLogger(),
|
||||
tmdb.NewMemDB(),
|
||||
app.DefaultNodeHome,
|
||||
chaincfg.DefaultNodeHome,
|
||||
nil,
|
||||
encodingConfig,
|
||||
opts,
|
||||
@ -67,7 +69,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
chainID,
|
||||
app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e9)),
|
||||
testAddresses,
|
||||
),
|
||||
newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
||||
@ -115,7 +117,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
tc.address,
|
||||
testAddresses[0],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
@ -45,7 +47,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -80,12 +82,12 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[2],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -121,7 +123,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
@ -58,7 +60,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -128,7 +130,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
[]sdk.Msg{banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
)}),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -161,7 +163,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
),
|
||||
&evmtypes.MsgEthereumTx{},
|
||||
},
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
@ -155,7 +157,7 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
// Genesis states
|
||||
evmGs := evmtypes.NewGenesisState(
|
||||
evmtypes.NewParams(
|
||||
"akava", // evmDenom
|
||||
chaincfg.BaseDenom, // evmDenom
|
||||
false, // allowedUnprotectedTxs
|
||||
true, // enableCreate
|
||||
true, // enableCall
|
||||
@ -264,10 +266,10 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||
}
|
||||
|
||||
// funds our test accounts with some ukava
|
||||
// funds our test accounts with some a0gi
|
||||
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e3)),
|
||||
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
||||
)
|
||||
|
||||
@ -354,45 +356,45 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
params := evmKeeper.GetParams(suite.ctx)
|
||||
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
||||
{
|
||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "initiator", Type: "string"},
|
||||
{Name: "receiver", Type: "string"},
|
||||
{Name: "kava_erc20_address", Type: "string"},
|
||||
{Name: "0gchain_erc20_address", Type: "string"},
|
||||
{Name: "amount", Type: "string"},
|
||||
},
|
||||
},
|
||||
// {
|
||||
// MsgTypeUrl: "/0g-chain.cdp.v1beta1.MsgCreateCDP",
|
||||
// MsgValueTypeName: "MsgValueCDPCreate",
|
||||
// ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
// {Name: "sender", Type: "string"},
|
||||
// {Name: "collateral", Type: "Coin"},
|
||||
// {Name: "principal", Type: "Coin"},
|
||||
// {Name: "collateral_type", Type: "string"},
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// MsgTypeUrl: "/0g-chain.cdp.v1beta1.MsgDeposit",
|
||||
// MsgValueTypeName: "MsgValueCDPDeposit",
|
||||
// ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
// {Name: "depositor", Type: "string"},
|
||||
// {Name: "owner", Type: "string"},
|
||||
// {Name: "collateral", Type: "Coin"},
|
||||
// {Name: "collateral_type", Type: "string"},
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// MsgTypeUrl: "/0g-chain.hard.v1beta1.MsgDeposit",
|
||||
// MsgValueTypeName: "MsgValueHardDeposit",
|
||||
// ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
// {Name: "depositor", Type: "string"},
|
||||
// {Name: "amount", Type: "Coin[]"},
|
||||
// },
|
||||
// },
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgCreateCDP",
|
||||
MsgValueTypeName: "MsgValueCDPCreate",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "sender", Type: "string"},
|
||||
{Name: "collateral", Type: "Coin"},
|
||||
{Name: "principal", Type: "Coin"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgDeposit",
|
||||
MsgValueTypeName: "MsgValueCDPDeposit",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "owner", Type: "string"},
|
||||
{Name: "collateral", Type: "Coin"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgDeposit",
|
||||
MsgValueTypeName: "MsgValueHardDeposit",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "amount", Type: "Coin[]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "initiator", Type: "string"},
|
||||
@ -400,23 +402,23 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
{Name: "amount", Type: "Coin"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgRepayDebt",
|
||||
MsgValueTypeName: "MsgValueCDPRepayDebt",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "sender", Type: "string"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
{Name: "payment", Type: "Coin"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgWithdraw",
|
||||
MsgValueTypeName: "MsgValueHardWithdraw",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "amount", Type: "Coin[]"},
|
||||
},
|
||||
},
|
||||
// {
|
||||
// MsgTypeUrl: "/0g-chain.cdp.v1beta1.MsgRepayDebt",
|
||||
// MsgValueTypeName: "MsgValueCDPRepayDebt",
|
||||
// ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
// {Name: "sender", Type: "string"},
|
||||
// {Name: "collateral_type", Type: "string"},
|
||||
// {Name: "payment", Type: "Coin"},
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// MsgTypeUrl: "/0g-chain.hard.v1beta1.MsgWithdraw",
|
||||
// MsgValueTypeName: "MsgValueHardWithdraw",
|
||||
// ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
// {Name: "depositor", Type: "string"},
|
||||
// {Name: "amount", Type: "Coin[]"},
|
||||
// },
|
||||
// },
|
||||
}
|
||||
evmKeeper.SetParams(suite.ctx, params)
|
||||
|
||||
@ -462,7 +464,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
|
||||
suite.tApp.FundModuleAccount(
|
||||
suite.ctx,
|
||||
evmutiltypes.ModuleName,
|
||||
sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(0))),
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
||||
@ -484,40 +486,40 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx bool
|
||||
errMsg string
|
||||
}{
|
||||
{
|
||||
name: "processes deposit eip712 messages successfully",
|
||||
usdcDepositAmt: 100,
|
||||
usdxToMintAmt: 99,
|
||||
},
|
||||
// {
|
||||
// name: "processes deposit eip712 messages successfully",
|
||||
// usdcDepositAmt: 100,
|
||||
// usdxToMintAmt: 99,
|
||||
// },
|
||||
{
|
||||
name: "fails when convertion more erc20 usdc than balance",
|
||||
usdcDepositAmt: 51_000,
|
||||
usdxToMintAmt: 100,
|
||||
errMsg: "transfer amount exceeds balance",
|
||||
},
|
||||
{
|
||||
name: "fails when minting more usdx than allowed",
|
||||
usdcDepositAmt: 100,
|
||||
usdxToMintAmt: 100,
|
||||
errMsg: "proposed collateral ratio is below liquidation ratio",
|
||||
},
|
||||
{
|
||||
name: "fails when trying to convert usdc for another address",
|
||||
usdcDepositAmt: 100,
|
||||
usdxToMintAmt: 90,
|
||||
errMsg: "unauthorized",
|
||||
failCheckTx: true,
|
||||
updateMsgs: func(msgs []sdk.Msg) []sdk.Msg {
|
||||
convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
||||
suite.testEVMAddr2,
|
||||
suite.testAddr,
|
||||
suite.usdcEVMAddr,
|
||||
suite.getEVMAmount(100),
|
||||
)
|
||||
msgs[0] = &convertMsg
|
||||
return msgs
|
||||
},
|
||||
},
|
||||
// {
|
||||
// name: "fails when minting more usdx than allowed",
|
||||
// usdcDepositAmt: 100,
|
||||
// usdxToMintAmt: 100,
|
||||
// errMsg: "proposed collateral ratio is below liquidation ratio",
|
||||
// },
|
||||
// {
|
||||
// name: "fails when trying to convert usdc for another address",
|
||||
// usdcDepositAmt: 100,
|
||||
// usdxToMintAmt: 90,
|
||||
// errMsg: "unauthorized",
|
||||
// failCheckTx: true,
|
||||
// updateMsgs: func(msgs []sdk.Msg) []sdk.Msg {
|
||||
// convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
||||
// suite.testEVMAddr2,
|
||||
// suite.testAddr,
|
||||
// suite.usdcEVMAddr,
|
||||
// suite.getEVMAmount(100),
|
||||
// )
|
||||
// msgs[0] = &convertMsg
|
||||
// return msgs
|
||||
// },
|
||||
// },
|
||||
{
|
||||
name: "fails when trying to convert erc20 for non-whitelisted contract",
|
||||
usdcDepositAmt: 100,
|
||||
@ -559,7 +561,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, "ukava")
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.DisplayDenom)
|
||||
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
||||
return txBuilder
|
||||
},
|
||||
@ -571,7 +573,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("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -584,7 +586,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("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -624,7 +626,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
msgs = tc.updateMsgs(msgs)
|
||||
}
|
||||
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -710,7 +712,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
||||
}
|
||||
|
||||
// deliver deposit msg
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
||||
)
|
||||
|
@ -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: "akava",
|
||||
EvmDenom: chaincfg.BaseDenom,
|
||||
})
|
||||
|
||||
testCases := []struct {
|
||||
@ -44,29 +45,29 @@ func TestEvmMinGasFilter(t *testing.T) {
|
||||
mustParseDecCoins(""),
|
||||
},
|
||||
{
|
||||
"zero ukava gas price",
|
||||
mustParseDecCoins("0ukava"),
|
||||
mustParseDecCoins("0ukava"),
|
||||
"zero a0gi gas price",
|
||||
mustParseDecCoins("0a0gi"),
|
||||
mustParseDecCoins("0a0gi"),
|
||||
},
|
||||
{
|
||||
"non-zero ukava gas price",
|
||||
mustParseDecCoins("0.001ukava"),
|
||||
mustParseDecCoins("0.001ukava"),
|
||||
"non-zero a0gi gas price",
|
||||
mustParseDecCoins("0.001a0gi"),
|
||||
mustParseDecCoins("0.001a0gi"),
|
||||
},
|
||||
{
|
||||
"zero ukava gas price, min akava price",
|
||||
mustParseDecCoins("0ukava;100000akava"),
|
||||
mustParseDecCoins("0ukava"), // akava is removed
|
||||
"zero a0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0a0gi;100000neuron"),
|
||||
mustParseDecCoins("0a0gi"), // neuron is removed
|
||||
},
|
||||
{
|
||||
"zero ukava gas price, min akava price, other token",
|
||||
mustParseDecCoins("0ukava;100000akava;0.001other"),
|
||||
mustParseDecCoins("0ukava;0.001other"), // akava is removed
|
||||
"zero a0gi gas price, min neuron price, other token",
|
||||
mustParseDecCoins("0a0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0a0gi;0.001other"), // neuron is removed
|
||||
},
|
||||
{
|
||||
"non-zero ukava gas price, min akava price",
|
||||
mustParseDecCoins("0.25ukava;100000akava;0.001other"),
|
||||
mustParseDecCoins("0.25ukava;0.001other"), // akava is removed
|
||||
"non-zero a0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0.25a0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0.25a0gi;0.001other"), // neuron is removed
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
@ -33,7 +35,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreateVestingAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||
false,
|
||||
),
|
||||
@ -44,7 +46,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreatePermanentLockedAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
true,
|
||||
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||
@ -63,7 +65,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"other messages not affected",
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
false,
|
||||
"",
|
||||
|
32
app/app.go
32
app/app.go
@ -3,10 +3,9 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
stdlog "log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
|
||||
dbm "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
@ -106,7 +105,8 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
kavaparams "github.com/0glabs/0g-chain/app/params"
|
||||
chainparams "github.com/0glabs/0g-chain/app/params"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/bep3"
|
||||
bep3keeper "github.com/0glabs/0g-chain/x/bep3/keeper"
|
||||
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||
@ -130,14 +130,7 @@ import (
|
||||
validatorvestingtypes "github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
const (
|
||||
appName = "kava"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultNodeHome default home directories for the application daemon
|
||||
DefaultNodeHome string
|
||||
|
||||
// ModuleBasics manages simple versions of full app modules.
|
||||
// It's used for things such as codec registration and genesis file verification.
|
||||
ModuleBasics = module.NewBasicManager(
|
||||
@ -249,7 +242,7 @@ var DefaultOptions = Options{
|
||||
EVMMaxGasWanted: ethermintconfig.DefaultMaxTxGasWanted,
|
||||
}
|
||||
|
||||
// App is the Kava ABCI application.
|
||||
// App is the 0gChain ABCI application.
|
||||
type App struct {
|
||||
*baseapp.BaseApp
|
||||
|
||||
@ -315,12 +308,9 @@ type App struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
stdlog.Printf("Failed to get home dir %v", err)
|
||||
}
|
||||
|
||||
DefaultNodeHome = filepath.Join(userHomeDir, ".kava")
|
||||
// 1stake = 1 ukava = 1_000_000_000_000 akava = 1_000_000_000_000 neuron
|
||||
conversionMultiplier := sdkmath.NewIntFromUint64(1_000_000_000_000)
|
||||
sdk.DefaultPowerReduction = sdk.DefaultPowerReduction.Mul(conversionMultiplier)
|
||||
}
|
||||
|
||||
// NewApp returns a reference to an initialized App.
|
||||
@ -329,7 +319,7 @@ func NewApp(
|
||||
db dbm.DB,
|
||||
homePath string,
|
||||
traceStore io.Writer,
|
||||
encodingConfig kavaparams.EncodingConfig,
|
||||
encodingConfig chainparams.EncodingConfig,
|
||||
options Options,
|
||||
baseAppOptions ...func(*baseapp.BaseApp),
|
||||
) *App {
|
||||
@ -337,7 +327,7 @@ func NewApp(
|
||||
legacyAmino := encodingConfig.Amino
|
||||
interfaceRegistry := encodingConfig.InterfaceRegistry
|
||||
|
||||
bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
|
||||
bApp := baseapp.NewBaseApp(chaincfg.AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
|
||||
bApp.SetCommitMultiStoreTracer(traceStore)
|
||||
bApp.SetVersion(version.Version)
|
||||
bApp.SetInterfaceRegistry(interfaceRegistry)
|
||||
@ -1064,7 +1054,7 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Store current module versions in kava-10 to setup future in-place upgrades.
|
||||
// Store current module versions in 0gChain-10 to setup future in-place upgrades.
|
||||
// During in-place migrations, the old module versions in the store will be referenced to determine which migrations to run.
|
||||
app.upgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
db "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cometbft/cometbft/libs/log"
|
||||
@ -25,11 +26,11 @@ import (
|
||||
)
|
||||
|
||||
func TestNewApp(t *testing.T) {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
NewApp(
|
||||
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
||||
db.NewMemDB(),
|
||||
DefaultNodeHome,
|
||||
chaincfg.DefaultNodeHome,
|
||||
nil,
|
||||
MakeEncodingConfig(),
|
||||
DefaultOptions,
|
||||
@ -37,9 +38,9 @@ func TestNewApp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExport(t *testing.T) {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
db := db.NewMemDB()
|
||||
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
||||
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, chaincfg.DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
||||
|
||||
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
package app
|
||||
|
||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
const (
|
||||
// Bech32MainPrefix defines the Bech32 prefix for account addresses
|
||||
Bech32MainPrefix = "kava"
|
||||
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
||||
Bech32PrefixAccPub = Bech32MainPrefix + "pub"
|
||||
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
||||
Bech32PrefixValAddr = Bech32MainPrefix + "val" + "oper"
|
||||
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
||||
Bech32PrefixValPub = Bech32MainPrefix + "val" + "oper" + "pub"
|
||||
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
||||
Bech32PrefixConsAddr = Bech32MainPrefix + "val" + "cons"
|
||||
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
||||
Bech32PrefixConsPub = Bech32MainPrefix + "val" + "cons" + "pub"
|
||||
|
||||
Bip44CoinType = 459 // see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||
)
|
||||
|
||||
// SetSDKConfig configures the global config with kava app specific parameters.
|
||||
// It does not seal the config to allow modification in tests.
|
||||
func SetSDKConfig() *sdk.Config {
|
||||
config := sdk.GetConfig()
|
||||
SetBech32AddressPrefixes(config)
|
||||
SetBip44CoinType(config)
|
||||
return config
|
||||
}
|
||||
|
||||
// SetBech32AddressPrefixes sets the global prefix to be used when serializing addresses to bech32 strings.
|
||||
func SetBech32AddressPrefixes(config *sdk.Config) {
|
||||
config.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32PrefixAccPub)
|
||||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
||||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
||||
}
|
||||
|
||||
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
|
||||
func SetBip44CoinType(config *sdk.Config) {
|
||||
config.SetCoinType(Bip44CoinType)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Package params defines the simulation parameters for the Kava app.
|
||||
Package params defines the simulation parameters for the 0gChain app.
|
||||
|
||||
It contains the default weights used for each transaction used on the module's
|
||||
simulation. These weights define the chance for a transaction to be simulated at
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
|
||||
var _ govv1.TallyHandler = TallyHandler{}
|
||||
|
||||
// TallyHandler is the tally handler for kava
|
||||
// TallyHandler is the tally handler for 0gchaind
|
||||
type TallyHandler struct {
|
||||
gk govkeeper.Keeper
|
||||
stk stakingkeeper.Keeper
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -43,7 +44,7 @@ func (suite *tallyHandlerSuite) SetupTest() {
|
||||
|
||||
stakingKeeper := *suite.app.GetStakingKeeper()
|
||||
suite.staking = stakingHelper{stakingKeeper}
|
||||
suite.staking.setBondDenom(suite.ctx, "ukava")
|
||||
suite.staking.setBondDenom(suite.ctx, chaincfg.DisplayDenom)
|
||||
|
||||
suite.tallier = NewTallyHandler(
|
||||
suite.app.GetGovKeeper(),
|
||||
@ -301,7 +302,7 @@ func (suite *tallyHandlerSuite) mintDerivative(owner sdk.AccAddress, validator s
|
||||
// suite.Require().NoError(err)
|
||||
|
||||
// return minted
|
||||
return sdk.NewCoin("ukava", amount)
|
||||
return sdk.NewCoin(chaincfg.DisplayDenom, amount)
|
||||
}
|
||||
|
||||
func (suite *tallyHandlerSuite) delegateToNewBondedValidator(delegator sdk.AccAddress, amount sdkmath.Int) stakingtypes.ValidatorI {
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
tmdb "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cometbft/cometbft/libs/log"
|
||||
@ -78,7 +79,7 @@ type TestApp struct {
|
||||
//
|
||||
// Note, it also sets the sdk config with the app's address prefix, coin type, etc.
|
||||
func NewTestApp() TestApp {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
return NewTestAppFromSealed()
|
||||
}
|
||||
@ -90,7 +91,7 @@ func NewTestAppFromSealed() TestApp {
|
||||
encCfg := MakeEncodingConfig()
|
||||
|
||||
app := NewApp(
|
||||
log.NewNopLogger(), db, DefaultNodeHome, nil,
|
||||
log.NewNopLogger(), db, chaincfg.DefaultNodeHome, nil,
|
||||
encCfg, DefaultOptions, baseapp.SetChainID(TestChainId),
|
||||
)
|
||||
return TestApp{App: *app}
|
||||
@ -168,7 +169,7 @@ func GenesisStateWithSingleValidator(
|
||||
balances := []banktypes.Balance{
|
||||
{
|
||||
Address: acc.GetAddress().String(),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(100000000000000))),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(100000000000000))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -231,7 +232,7 @@ func genesisStateWithValSet(
|
||||
}
|
||||
// set validators and delegations
|
||||
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
||||
currentStakingGenesis.Params.BondDenom = "ukava"
|
||||
currentStakingGenesis.Params.BondDenom = chaincfg.DisplayDenom
|
||||
|
||||
stakingGenesis := stakingtypes.NewGenesisState(
|
||||
currentStakingGenesis.Params,
|
||||
@ -251,13 +252,13 @@ func genesisStateWithValSet(
|
||||
|
||||
for range delegations {
|
||||
// add delegated tokens to total supply
|
||||
totalSupply = totalSupply.Add(sdk.NewCoin("ukava", bondAmt))
|
||||
totalSupply = totalSupply.Add(sdk.NewCoin(chaincfg.DisplayDenom, 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("ukava", bondAmt)},
|
||||
Coins: sdk.Coins{sdk.NewCoin(chaincfg.DisplayDenom, bondAmt)},
|
||||
})
|
||||
|
||||
bankGenesis := banktypes.NewGenesisState(
|
||||
|
@ -92,7 +92,7 @@ type Fixtures struct {
|
||||
|
||||
// NewFixtures creates a new instance of Fixtures with many vars set
|
||||
func NewFixtures(t *testing.T) *Fixtures {
|
||||
tmpDir, err := ioutil.TempDir("", "kava_integration_"+t.Name()+"_")
|
||||
tmpDir, err := ioutil.TempDir("", "0gchain_integration_"+t.Name()+"_")
|
||||
require.NoError(t, err)
|
||||
|
||||
servAddr, port, err := server.FreeTCPAddr()
|
||||
@ -201,9 +201,9 @@ func (f *Fixtures) Flags() string {
|
||||
}
|
||||
|
||||
//___________________________________________________________________________________
|
||||
// kavad
|
||||
// 0gchaind
|
||||
|
||||
// UnsafeResetAll is kavad unsafe-reset-all
|
||||
// UnsafeResetAll is 0gchaind unsafe-reset-all
|
||||
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
||||
executeWrite(f.T, addFlags(cmd, flags))
|
||||
@ -211,7 +211,7 @@ func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||
require.NoError(f.T, err)
|
||||
}
|
||||
|
||||
// KvInit is kavad init
|
||||
// KvInit is 0gchaind init
|
||||
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
||||
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
|
||||
@ -229,25 +229,25 @@ func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||
f.ChainID = chainID
|
||||
}
|
||||
|
||||
// AddGenesisAccount is kavad add-genesis-account
|
||||
// AddGenesisAccount is 0gchaind add-genesis-account
|
||||
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.KvdBinary, address, coins, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// GenTx is kavad gentx
|
||||
// GenTx is 0gchaind gentx
|
||||
func (f *Fixtures) GenTx(name string, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s --keyring-backend=test", f.KvdBinary, name, f.KvdHome, f.KvcliHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// CollectGenTxs is kavad collect-gentxs
|
||||
// CollectGenTxs is 0gchaind collect-gentxs
|
||||
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
||||
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// GDStart runs kavad start with the appropriate flags and returns a process
|
||||
// GDStart runs 0gchaind start with the appropriate flags and returns a process
|
||||
func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
||||
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v --pruning=everything", f.KvdBinary, f.KvdHome, f.RPCAddr, f.P2PAddr)
|
||||
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
|
||||
@ -256,7 +256,7 @@ func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
||||
return proc
|
||||
}
|
||||
|
||||
// GDTendermint returns the results of kavad tendermint [query]
|
||||
// GDTendermint returns the results of 0gchaind tendermint [query]
|
||||
func (f *Fixtures) GDTendermint(query string) string {
|
||||
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
||||
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
||||
@ -265,7 +265,7 @@ func (f *Fixtures) GDTendermint(query string) string {
|
||||
return strings.TrimSpace(stdout)
|
||||
}
|
||||
|
||||
// ValidateGenesis runs kavad validate-genesis
|
||||
// ValidateGenesis runs 0gchaind validate-genesis
|
||||
func (f *Fixtures) ValidateGenesis() {
|
||||
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, cmd)
|
||||
|
@ -7,29 +7,29 @@ import (
|
||||
"github.com/0glabs/0g-chain/client/grpc/util"
|
||||
)
|
||||
|
||||
// KavaGrpcClient enables the usage of kava grpc query clients and query utils
|
||||
type KavaGrpcClient struct {
|
||||
config KavaGrpcClientConfig
|
||||
// ZgChainGrpcClient enables the usage of 0gchaind grpc query clients and query utils
|
||||
type ZgChainGrpcClient struct {
|
||||
config ZgChainGrpcClientConfig
|
||||
|
||||
// Query clients for cosmos and kava modules
|
||||
// Query clients for cosmos and 0gchaind modules
|
||||
Query *query.QueryClient
|
||||
|
||||
// Utils for common queries (ie fetch an unpacked BaseAccount)
|
||||
*util.Util
|
||||
}
|
||||
|
||||
// KavaGrpcClientConfig is a configuration struct for a KavaGrpcClient
|
||||
type KavaGrpcClientConfig struct {
|
||||
// ZgChainGrpcClientConfig is a configuration struct for a ZgChainGrpcClient
|
||||
type ZgChainGrpcClientConfig struct {
|
||||
// note: add future config options here
|
||||
}
|
||||
|
||||
// NewClient creates a new KavaGrpcClient via a grpc url
|
||||
func NewClient(grpcUrl string) (*KavaGrpcClient, error) {
|
||||
// NewClient creates a new ZgChainGrpcClient via a grpc url
|
||||
func NewClient(grpcUrl string) (*ZgChainGrpcClient, error) {
|
||||
return NewClientWithConfig(grpcUrl, NewDefaultConfig())
|
||||
}
|
||||
|
||||
// NewClientWithConfig creates a new KavaGrpcClient via a grpc url and config
|
||||
func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpcClient, error) {
|
||||
// NewClientWithConfig creates a new ZgChainGrpcClient via a grpc url and config
|
||||
func NewClientWithConfig(grpcUrl string, config ZgChainGrpcClientConfig) (*ZgChainGrpcClient, error) {
|
||||
if grpcUrl == "" {
|
||||
return nil, errors.New("grpc url cannot be empty")
|
||||
}
|
||||
@ -37,7 +37,7 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
|
||||
if error != nil {
|
||||
return nil, error
|
||||
}
|
||||
client := &KavaGrpcClient{
|
||||
client := &ZgChainGrpcClient{
|
||||
Query: query,
|
||||
Util: util.NewUtil(query),
|
||||
config: config,
|
||||
@ -45,6 +45,6 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func NewDefaultConfig() KavaGrpcClientConfig {
|
||||
return KavaGrpcClientConfig{}
|
||||
func NewDefaultConfig() ZgChainGrpcClientConfig {
|
||||
return ZgChainGrpcClientConfig{}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
The query package includes Cosmos and Kava gRPC query clients.
|
||||
The query package includes Cosmos and 0gchaind gRPC query clients.
|
||||
|
||||
To ensure that the `QueryClient` stays updated, add new module query clients
|
||||
to the `QueryClient` whenever new modules with grpc queries are added to the Kava app.
|
||||
to the `QueryClient` whenever new modules with grpc queries are added to the 0gchaind app.
|
||||
*/
|
||||
package query
|
||||
|
@ -31,7 +31,7 @@ import (
|
||||
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||
)
|
||||
|
||||
// QueryClient is a wrapper with all Cosmos and Kava grpc query clients
|
||||
// QueryClient is a wrapper with all Cosmos and 0gchaind grpc query clients
|
||||
type QueryClient struct {
|
||||
// cosmos-sdk query clients
|
||||
|
||||
@ -58,7 +58,7 @@ type QueryClient struct {
|
||||
IbcClient ibcclienttypes.QueryClient
|
||||
IbcTransfer ibctransfertypes.QueryClient
|
||||
|
||||
// kava module query clients
|
||||
// 0gchaind module query clients
|
||||
|
||||
// Auction auctiontypes.QueryClient
|
||||
Bep3 bep3types.QueryClient
|
||||
|
@ -54,7 +54,7 @@ func TestNewQueryClient_ValidClient(t *testing.T) {
|
||||
require.NotNil(t, client.IbcClient)
|
||||
require.NotNil(t, client.IbcTransfer)
|
||||
|
||||
// validate kava clients
|
||||
// validate 0gchaind clients
|
||||
// require.NotNil(t, client.Auction)
|
||||
require.NotNil(t, client.Bep3)
|
||||
// require.NotNil(t, client.Cdp)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
The util package contains utility functions for the Kava gRPC client.
|
||||
The util package contains utility functions for the 0gchaind gRPC client.
|
||||
|
||||
For example, `account.go` includes account-related query helpers.
|
||||
In this file, utilities such as `client.Util.BaseAccount(addr)` is exposed to
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
query "github.com/0glabs/0g-chain/client/grpc/query"
|
||||
)
|
||||
|
||||
// Util contains utility functions for the Kava gRPC client
|
||||
// Util contains utility functions for the 0gchaind gRPC client
|
||||
type Util struct {
|
||||
query *query.QueryClient
|
||||
encodingConfig params.EncodingConfig
|
||||
|
@ -34,7 +34,7 @@ const (
|
||||
flagSkipLoadLatest = "skip-load-latest"
|
||||
)
|
||||
|
||||
// appCreator holds functions used by the sdk server to control the kava app.
|
||||
// appCreator holds functions used by the sdk server to control the 0gchaind app.
|
||||
// The methods implement types in cosmos-sdk/server/types
|
||||
type appCreator struct {
|
||||
encodingConfig params.EncodingConfig
|
||||
|
@ -6,14 +6,13 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/server"
|
||||
svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rootCmd := NewRootCmd()
|
||||
|
||||
if err := svrcmd.Execute(rootCmd, chaincfg.EnvPrefix, app.DefaultNodeHome); err != nil {
|
||||
if err := svrcmd.Execute(rootCmd, chaincfg.EnvPrefix, chaincfg.DefaultNodeHome); err != nil {
|
||||
switch e := err.(type) {
|
||||
case server.ErrorCode:
|
||||
os.Exit(e.Code)
|
||||
|
@ -39,7 +39,7 @@ func newShardCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "shard --home <path-to-home-dir> --start <start-block> --end <end-block> [--only-app-state] [--only-cometbft-state] [--force-app-version <app-version>]",
|
||||
Short: "Strip all blocks from the database outside of a given range",
|
||||
Long: `shard opens a local kava home directory's databases and removes all blocks outside a range defined by --start and --end. The range is inclusive of the end block.
|
||||
Long: `shard opens a local 0gchaind home directory's databases and removes all blocks outside a range defined by --start and --end. The range is inclusive of the end block.
|
||||
|
||||
It works by first rolling back the latest state to the block before the end block, and then by pruning all state before the start block.
|
||||
|
||||
@ -54,14 +54,14 @@ Similarly, the --only-cometbft-state flag skips pruning app state. This can be u
|
||||
The shard command only flags the iavl tree nodes for deletion. Actual removal from the databases will be performed when each database is compacted.
|
||||
|
||||
WARNING: this is a destructive action.`,
|
||||
Example: `Create a 1M block data shard (keeps blocks kava 1,000,000 to 2,000,000)
|
||||
$ kava shard --home path/to/.kava --start 1000000 --end 2000000
|
||||
Example: `Create a 1M block data shard (keeps blocks 1,000,000 to 2,000,000)
|
||||
$ 0gchaind shard --home path/to/.kava --start 1000000 --end 2000000
|
||||
|
||||
Prune all blocks up to 5,000,000:
|
||||
$ kava shard --home path/to/.kava --start 5000000 --end -1
|
||||
$ 0gchaind shard --home path/to/.kava --start 5000000 --end -1
|
||||
|
||||
Prune first 1M blocks _without_ affecting blockstore or cometBFT state:
|
||||
$ kava shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||
$ 0gchaind shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
//////////////////////////
|
||||
// parse & validate flags
|
||||
|
@ -4,11 +4,11 @@ pragma solidity ^0.8.18;
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
|
||||
/// @title An ERC20 token contract owned and deployed by the evmutil module of Kava.
|
||||
/// @title An ERC20 token contract owned and deployed by the evmutil module of 0g-chain.
|
||||
/// Tokens are backed one-for-one by cosmos-sdk coins held in the module account.
|
||||
/// @author Kava Labs, LLC
|
||||
/// @custom:security-contact security@kava.io
|
||||
contract ERC20KavaWrappedCosmosCoin is ERC20, Ownable {
|
||||
/// @author 0g Labs, LLC
|
||||
/// @custom:security-contact security@0g.ai
|
||||
contract ERC20ZgChainWrappedCosmosCoin is ERC20, Ownable {
|
||||
/// @notice The decimals places of the token. For display purposes only.
|
||||
uint8 private immutable _decimals;
|
||||
|
||||
|
@ -5,7 +5,7 @@ const config: HardhatUserConfig = {
|
||||
solidity: {
|
||||
version: "0.8.18",
|
||||
settings: {
|
||||
// istanbul upgrade occurred before the london hardfork, so is compatible with kava's evm
|
||||
// istanbul upgrade occurred before the london hardfork, so is compatible with 0g-chain's evm
|
||||
evmVersion: "istanbul",
|
||||
// optimize build for deployment to mainnet!
|
||||
optimizer: {
|
||||
@ -16,21 +16,21 @@ const config: HardhatUserConfig = {
|
||||
},
|
||||
networks: {
|
||||
// kvtool's local network
|
||||
kava: {
|
||||
chain: {
|
||||
url: "http://127.0.0.1:8545",
|
||||
accounts: [
|
||||
// kava keys unsafe-export-eth-key whale2
|
||||
// 0g-chain keys unsafe-export-eth-key whale2
|
||||
"AA50F4C6C15190D9E18BF8B14FC09BFBA0E7306331A4F232D10A77C2879E7966",
|
||||
],
|
||||
},
|
||||
protonet: {
|
||||
url: "https://evm.app.protonet.us-east.production.kava.io:443",
|
||||
url: "https://evm.app.protonet.us-east.production.0g-chain.io:443",
|
||||
accounts: [
|
||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||
],
|
||||
},
|
||||
internal_testnet: {
|
||||
url: "https://evm.data.internal.testnet.us-east.production.kava.io:443",
|
||||
url: "https://evm.data.internal.testnet.us-east.production.0g-chain.io:443",
|
||||
accounts: [
|
||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||
],
|
||||
|
2
contracts/package-lock.json
generated
2
contracts/package-lock.json
generated
@ -5,7 +5,7 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kava-contracts",
|
||||
"name": "0g-chain-contracts",
|
||||
"version": "0.0.1",
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "kava-contracts",
|
||||
"name": "0g-chain-contracts",
|
||||
"version": "0.0.1",
|
||||
"author": "Kava Labs",
|
||||
"author": "0g Labs",
|
||||
"private": true,
|
||||
"description": "Solidity contracts for Kava Blockchain",
|
||||
"description": "Solidity contracts for 0g Blockchain",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
@ -12,7 +12,7 @@
|
||||
"clean": "hardhat clean",
|
||||
"compile": "hardhat compile",
|
||||
"coverage": "hardhat coverage",
|
||||
"ethermint-json": "jq '{ abi: .abi | tostring, bin: .bytecode | ltrimstr(\"0x\")}' artifacts/contracts/ERC20KavaWrappedCosmosCoin.sol/ERC20KavaWrappedCosmosCoin.json > ../x/evmutil/types/ethermint_json/ERC20KavaWrappedCosmosCoin.json",
|
||||
"ethermint-json": "jq '{ abi: .abi | tostring, bin: .bytecode | ltrimstr(\"0x\")}' artifacts/contracts/ERC20ZgChainWrappedCosmosCoin.sol/ERC20ZgChainWrappedCosmosCoin.json > ../x/evmutil/types/ethermint_json/ERC20ZgChainWrappedCosmosCoin.json",
|
||||
"gen-ts-types": "hardhat typechain",
|
||||
"lint": "eslint '**/*.{js,ts}'",
|
||||
"lint-fix": "eslint '**/*.{js,ts}' --fix",
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { ethers } from "hardhat";
|
||||
|
||||
async function main() {
|
||||
const tokenName = "Kava-wrapped ATOM";
|
||||
const tokenName = "0g-chain-wrapped ATOM";
|
||||
const tokenSymbol = "kATOM";
|
||||
const tokenDecimals = 6;
|
||||
|
||||
const ERC20KavaWrappedCosmosCoin = await ethers.getContractFactory(
|
||||
"ERC20KavaWrappedCosmosCoin"
|
||||
const ERC20ZgChainWrappedCosmosCoin = await ethers.getContractFactory(
|
||||
"ERC20ZgChainWrappedCosmosCoin"
|
||||
);
|
||||
const token = await ERC20KavaWrappedCosmosCoin.deploy(
|
||||
const token = await ERC20ZgChainWrappedCosmosCoin.deploy(
|
||||
tokenName,
|
||||
tokenSymbol,
|
||||
tokenDecimals
|
||||
|
@ -2,21 +2,21 @@ import { expect } from "chai";
|
||||
import { Signer } from "ethers";
|
||||
import { ethers } from "hardhat";
|
||||
import {
|
||||
ERC20KavaWrappedCosmosCoin,
|
||||
ERC20KavaWrappedCosmosCoin__factory as ERC20KavaWrappedCosmosCoinFactory,
|
||||
ERC20ZgChainWrappedCosmosCoin,
|
||||
ERC20ZgChainWrappedCosmosCoin__factory as ERC20ZgChainWrappedCosmosCoinFactory,
|
||||
} from "../typechain-types";
|
||||
|
||||
const decimals = 6n;
|
||||
|
||||
describe("ERC20KavaWrappedCosmosCoin", function () {
|
||||
let erc20: ERC20KavaWrappedCosmosCoin;
|
||||
let erc20Factory: ERC20KavaWrappedCosmosCoinFactory;
|
||||
describe("ERC20ZgChainWrappedCosmosCoin", function () {
|
||||
let erc20: ERC20ZgChainWrappedCosmosCoin;
|
||||
let erc20Factory: ERC20ZgChainWrappedCosmosCoinFactory;
|
||||
let owner: Signer;
|
||||
let sender: Signer;
|
||||
|
||||
beforeEach(async function () {
|
||||
erc20Factory = await ethers.getContractFactory(
|
||||
"ERC20KavaWrappedCosmosCoin"
|
||||
"ERC20ZgChainWrappedCosmosCoin"
|
||||
);
|
||||
erc20 = await erc20Factory.deploy("Wrapped ATOM", "ATOM", decimals);
|
||||
[owner, sender] = await ethers.getSigners();
|
||||
|
@ -11,8 +11,8 @@ There are two types of migration:
|
||||
Genesis migration starts a whole new blockchain (with new chain-id) for the new software version.
|
||||
In-Place upgrade keeps the blockchain (and chain-id) the same for the new software version.
|
||||
|
||||
We only support migrations between mainnet kava releases.
|
||||
We only support migrations from the previous mainnet kava version to the current. We don't support migrating between two old versions, use the old software version for this.
|
||||
We only support migrations between mainnet 0g-chain releases.
|
||||
We only support migrations from the previous mainnet 0g-chain version to the current. We don't support migrating between two old versions, use the old software version for this.
|
||||
We only support migrations from old to new versions, not the other way around.
|
||||
|
||||
Genesis Migration
|
||||
@ -22,7 +22,7 @@ The process is:
|
||||
- marshal it to json (using current codec)
|
||||
|
||||
On each release we can delete the previous releases migration and old GenesisState type.
|
||||
eg kava-3 migrates `auth.GenesisState` from kava-2 to `auth.GenesisState` from kava-3,
|
||||
but for kava-4 we don't need to keep around kava-2's `auth.GenesisState` type.
|
||||
eg 0g-chain-3 migrates `auth.GenesisState` from 0g-chain-2 to `auth.GenesisState` from 0g-chain-3,
|
||||
but for 0g-chain-4 we don't need to keep around 0g-chain-2's `auth.GenesisState` type.
|
||||
*/
|
||||
package migrate
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -41,7 +43,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -64,7 +66,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -97,7 +99,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -125,25 +127,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(4e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, 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("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +30 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -159,36 +161,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
expectedPeriods := []vestingtypes.Period{
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, 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("ukava", sdkmath.NewInt(3e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, 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("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -198,35 +200,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(3e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, 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("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
vacc := createVestingAccount(balance, vestingStartTime, periods)
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))))
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, 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("ukava", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
all:
|
||||
docker build --tag kava/kavanode kavanode
|
||||
docker build --tag 0glabs/0g-chain-node 0g-chain-node
|
||||
|
||||
.PHONY: all
|
||||
|
@ -9,29 +9,29 @@ import (
|
||||
|
||||
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_NonAuthority() {
|
||||
// // ARRANGE
|
||||
// // setup kava account
|
||||
// funds := ukava(1e5) // .1 KAVA
|
||||
// kavaAcc := suite.Kava.NewFundedAccount("community-non-authority", sdk.NewCoins(funds))
|
||||
// // setup 0g account
|
||||
// funds := a0gi(1e5) // .1 A0GI
|
||||
// zgChainAcc := suite.ZgChain.NewFundedAccount("community-non-authority", sdk.NewCoins(funds))
|
||||
|
||||
// gasLimit := int64(2e5)
|
||||
// fee := ukava(200)
|
||||
// fee := a0gi(200)
|
||||
|
||||
// msg := communitytypes.NewMsgUpdateParams(
|
||||
// kavaAcc.SdkAddress,
|
||||
// zgChainAcc.SdkAddress,
|
||||
// communitytypes.DefaultParams(),
|
||||
// )
|
||||
|
||||
// // ACT
|
||||
// req := util.KavaMsgRequest{
|
||||
// req := util.ZgChainMsgRequest{
|
||||
// Msgs: []sdk.Msg{&msg},
|
||||
// GasLimit: uint64(gasLimit),
|
||||
// FeeAmount: sdk.NewCoins(fee),
|
||||
// Memo: "this is a failure!",
|
||||
// }
|
||||
// res := kavaAcc.SignAndBroadcastKavaTx(req)
|
||||
// res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||
|
||||
// // ASSERT
|
||||
// _, err := util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||
// _, err := util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||
// suite.Require().Error(err)
|
||||
// suite.Require().ErrorContains(
|
||||
// err,
|
||||
@ -42,32 +42,32 @@ import (
|
||||
|
||||
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_Authority() {
|
||||
// // ARRANGE
|
||||
// govParamsRes, err := suite.Kava.Grpc.Query.Gov.Params(context.Background(), &govv1.QueryParamsRequest{
|
||||
// govParamsRes, err := suite.ZgChain.Grpc.Query.Gov.Params(context.Background(), &govv1.QueryParamsRequest{
|
||||
// ParamsType: govv1.ParamDeposit,
|
||||
// })
|
||||
// suite.NoError(err)
|
||||
|
||||
// // Check initial params
|
||||
// communityParamsResInitial, err := suite.Kava.Grpc.Query.Community.Params(
|
||||
// communityParamsResInitial, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||
// context.Background(),
|
||||
// &communitytypes.QueryParamsRequest{},
|
||||
// )
|
||||
// suite.Require().NoError(err)
|
||||
|
||||
// // setup kava account
|
||||
// // .1 KAVA + min deposit amount for proposal
|
||||
// funds := sdk.NewCoins(ukava(1e5)).Add(govParamsRes.DepositParams.MinDeposit...)
|
||||
// kavaAcc := suite.Kava.NewFundedAccount("community-update-params", funds)
|
||||
// // setup 0g account
|
||||
// // .1 A0GI + min deposit amount for proposal
|
||||
// funds := sdk.NewCoins(a0gi(1e5)).Add(govParamsRes.DepositParams.MinDeposit...)
|
||||
// zgChainAcc := suite.ZgChain.NewFundedAccount("community-update-params", funds)
|
||||
|
||||
// gasLimit := int64(2e5)
|
||||
// fee := ukava(200)
|
||||
// fee := a0gi(200)
|
||||
|
||||
// // Wait until switchover actually happens - When testing without the upgrade
|
||||
// // handler that sets a relative switchover time, the switchover time in
|
||||
// // genesis should be set in the past so it runs immediately.
|
||||
// suite.Require().Eventually(
|
||||
// func() bool {
|
||||
// params, err := suite.Kava.Grpc.Query.Community.Params(
|
||||
// params, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||
// context.Background(),
|
||||
// &communitytypes.QueryParamsRequest{},
|
||||
// )
|
||||
@ -107,24 +107,24 @@ import (
|
||||
// proposalMsg, err := govv1.NewMsgSubmitProposal(
|
||||
// []sdk.Msg{&updateParamsMsg},
|
||||
// govParamsRes.Params.MinDeposit,
|
||||
// kavaAcc.SdkAddress.String(),
|
||||
// zgChainAcc.SdkAddress.String(),
|
||||
// "community-update-params",
|
||||
// "title",
|
||||
// "summary",
|
||||
// )
|
||||
// suite.NoError(err)
|
||||
|
||||
// req := util.KavaMsgRequest{
|
||||
// req := util.ZgChainMsgRequest{
|
||||
// Msgs: []sdk.Msg{proposalMsg},
|
||||
// GasLimit: uint64(gasLimit),
|
||||
// FeeAmount: sdk.NewCoins(fee),
|
||||
// Memo: "this is a proposal please accept me",
|
||||
// }
|
||||
// res := kavaAcc.SignAndBroadcastKavaTx(req)
|
||||
// res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||
// suite.Require().NoError(res.Err)
|
||||
|
||||
// // Wait for proposal to be submitted
|
||||
// txRes, err := util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||
// txRes, err := util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||
// suite.Require().NoError(err)
|
||||
|
||||
// // Parse tx response to get proposal id
|
||||
@ -132,7 +132,7 @@ import (
|
||||
// suite.decodeTxMsgResponse(txRes, &govRes)
|
||||
|
||||
// // 2. Vote for proposal from whale account
|
||||
// whale := suite.Kava.GetAccount(testutil.FundedAccountName)
|
||||
// whale := suite.ZgChain.GetAccount(testutil.FundedAccountName)
|
||||
// voteMsg := govv1.NewMsgVote(
|
||||
// whale.SdkAddress,
|
||||
// govRes.ProposalId,
|
||||
@ -140,21 +140,21 @@ import (
|
||||
// "",
|
||||
// )
|
||||
|
||||
// voteReq := util.KavaMsgRequest{
|
||||
// voteReq := util.ZgChainMsgRequest{
|
||||
// Msgs: []sdk.Msg{voteMsg},
|
||||
// GasLimit: uint64(gasLimit),
|
||||
// FeeAmount: sdk.NewCoins(fee),
|
||||
// Memo: "voting",
|
||||
// }
|
||||
// voteRes := whale.SignAndBroadcastKavaTx(voteReq)
|
||||
// voteRes := whale.SignAndBroadcastZgChainTx(voteReq)
|
||||
// suite.Require().NoError(voteRes.Err)
|
||||
|
||||
// _, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, voteRes.Result.TxHash, 6*time.Second)
|
||||
// _, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, voteRes.Result.TxHash, 6*time.Second)
|
||||
// suite.Require().NoError(err)
|
||||
|
||||
// // 3. Wait until proposal passes
|
||||
// suite.Require().Eventually(func() bool {
|
||||
// proposalRes, err := suite.Kava.Grpc.Query.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
||||
// proposalRes, err := suite.ZgChain.Grpc.Query.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
||||
// ProposalId: govRes.ProposalId,
|
||||
// })
|
||||
// suite.NoError(err)
|
||||
@ -163,7 +163,7 @@ import (
|
||||
// }, 60*time.Second, 1*time.Second)
|
||||
|
||||
// // Check parameters are updated
|
||||
// communityParamsRes, err := suite.Kava.Grpc.Query.Community.Params(
|
||||
// communityParamsRes, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||
// context.Background(),
|
||||
// &communitytypes.QueryParamsRequest{},
|
||||
// )
|
||||
@ -179,10 +179,10 @@ func (suite *IntegrationTestSuite) decodeTxMsgResponse(txRes *sdk.TxResponse, pt
|
||||
|
||||
// Unmarshal data to TxMsgData
|
||||
var txMsgData sdk.TxMsgData
|
||||
suite.Kava.EncodingConfig.Marshaler.MustUnmarshal(txResBytes, &txMsgData)
|
||||
suite.ZgChain.EncodingConfig.Marshaler.MustUnmarshal(txResBytes, &txMsgData)
|
||||
suite.T().Logf("txData.MsgResponses: %v", txMsgData.MsgResponses)
|
||||
|
||||
// Parse MsgResponse
|
||||
suite.Kava.EncodingConfig.Marshaler.MustUnmarshal(txMsgData.MsgResponses[0].Value, ptr)
|
||||
suite.ZgChain.EncodingConfig.Marshaler.MustUnmarshal(txMsgData.MsgResponses[0].Value, ptr)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
@ -24,24 +24,24 @@ func setupConvertToCoinTest(
|
||||
) (denom string, initialFunds sdk.Coins, user *testutil.SigningAccount) {
|
||||
// we expect a denom to be registered to the allowed denoms param
|
||||
// and for the funded account to have a balance for that denom
|
||||
params, err := suite.Kava.Grpc.Query.Evmutil.Params(
|
||||
params, err := suite.ZgChain.Grpc.Query.Evmutil.Params(
|
||||
context.Background(),
|
||||
&evmutiltypes.QueryParamsRequest{},
|
||||
)
|
||||
suite.NoError(err)
|
||||
suite.GreaterOrEqual(
|
||||
len(params.Params.AllowedCosmosDenoms), 1,
|
||||
"kava chain expected to have at least one AllowedCosmosDenom for ERC20 conversion",
|
||||
"0g-chain expected to have at least one AllowedCosmosDenom for ERC20 conversion",
|
||||
)
|
||||
|
||||
tokenInfo := params.Params.AllowedCosmosDenoms[0]
|
||||
denom = tokenInfo.CosmosDenom
|
||||
initialFunds = sdk.NewCoins(
|
||||
sdk.NewInt64Coin(suite.Kava.StakingDenom, 1e5), // gas money
|
||||
sdk.NewInt64Coin(suite.ZgChain.StakingDenom, 1e5), // gas money
|
||||
sdk.NewInt64Coin(denom, initialCosmosCoinConversionDenomFunds), // conversion-enabled cosmos coin
|
||||
)
|
||||
|
||||
user = suite.Kava.NewFundedAccount(accountName, initialFunds)
|
||||
user = suite.ZgChain.NewFundedAccount(accountName, initialFunds)
|
||||
|
||||
return denom, initialFunds, user
|
||||
}
|
||||
@ -63,20 +63,20 @@ func (suite *IntegrationTestSuite) setupAccountWithCosmosCoinERC20Balance(
|
||||
user.EvmAddress.Hex(),
|
||||
convertAmount,
|
||||
)
|
||||
tx := util.KavaMsgRequest{
|
||||
tx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&msg},
|
||||
GasLimit: 4e5,
|
||||
FeeAmount: sdk.NewCoins(ukava(400)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(400))),
|
||||
Data: "converting sdk coin to erc20",
|
||||
}
|
||||
res := user.SignAndBroadcastKavaTx(tx)
|
||||
res := user.SignAndBroadcastZgChainTx(tx)
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// adjust sdk balance
|
||||
sdkBalance = sdkBalance.Sub(convertAmount)
|
||||
|
||||
// query for the deployed contract
|
||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
context.Background(),
|
||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||
)
|
||||
@ -92,7 +92,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter")
|
||||
|
||||
convertAmount := int64(5e3)
|
||||
initialModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
initialModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
|
||||
///////////////////////////////
|
||||
// CONVERT COSMOS COIN -> ERC20
|
||||
@ -102,17 +102,17 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
user.EvmAddress.Hex(),
|
||||
sdk.NewInt64Coin(denom, convertAmount),
|
||||
)
|
||||
tx := util.KavaMsgRequest{
|
||||
tx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertToErc20Msg},
|
||||
GasLimit: 2e6,
|
||||
FeeAmount: sdk.NewCoins(ukava(2000)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(2000))),
|
||||
Data: "converting sdk coin to erc20",
|
||||
}
|
||||
res := user.SignAndBroadcastKavaTx(tx)
|
||||
res := user.SignAndBroadcastZgChainTx(tx)
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// query for the deployed contract
|
||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
context.Background(),
|
||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||
)
|
||||
@ -122,17 +122,17 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
||||
|
||||
// check erc20 balance
|
||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
||||
|
||||
// check cosmos coin is deducted from account
|
||||
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
||||
balance := suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
balance := suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(expectedFunds, balance)
|
||||
|
||||
// check that module account has sdk coins
|
||||
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
||||
actualModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
actualModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
||||
|
||||
///////////////////////////////
|
||||
@ -144,26 +144,26 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
sdk.NewInt64Coin(denom, convertAmount),
|
||||
)
|
||||
|
||||
tx = util.KavaMsgRequest{
|
||||
tx = util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertFromErc20Msg},
|
||||
GasLimit: 2e5,
|
||||
FeeAmount: sdk.NewCoins(ukava(200)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||
Data: "converting erc20 to cosmos coin",
|
||||
}
|
||||
res = user.SignAndBroadcastKavaTx(tx)
|
||||
res = user.SignAndBroadcastZgChainTx(tx)
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// check erc20 balance
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
||||
|
||||
// check cosmos coin is added back to account
|
||||
expectedFunds = initialFunds.AmountOf(denom)
|
||||
balance = suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
balance = suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(expectedFunds, balance)
|
||||
|
||||
// check that module account has sdk coins deducted
|
||||
actualModuleBalance = suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
actualModuleBalance = suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
suite.Equal(initialModuleBalance, actualModuleBalance)
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter-eip712")
|
||||
|
||||
convertAmount := int64(5e3)
|
||||
initialModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
initialModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
|
||||
///////////////////////////////
|
||||
// CONVERT COSMOS COIN -> ERC20
|
||||
@ -184,28 +184,28 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
)
|
||||
tx := suite.NewEip712TxBuilder(
|
||||
user,
|
||||
suite.Kava,
|
||||
suite.ZgChain,
|
||||
2e6,
|
||||
sdk.NewCoins(ukava(1e4)),
|
||||
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||
[]sdk.Msg{&convertToErc20Msg},
|
||||
"this is a memo",
|
||||
).GetTx()
|
||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
suite.NoError(err)
|
||||
|
||||
// submit the eip712 message to the chain.
|
||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
TxBytes: txBytes,
|
||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 12*time.Second)
|
||||
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 12*time.Second)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// query for the deployed contract
|
||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
context.Background(),
|
||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||
)
|
||||
@ -215,17 +215,17 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
||||
|
||||
// check erc20 balance
|
||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
||||
|
||||
// check cosmos coin is deducted from account
|
||||
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
||||
balance := suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
balance := suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(expectedFunds, balance)
|
||||
|
||||
// check that module account has sdk coins
|
||||
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
||||
actualModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
actualModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
||||
|
||||
///////////////////////////////
|
||||
@ -238,37 +238,37 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
)
|
||||
tx = suite.NewEip712TxBuilder(
|
||||
user,
|
||||
suite.Kava,
|
||||
suite.ZgChain,
|
||||
2e5,
|
||||
sdk.NewCoins(ukava(200)),
|
||||
sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||
[]sdk.Msg{&convertFromErc20Msg},
|
||||
"",
|
||||
).GetTx()
|
||||
txBytes, err = suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
txBytes, err = suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
suite.NoError(err)
|
||||
|
||||
// submit the eip712 message to the chain
|
||||
res, err = suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
res, err = suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
TxBytes: txBytes,
|
||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
suite.NoError(err)
|
||||
|
||||
// check erc20 balance
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
||||
|
||||
// check cosmos coin is added back to account
|
||||
expectedFunds = initialFunds.AmountOf(denom)
|
||||
balance = suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
balance = suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(expectedFunds, balance)
|
||||
|
||||
// check that module account has sdk coins deducted
|
||||
actualModuleBalance = suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
actualModuleBalance = suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
suite.Equal(initialModuleBalance, actualModuleBalance)
|
||||
}
|
||||
|
||||
@ -334,8 +334,8 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
"cosmo-coin-converter-complex-alice", initialAliceAmount,
|
||||
)
|
||||
|
||||
gasMoney := sdk.NewCoins(ukava(1e5))
|
||||
bob := suite.Kava.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
||||
gasMoney := sdk.NewCoins(a0gi(big.NewInt(1e5)))
|
||||
bob := suite.ZgChain.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
||||
amount := big.NewInt(1e3) // test assumes this is half of alice's balance.
|
||||
|
||||
// bob can't move alice's funds
|
||||
@ -400,10 +400,10 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
suite.Require().NoError(res.Err)
|
||||
|
||||
// alice should have amount deducted
|
||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(initialAliceAmount-amount.Int64()), erc20Balance, "alice has unexpected erc20 balance")
|
||||
// bob should have amount added
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||
suite.BigIntsEqual(amount, erc20Balance, "bob has unexpected erc20 balance")
|
||||
|
||||
// convert bob's new funds back to an sdk.Coin
|
||||
@ -412,24 +412,24 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
bob.SdkAddress.String(),
|
||||
sdk.NewInt64Coin(denom, amount.Int64()),
|
||||
)
|
||||
convertTx := util.KavaMsgRequest{
|
||||
convertTx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertMsg},
|
||||
GasLimit: 2e5,
|
||||
FeeAmount: sdk.NewCoins(ukava(200)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||
Data: "bob converts his new erc20 to an sdk.Coin",
|
||||
}
|
||||
convertRes := bob.SignAndBroadcastKavaTx(convertTx)
|
||||
convertRes := bob.SignAndBroadcastZgChainTx(convertTx)
|
||||
suite.NoError(convertRes.Err)
|
||||
|
||||
// bob should have no more erc20 balance
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected no erc20 balance for bob")
|
||||
// bob should have sdk balance
|
||||
balance := suite.Kava.QuerySdkForBalances(bob.SdkAddress).AmountOf(denom)
|
||||
balance := suite.ZgChain.QuerySdkForBalances(bob.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(sdk.NewIntFromBigInt(amount), balance)
|
||||
|
||||
// alice should have the remaining balance
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
suite.BigIntsEqual(amount, erc20Balance, "expected alice to have half initial funds remaining")
|
||||
|
||||
// convert alice's remaining balance back to sdk coins
|
||||
@ -438,6 +438,6 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
alice.SdkAddress.String(),
|
||||
sdk.NewInt64Coin(denom, amount.Int64()),
|
||||
)
|
||||
convertRes = alice.SignAndBroadcastKavaTx(convertTx)
|
||||
convertRes = alice.SignAndBroadcastZgChainTx(convertTx)
|
||||
suite.NoError(convertRes.Err)
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/tests/e2e/contracts/greeter"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
@ -21,10 +22,10 @@ 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.Kava.NewFundedAccount("greeter-contract-user", sdk.NewCoins(ukava(1e6)))
|
||||
user := suite.ZgChain.NewFundedAccount("greeter-contract-user", sdk.NewCoins(a0gi(big.NewInt(1e6))))
|
||||
|
||||
greeterAddr := suite.Kava.ContractAddrs["greeter"]
|
||||
contract, err := greeter.NewGreeter(greeterAddr, suite.Kava.EvmClient)
|
||||
greeterAddr := suite.ZgChain.ContractAddrs["greeter"]
|
||||
contract, err := greeter.NewGreeter(greeterAddr, suite.ZgChain.EvmClient)
|
||||
suite.NoError(err)
|
||||
|
||||
beforeGreeting, err := contract.Greet(nil)
|
||||
@ -34,7 +35,7 @@ func (suite *IntegrationTestSuite) TestEthCallToGreeterContract() {
|
||||
tx, err := contract.SetGreeting(user.EvmAuth, updatedGreeting)
|
||||
suite.NoError(err)
|
||||
|
||||
_, err = util.WaitForEvmTxReceipt(suite.Kava.EvmClient, tx.Hash(), 10*time.Second)
|
||||
_, err = util.WaitForEvmTxReceipt(suite.ZgChain.EvmClient, tx.Hash(), 10*time.Second)
|
||||
suite.NoError(err)
|
||||
|
||||
afterGreeting, err := contract.Greet(nil)
|
||||
@ -49,14 +50,14 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
||||
amount := big.NewInt(1)
|
||||
|
||||
// make unauthenticated eth_call query to check balance
|
||||
beforeBalance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||
beforeBalance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||
|
||||
// make authenticate eth_call to transfer tokens
|
||||
res := suite.FundKavaErc20Balance(randoReceiver, amount)
|
||||
res := suite.FundZgChainErc20Balance(randoReceiver, amount)
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// make another unauthenticated eth_call query to check new balance
|
||||
afterBalance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||
afterBalance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||
|
||||
suite.BigIntsEqual(big.NewInt(0), beforeBalance, "expected before balance to be zero")
|
||||
suite.BigIntsEqual(amount, afterBalance, "unexpected post-transfer balance")
|
||||
@ -64,42 +65,42 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
||||
|
||||
func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// create new funded account
|
||||
sender := suite.Kava.NewFundedAccount("eip712-msgSend", sdk.NewCoins(ukava(2e4)))
|
||||
sender := suite.ZgChain.NewFundedAccount("eip712-msgSend", sdk.NewCoins(a0gi(big.NewInt(2e4))))
|
||||
receiver := app.RandomAddress()
|
||||
|
||||
// setup message for sending some kava to random receiver
|
||||
// setup message for sending some a0gi to random receiver
|
||||
msgs := []sdk.Msg{
|
||||
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(ukava(1e3))),
|
||||
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(a0gi(big.NewInt(1e3)))),
|
||||
}
|
||||
|
||||
// create tx
|
||||
tx := suite.NewEip712TxBuilder(
|
||||
sender,
|
||||
suite.Kava,
|
||||
suite.ZgChain,
|
||||
1e6,
|
||||
sdk.NewCoins(ukava(1e4)),
|
||||
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||
msgs,
|
||||
"this is a memo",
|
||||
).GetTx()
|
||||
|
||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
suite.NoError(err)
|
||||
|
||||
// broadcast tx
|
||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
TxBytes: txBytes,
|
||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
suite.NoError(err)
|
||||
|
||||
// check that the message was processed & the kava is transferred.
|
||||
balRes, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
// check that the message was processed & the a0gi is transferred.
|
||||
balRes, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
Address: receiver.String(),
|
||||
Denom: "ukava",
|
||||
Denom: chaincfg.DisplayDenom,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdk.NewInt(1e3), balRes.Balance.Amount)
|
||||
@ -114,9 +115,9 @@ func (suite *IntegrationTestSuite) TestEip712ConvertToCoinAndDepositToLend() {
|
||||
sdkDenom := suite.DeployedErc20.CosmosDenom
|
||||
|
||||
// create new funded account
|
||||
depositor := suite.Kava.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(ukava(1e5)))
|
||||
depositor := suite.ZgChain.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(a0gi(big.NewInt(1e5))))
|
||||
// give them erc20 balance to deposit
|
||||
fundRes := suite.FundKavaErc20Balance(depositor.EvmAddress, amount.BigInt())
|
||||
fundRes := suite.FundZgChainErc20Balance(depositor.EvmAddress, amount.BigInt())
|
||||
suite.NoError(fundRes.Err)
|
||||
|
||||
// setup messages for convert to coin & deposit into earn
|
||||
@ -142,33 +143,33 @@ func (suite *IntegrationTestSuite) TestEip712ConvertToCoinAndDepositToLend() {
|
||||
// create tx
|
||||
tx := suite.NewEip712TxBuilder(
|
||||
depositor,
|
||||
suite.Kava,
|
||||
suite.ZgChain,
|
||||
1e6,
|
||||
sdk.NewCoins(ukava(1e4)),
|
||||
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||
msgs,
|
||||
"doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit",
|
||||
).GetTx()
|
||||
|
||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
suite.NoError(err)
|
||||
|
||||
// broadcast tx
|
||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
TxBytes: txBytes,
|
||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// check that depositor no longer has erc20 balance
|
||||
balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||
balance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(0), balance, "expected no erc20 balance")
|
||||
|
||||
// check that account has cdp
|
||||
// cdpRes, err := suite.Kava.Grpc.Query.Cdp.Cdp(context.Background(), &cdptypes.QueryCdpRequest{
|
||||
// cdpRes, err := suite.ZgChain.Grpc.Query.Cdp.Cdp(context.Background(), &cdptypes.QueryCdpRequest{
|
||||
// CollateralType: suite.DeployedErc20.CdpCollateralType,
|
||||
// Owner: depositor.SdkAddress.String(),
|
||||
// })
|
||||
@ -187,15 +188,15 @@ func (suite *IntegrationTestSuite) TestEip712ConvertToCoinAndDepositToLend() {
|
||||
depositor.EvmAddress.Hex(),
|
||||
sdk.NewCoin(sdkDenom, amount),
|
||||
)
|
||||
withdrawAndConvertBack := util.KavaMsgRequest{
|
||||
withdrawAndConvertBack := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{ /*&withdraw,*/ &convertBack},
|
||||
GasLimit: 1e6,
|
||||
FeeAmount: sdk.NewCoins(ukava(1000)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(1000))),
|
||||
Data: "withdrawing from mint & converting back to erc20",
|
||||
}
|
||||
lastRes := depositor.SignAndBroadcastKavaTx(withdrawAndConvertBack)
|
||||
lastRes := depositor.SignAndBroadcastZgChainTx(withdrawAndConvertBack)
|
||||
suite.NoError(lastRes.Err)
|
||||
|
||||
balance = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||
balance = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||
suite.BigIntsEqual(amount.BigInt(), balance, "expected returned erc20 balance")
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
@ -11,13 +12,13 @@ import (
|
||||
|
||||
func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
|
||||
// ARRANGE
|
||||
// setup kava account
|
||||
funds := ukava(1e5) // .1 KAVA
|
||||
kavaAcc := suite.Kava.NewFundedAccount("balance-test", sdk.NewCoins(funds))
|
||||
// setup 0g account
|
||||
funds := a0gi(big.NewInt(1e5))
|
||||
zgAcc := suite.ZgChain.NewFundedAccount("balance-test", sdk.NewCoins(funds))
|
||||
|
||||
// ACT
|
||||
rsp, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
Address: kavaAcc.SdkAddress.String(),
|
||||
rsp, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
Address: zgAcc.SdkAddress.String(),
|
||||
Denom: funds.Denom,
|
||||
})
|
||||
|
||||
@ -28,7 +29,7 @@ func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
|
||||
|
||||
func (suite *IntegrationTestSuite) TestGrpcClientQueryKavaModule_EvmParams() {
|
||||
// ACT
|
||||
rsp, err := suite.Kava.Grpc.Query.Evmutil.Params(
|
||||
rsp, err := suite.ZgChain.Grpc.Query.Evmutil.Params(
|
||||
context.Background(), &evmutiltypes.QueryParamsRequest{},
|
||||
)
|
||||
|
||||
|
@ -1,20 +1,22 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func (suite *IntegrationTestSuite) TestGrpcClientUtil_Account() {
|
||||
// ARRANGE
|
||||
// setup kava account
|
||||
kavaAcc := suite.Kava.NewFundedAccount("account-test", sdk.NewCoins(ukava(1e5)))
|
||||
// setup 0g account
|
||||
zgAcc := suite.ZgChain.NewFundedAccount("account-test", sdk.NewCoins(a0gi(big.NewInt(1e5))))
|
||||
|
||||
// ACT
|
||||
rsp, err := suite.Kava.Grpc.BaseAccount(kavaAcc.SdkAddress.String())
|
||||
rsp, err := suite.ZgChain.Grpc.BaseAccount(zgAcc.SdkAddress.String())
|
||||
|
||||
// ASSERT
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(kavaAcc.SdkAddress.String(), rsp.Address)
|
||||
suite.Equal(zgAcc.SdkAddress.String(), rsp.Address)
|
||||
suite.Greater(rsp.AccountNumber, uint64(1))
|
||||
suite.Equal(uint64(0), rsp.Sequence)
|
||||
}
|
||||
|
@ -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"
|
||||
)
|
||||
|
||||
@ -20,14 +21,14 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
|
||||
suite.SkipIfKvtoolDisabled()
|
||||
|
||||
// read expected min fee from app.toml
|
||||
minGasPrices, err := getMinFeeFromAppToml(util.KavaHomePath())
|
||||
minGasPrices, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||
suite.NoError(err)
|
||||
|
||||
// evm uses akava, get akava min fee
|
||||
evmMinGas := minGasPrices.AmountOf("akava").TruncateInt().BigInt()
|
||||
// evm uses neuron, get neuron min fee
|
||||
evmMinGas := minGasPrices.AmountOf(chaincfg.BaseDenom).TruncateInt().BigInt()
|
||||
|
||||
// returns eth_gasPrice, units in kava
|
||||
gasPrice, err := suite.Kava.EvmClient.SuggestGasPrice(context.Background())
|
||||
// returns eth_gasPrice, units in a0gi
|
||||
gasPrice, err := suite.ZgChain.EvmClient.SuggestGasPrice(context.Background())
|
||||
suite.NoError(err)
|
||||
|
||||
suite.Equal(evmMinGas, gasPrice)
|
||||
@ -37,13 +38,13 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
||||
suite.SkipIfKvtoolDisabled()
|
||||
|
||||
// setup sender & receiver
|
||||
sender := suite.Kava.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(ukava(1e3)))
|
||||
sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(a0gi(big.NewInt(1e3))))
|
||||
randoReceiver := util.SdkToEvmAddress(app.RandomAddress())
|
||||
|
||||
// get min gas price for evm (from app.toml)
|
||||
minFees, err := getMinFeeFromAppToml(util.KavaHomePath())
|
||||
minFees, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||
suite.NoError(err)
|
||||
minGasPrice := minFees.AmountOf("akava").TruncateInt()
|
||||
minGasPrice := minFees.AmountOf(chaincfg.BaseDenom).TruncateInt()
|
||||
|
||||
// attempt tx with less than min gas price (min fee - 1)
|
||||
tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt()
|
||||
@ -58,12 +59,12 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
||||
suite.ErrorContains(res.Err, "insufficient fee")
|
||||
}
|
||||
|
||||
func getMinFeeFromAppToml(kavaHome string) (sdk.DecCoins, error) {
|
||||
func getMinFeeFromAppToml(zgChainHome string) (sdk.DecCoins, error) {
|
||||
// read the expected min gas price from app.toml
|
||||
parsed := struct {
|
||||
MinGasPrices string `toml:"minimum-gas-prices"`
|
||||
}{}
|
||||
appToml, err := os.ReadFile(filepath.Join(kavaHome, "config", "app.toml"))
|
||||
appToml, err := os.ReadFile(filepath.Join(zgChainHome, "config", "app.toml"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -19,16 +19,17 @@ 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) // akava
|
||||
minEvmGasPrice = big.NewInt(1e10) // neuron
|
||||
)
|
||||
|
||||
func ukava(amt int64) sdk.Coin {
|
||||
return sdk.NewCoin("ukava", sdkmath.NewInt(amt))
|
||||
func a0gi(amt *big.Int) sdk.Coin {
|
||||
return sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewIntFromBigInt(amt))
|
||||
}
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
@ -39,63 +40,63 @@ func TestIntegrationTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
||||
|
||||
// example test that queries kava via SDK and EVM
|
||||
// example test that queries 0gchain via SDK and EVM
|
||||
func (suite *IntegrationTestSuite) TestChainID() {
|
||||
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.Kava.ChainID)
|
||||
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.ZgChain.ChainID)
|
||||
suite.NoError(err)
|
||||
|
||||
// EVM query
|
||||
evmNetworkId, err := suite.Kava.EvmClient.NetworkID(context.Background())
|
||||
evmNetworkId, err := suite.ZgChain.EvmClient.NetworkID(context.Background())
|
||||
suite.NoError(err)
|
||||
suite.Equal(expectedEvmNetworkId, evmNetworkId)
|
||||
|
||||
// SDK query
|
||||
nodeInfo, err := suite.Kava.Grpc.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||
nodeInfo, err := suite.ZgChain.Grpc.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||
suite.NoError(err)
|
||||
suite.Equal(suite.Kava.ChainID, nodeInfo.DefaultNodeInfo.Network)
|
||||
suite.Equal(suite.ZgChain.ChainID, nodeInfo.DefaultNodeInfo.Network)
|
||||
}
|
||||
|
||||
// example test that funds a new account & queries its balance
|
||||
func (suite *IntegrationTestSuite) TestFundedAccount() {
|
||||
funds := ukava(1e3)
|
||||
acc := suite.Kava.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
||||
funds := a0gi(big.NewInt(1e3))
|
||||
acc := suite.ZgChain.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
||||
|
||||
// check that the sdk & evm signers are for the same account
|
||||
suite.Equal(acc.SdkAddress.String(), util.EvmToSdkAddress(acc.EvmAddress).String())
|
||||
suite.Equal(acc.EvmAddress.Hex(), util.SdkToEvmAddress(acc.SdkAddress).Hex())
|
||||
|
||||
// check balance via SDK query
|
||||
res, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
||||
acc.SdkAddress, "ukava",
|
||||
res, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
||||
acc.SdkAddress, chaincfg.DisplayDenom,
|
||||
))
|
||||
suite.NoError(err)
|
||||
suite.Equal(funds, *res.Balance)
|
||||
|
||||
// check balance via EVM query
|
||||
akavaBal, err := suite.Kava.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
|
||||
neuronBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
|
||||
suite.NoError(err)
|
||||
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), akavaBal)
|
||||
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), neuronBal)
|
||||
}
|
||||
|
||||
// example test that signs & broadcasts an EVM tx
|
||||
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||
// fund an account that can perform the transfer
|
||||
initialFunds := ukava(1e6) // 1 KAVA
|
||||
acc := suite.Kava.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
|
||||
initialFunds := a0gi(big.NewInt(1e6)) // 1 A0GI
|
||||
acc := suite.ZgChain.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
|
||||
|
||||
// get a rando account to send kava to
|
||||
// get a rando account to send 0gchain to
|
||||
randomAddr := app.RandomAddress()
|
||||
to := util.SdkToEvmAddress(randomAddr)
|
||||
|
||||
// example fetching of nonce (account sequence)
|
||||
nonce, err := suite.Kava.EvmClient.PendingNonceAt(context.Background(), acc.EvmAddress)
|
||||
nonce, err := suite.ZgChain.EvmClient.PendingNonceAt(context.Background(), acc.EvmAddress)
|
||||
suite.NoError(err)
|
||||
suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs
|
||||
|
||||
// transfer kava over EVM
|
||||
kavaToTransfer := big.NewInt(1e17) // .1 KAVA; akava has 18 decimals.
|
||||
// transfer a0gi over EVM
|
||||
a0giToTransfer := big.NewInt(1e17) // .1 A0GI; neuron has 18 decimals.
|
||||
req := util.EvmTxRequest{
|
||||
Tx: ethtypes.NewTransaction(nonce, to, kavaToTransfer, 1e5, minEvmGasPrice, nil),
|
||||
Tx: ethtypes.NewTransaction(nonce, to, a0giToTransfer, 1e5, minEvmGasPrice, nil),
|
||||
Data: "any ol' data to track this through the system",
|
||||
}
|
||||
res := acc.SignAndBroadcastEvmTx(req)
|
||||
@ -103,36 +104,36 @@ 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.
|
||||
ukavaUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
|
||||
a0giUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
|
||||
Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)).
|
||||
QuoRaw(1e12) // convert akava to ukava
|
||||
QuoRaw(1e12) // convert neuron to a0gi
|
||||
|
||||
// expect (9 - gas used) KAVA remaining in account.
|
||||
balance := suite.Kava.QuerySdkForBalances(acc.SdkAddress)
|
||||
suite.Equal(sdkmath.NewInt(9e5).Sub(ukavaUsedForGas), balance.AmountOf("ukava"))
|
||||
// expect (9 - gas used) A0GI remaining in account.
|
||||
balance := suite.ZgChain.QuerySdkForBalances(acc.SdkAddress)
|
||||
suite.Equal(sdkmath.NewInt(9e5).Sub(a0giUsedForGas), balance.AmountOf(chaincfg.DisplayDenom))
|
||||
}
|
||||
|
||||
// TestIbcTransfer transfers KAVA from the primary kava chain (suite.Kava) to the ibc chain (suite.Ibc).
|
||||
// Note that because the IBC chain also runs kava's binary, this tests both the sending & receiving.
|
||||
// TestIbcTransfer transfers A0GI 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 kava account
|
||||
funds := ukava(1e5) // .1 KAVA
|
||||
kavaAcc := suite.Kava.NewFundedAccount("ibc-transfer-kava-side", sdk.NewCoins(funds))
|
||||
// setup 0g-chain account
|
||||
funds := a0gi(big.NewInt(1e5)) // .1 A0GI
|
||||
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 := ukava(200)
|
||||
fee := a0gi(big.NewInt(200))
|
||||
|
||||
fundsToSend := ukava(5e4) // .005 KAVA
|
||||
fundsToSend := a0gi(big.NewInt(5e4)) // .005 A0GI
|
||||
transferMsg := ibctypes.NewMsgTransfer(
|
||||
testutil.IbcPort,
|
||||
testutil.IbcChannel,
|
||||
fundsToSend,
|
||||
kavaAcc.SdkAddress.String(),
|
||||
zgChainAcc.SdkAddress.String(),
|
||||
ibcAcc.SdkAddress.String(),
|
||||
ibcclienttypes.NewHeight(0, 0), // timeout height disabled when 0
|
||||
uint64(time.Now().Add(30*time.Second).UnixNano()),
|
||||
@ -142,22 +143,22 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
||||
expectedSrcBalance := funds.Sub(fundsToSend).Sub(fee)
|
||||
|
||||
// ACT
|
||||
// IBC transfer from kava -> ibc
|
||||
transferTo := util.KavaMsgRequest{
|
||||
// IBC transfer from 0g-chain -> ibc
|
||||
transferTo := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{transferMsg},
|
||||
GasLimit: uint64(gasLimit),
|
||||
FeeAmount: sdk.NewCoins(fee),
|
||||
Memo: "sent from Kava!",
|
||||
Memo: "sent from ZgChain!",
|
||||
}
|
||||
res := kavaAcc.SignAndBroadcastKavaTx(transferTo)
|
||||
res := zgChainAcc.SignAndBroadcastZgChainTx(transferTo)
|
||||
|
||||
// ASSERT
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// the balance should be deducted from kava account
|
||||
// the balance should be deducted from 0g-chain account
|
||||
suite.Eventually(func() bool {
|
||||
balance := suite.Kava.QuerySdkForBalances(kavaAcc.SdkAddress)
|
||||
return balance.AmountOf("ukava").Equal(expectedSrcBalance.Amount)
|
||||
balance := suite.ZgChain.QuerySdkForBalances(zgChainAcc.SdkAddress)
|
||||
return balance.AmountOf(chaincfg.DisplayDenom).Equal(expectedSrcBalance.Amount)
|
||||
}, 10*time.Second, 1*time.Second)
|
||||
|
||||
// expect the balance to be transferred to the ibc chain!
|
||||
|
@ -3,6 +3,7 @@ package e2e_test
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
tmtypes "github.com/cometbft/cometbft/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -13,11 +14,11 @@ import (
|
||||
func (suite *IntegrationTestSuite) TestUpgradeParams_SDK() {
|
||||
suite.SkipIfUpgradeDisabled()
|
||||
|
||||
beforeUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
|
||||
afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||
beforeUpgradeCtx := suite.ZgChain.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
|
||||
afterUpgradeCtx := suite.ZgChain.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||
|
||||
// Before params
|
||||
grpcClient := suite.Kava.Grpc
|
||||
grpcClient := suite.ZgChain.Grpc
|
||||
govParamsBefore, err := grpcClient.Query.Gov.Params(beforeUpgradeCtx, &govtypes.QueryParamsRequest{
|
||||
ParamsType: govtypes.ParamDeposit,
|
||||
})
|
||||
@ -47,13 +48,13 @@ func (suite *IntegrationTestSuite) TestUpgradeParams_SDK() {
|
||||
"x/gov DepositParams max deposit period after upgrade should be 172800s",
|
||||
)
|
||||
suite.Assert().Equal(
|
||||
[]sdk.Coin{{Denom: "ukava", Amount: sdk.NewInt(10_000_000)}},
|
||||
[]sdk.Coin{{Denom: chaincfg.DisplayDenom, Amount: sdk.NewInt(10_000_000)}},
|
||||
govParamsAfter.DepositParams.MinDeposit,
|
||||
"x/gov DepositParams min deposit after upgrade should be 10_000_000 ukava",
|
||||
)
|
||||
|
||||
expectedParams := govtypes.Params{
|
||||
MinDeposit: sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(10_000_000))),
|
||||
MinDeposit: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdk.NewInt(10_000_000))),
|
||||
MaxDepositPeriod: mustParseDuration("172800s"),
|
||||
VotingPeriod: mustParseDuration("30s"),
|
||||
Quorum: "0.334000000000000000",
|
||||
@ -71,9 +72,9 @@ func (suite *IntegrationTestSuite) TestUpgradeParams_SDK() {
|
||||
func (suite *IntegrationTestSuite) TestUpgradeParams_Consensus() {
|
||||
suite.SkipIfUpgradeDisabled()
|
||||
|
||||
afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||
afterUpgradeCtx := suite.ZgChain.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||
|
||||
grpcClient := suite.Kava.Grpc
|
||||
grpcClient := suite.ZgChain.Grpc
|
||||
paramsAfter, err := grpcClient.Query.Consensus.Params(afterUpgradeCtx, &consensustypes.QueryParamsRequest{})
|
||||
suite.NoError(err)
|
||||
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
rpchttpclient "github.com/cometbft/cometbft/rpc/client/http"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
)
|
||||
@ -67,20 +69,20 @@ func (c *Chains) Register(name string, chain *ChainDetails) error {
|
||||
// the Chain details are all hardcoded because they are currently fixed by kvtool.
|
||||
// someday they may be accepted as configurable parameters.
|
||||
var (
|
||||
kvtoolKavaChain = ChainDetails{
|
||||
kvtoolZgChainChain = ChainDetails{
|
||||
RpcUrl: "http://localhost:26657",
|
||||
GrpcUrl: "http://localhost:9090",
|
||||
EvmRpcUrl: "http://localhost:8545",
|
||||
|
||||
ChainId: "kavalocalnet_8888-1",
|
||||
StakingDenom: "ukava",
|
||||
ChainId: "0gchainlocalnet_8888-1",
|
||||
StakingDenom: chaincfg.DisplayDenom,
|
||||
}
|
||||
kvtoolIbcChain = ChainDetails{
|
||||
RpcUrl: "http://localhost:26658",
|
||||
GrpcUrl: "http://localhost:9092",
|
||||
EvmRpcUrl: "http://localhost:8547",
|
||||
|
||||
ChainId: "kavalocalnet_8889-2",
|
||||
ChainId: "0gchainlocalnet_8889-2",
|
||||
StakingDenom: "uatom",
|
||||
}
|
||||
)
|
||||
|
@ -8,24 +8,24 @@ import (
|
||||
)
|
||||
|
||||
type KvtoolRunnerConfig struct {
|
||||
KavaConfigTemplate string
|
||||
ZgChainConfigTemplate string
|
||||
|
||||
ImageTag string
|
||||
IncludeIBC bool
|
||||
|
||||
EnableAutomatedUpgrade bool
|
||||
KavaUpgradeName string
|
||||
KavaUpgradeHeight int64
|
||||
KavaUpgradeBaseImageTag string
|
||||
EnableAutomatedUpgrade bool
|
||||
ZgChainUpgradeName string
|
||||
ZgChainUpgradeHeight int64
|
||||
ZgChainUpgradeBaseImageTag string
|
||||
|
||||
SkipShutdown bool
|
||||
}
|
||||
|
||||
// KvtoolRunner implements a NodeRunner that spins up local chains with kvtool.
|
||||
// It has support for the following:
|
||||
// - running a Kava node
|
||||
// - optionally, running an IBC node with a channel opened to the Kava node
|
||||
// - optionally, start the Kava node on one version and upgrade to another
|
||||
// - running a ZgChain node
|
||||
// - optionally, running an IBC node with a channel opened to the ZgChain node
|
||||
// - optionally, start the ZgChain node on one version and upgrade to another
|
||||
type KvtoolRunner struct {
|
||||
config KvtoolRunnerConfig
|
||||
}
|
||||
@ -51,8 +51,8 @@ func (k *KvtoolRunner) StartChains() Chains {
|
||||
}
|
||||
|
||||
// start local test network with kvtool
|
||||
log.Println("starting kava node")
|
||||
kvtoolArgs := []string{"testnet", "bootstrap", "--kava.configTemplate", k.config.KavaConfigTemplate}
|
||||
log.Println("starting 0gchain node")
|
||||
kvtoolArgs := []string{"testnet", "bootstrap", "--0gchain.configTemplate", k.config.ZgChainConfigTemplate}
|
||||
// include an ibc chain if desired
|
||||
if k.config.IncludeIBC {
|
||||
kvtoolArgs = append(kvtoolArgs, "--ibc")
|
||||
@ -60,32 +60,32 @@ func (k *KvtoolRunner) StartChains() Chains {
|
||||
// handle automated upgrade functionality, if defined
|
||||
if k.config.EnableAutomatedUpgrade {
|
||||
kvtoolArgs = append(kvtoolArgs,
|
||||
"--upgrade-name", k.config.KavaUpgradeName,
|
||||
"--upgrade-height", fmt.Sprint(k.config.KavaUpgradeHeight),
|
||||
"--upgrade-base-image-tag", k.config.KavaUpgradeBaseImageTag,
|
||||
"--upgrade-name", k.config.ZgChainUpgradeName,
|
||||
"--upgrade-height", fmt.Sprint(k.config.ZgChainUpgradeHeight),
|
||||
"--upgrade-base-image-tag", k.config.ZgChainUpgradeBaseImageTag,
|
||||
)
|
||||
}
|
||||
// start the chain
|
||||
startKavaCmd := exec.Command("kvtool", kvtoolArgs...)
|
||||
startKavaCmd.Env = os.Environ()
|
||||
startKavaCmd.Env = append(startKavaCmd.Env, fmt.Sprintf("KAVA_TAG=%s", k.config.ImageTag))
|
||||
startKavaCmd.Stdout = os.Stdout
|
||||
startKavaCmd.Stderr = os.Stderr
|
||||
log.Println(startKavaCmd.String())
|
||||
if err := startKavaCmd.Run(); err != nil {
|
||||
panic(fmt.Sprintf("failed to start kava: %s", err.Error()))
|
||||
startZgChainCmd := exec.Command("kvtool", kvtoolArgs...)
|
||||
startZgChainCmd.Env = os.Environ()
|
||||
startZgChainCmd.Env = append(startZgChainCmd.Env, fmt.Sprintf("0GCHAIN_TAG=%s", k.config.ImageTag))
|
||||
startZgChainCmd.Stdout = os.Stdout
|
||||
startZgChainCmd.Stderr = os.Stderr
|
||||
log.Println(startZgChainCmd.String())
|
||||
if err := startZgChainCmd.Run(); err != nil {
|
||||
panic(fmt.Sprintf("failed to start 0gchain: %s", err.Error()))
|
||||
}
|
||||
|
||||
// wait for chain to be live.
|
||||
// if an upgrade is defined, this waits for the upgrade to be completed.
|
||||
if err := waitForChainStart(kvtoolKavaChain); err != nil {
|
||||
if err := waitForChainStart(kvtoolZgChainChain); err != nil {
|
||||
k.Shutdown()
|
||||
panic(err)
|
||||
}
|
||||
log.Println("kava is started!")
|
||||
log.Println("0gchain is started!")
|
||||
|
||||
chains := NewChains()
|
||||
chains.Register("kava", &kvtoolKavaChain)
|
||||
chains.Register("0gchain", &kvtoolZgChainChain)
|
||||
if k.config.IncludeIBC {
|
||||
chains.Register("ibc", &kvtoolIbcChain)
|
||||
}
|
||||
@ -101,11 +101,11 @@ func (k *KvtoolRunner) Shutdown() {
|
||||
log.Printf("would shut down but SkipShutdown is true")
|
||||
return
|
||||
}
|
||||
log.Println("shutting down kava node")
|
||||
shutdownKavaCmd := exec.Command("kvtool", "testnet", "down")
|
||||
shutdownKavaCmd.Stdout = os.Stdout
|
||||
shutdownKavaCmd.Stderr = os.Stderr
|
||||
if err := shutdownKavaCmd.Run(); err != nil {
|
||||
log.Println("shutting down 0gchain node")
|
||||
shutdownZgChainCmd := exec.Command("kvtool", "testnet", "down")
|
||||
shutdownZgChainCmd.Stdout = os.Stdout
|
||||
shutdownZgChainCmd.Stderr = os.Stderr
|
||||
if err := shutdownZgChainCmd.Run(); err != nil {
|
||||
panic(fmt.Sprintf("failed to shutdown kvtool: %s", err.Error()))
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,17 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/0glabs/0g-chain/client/grpc"
|
||||
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/client/grpc"
|
||||
)
|
||||
|
||||
// LiveNodeRunnerConfig implements NodeRunner.
|
||||
// It connects to a running network via the RPC, GRPC, and EVM urls.
|
||||
type LiveNodeRunnerConfig struct {
|
||||
KavaRpcUrl string
|
||||
KavaGrpcUrl string
|
||||
KavaEvmRpcUrl string
|
||||
ZgChainRpcUrl string
|
||||
ZgChainGrpcUrl string
|
||||
ZgChainEvmRpcUrl string
|
||||
|
||||
UpgradeHeight int64
|
||||
}
|
||||
@ -37,41 +36,41 @@ func NewLiveNodeRunner(config LiveNodeRunnerConfig) *LiveNodeRunner {
|
||||
// It initializes connections to the chain based on parameters.
|
||||
// It attempts to ping the necessary endpoints and panics if they cannot be reached.
|
||||
func (r LiveNodeRunner) StartChains() Chains {
|
||||
fmt.Println("establishing connection to live kava network")
|
||||
fmt.Println("establishing connection to live 0g-chain network")
|
||||
chains := NewChains()
|
||||
|
||||
kavaChain := ChainDetails{
|
||||
RpcUrl: r.config.KavaRpcUrl,
|
||||
GrpcUrl: r.config.KavaGrpcUrl,
|
||||
EvmRpcUrl: r.config.KavaEvmRpcUrl,
|
||||
zgChain := ChainDetails{
|
||||
RpcUrl: r.config.ZgChainRpcUrl,
|
||||
GrpcUrl: r.config.ZgChainGrpcUrl,
|
||||
EvmRpcUrl: r.config.ZgChainEvmRpcUrl,
|
||||
}
|
||||
|
||||
if err := waitForChainStart(kavaChain); err != nil {
|
||||
if err := waitForChainStart(zgChain); err != nil {
|
||||
panic(fmt.Sprintf("failed to ping chain: %s", err))
|
||||
}
|
||||
|
||||
// determine chain id
|
||||
client, err := grpc.NewClient(kavaChain.GrpcUrl)
|
||||
client, err := grpc.NewClient(zgChain.GrpcUrl)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create kava grpc client: %s", err))
|
||||
panic(fmt.Sprintf("failed to create 0g-chain grpc client: %s", err))
|
||||
}
|
||||
|
||||
nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to fetch kava node info: %s", err))
|
||||
panic(fmt.Sprintf("failed to fetch 0g-chain node info: %s", err))
|
||||
}
|
||||
kavaChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
||||
zgChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
||||
|
||||
// determine staking denom
|
||||
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to fetch kava staking params: %s", err))
|
||||
panic(fmt.Sprintf("failed to fetch 0g-chain staking params: %s", err))
|
||||
}
|
||||
kavaChain.StakingDenom = stakingParams.Params.BondDenom
|
||||
zgChain.StakingDenom = stakingParams.Params.BondDenom
|
||||
|
||||
chains.Register("kava", &kavaChain)
|
||||
chains.Register("0gchain", &zgChain)
|
||||
|
||||
fmt.Printf("successfully connected to live network %+v\n", kavaChain)
|
||||
fmt.Printf("successfully connected to live network %+v\n", zgChain)
|
||||
|
||||
return chains
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func waitForChainStart(chainDetails ChainDetails) error {
|
||||
b := backoff.NewExponentialBackOff()
|
||||
b.MaxInterval = 5 * time.Second
|
||||
b.MaxElapsedTime = 30 * time.Second
|
||||
if err := backoff.Retry(func() error { return pingKava(chainDetails.RpcUrl) }, b); err != nil {
|
||||
if err := backoff.Retry(func() error { return pingZgChain(chainDetails.RpcUrl) }, b); err != nil {
|
||||
return fmt.Errorf("failed connect to chain: %s", err)
|
||||
}
|
||||
|
||||
@ -34,9 +34,9 @@ func waitForChainStart(chainDetails ChainDetails) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func pingKava(rpcUrl string) error {
|
||||
func pingZgChain(rpcUrl string) error {
|
||||
statusUrl := fmt.Sprintf("%s/status", rpcUrl)
|
||||
log.Printf("pinging kava chain: %s\n", statusUrl)
|
||||
log.Printf("pinging 0g-chain: %s\n", statusUrl)
|
||||
res, err := http.Get(statusUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -45,7 +45,7 @@ func pingKava(rpcUrl string) error {
|
||||
if res.StatusCode >= 400 {
|
||||
return fmt.Errorf("ping to status failed: %d", res.StatusCode)
|
||||
}
|
||||
log.Println("successfully started Kava!")
|
||||
log.Println("successfully started ZgChain!")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
emtests "github.com/evmos/ethermint/tests"
|
||||
emtypes "github.com/evmos/ethermint/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
|
||||
@ -43,9 +43,9 @@ type SigningAccount struct {
|
||||
evmReqChan chan<- util.EvmTxRequest
|
||||
evmResChan <-chan util.EvmTxResponse
|
||||
|
||||
kavaSigner *util.KavaSigner
|
||||
sdkReqChan chan<- util.KavaMsgRequest
|
||||
sdkResChan <-chan util.KavaMsgResponse
|
||||
zgChainSigner *util.ZgChainSigner
|
||||
sdkReqChan chan<- util.ZgChainMsgRequest
|
||||
sdkResChan <-chan util.ZgChainMsgResponse
|
||||
|
||||
EvmAuth *bind.TransactOpts
|
||||
|
||||
@ -72,7 +72,7 @@ func (chain *Chain) AddNewSigningAccount(name string, hdPath *hd.BIP44Params, ch
|
||||
chain.t.Fatalf("account with name %s already exists", name)
|
||||
}
|
||||
|
||||
// Kava signing account for SDK side
|
||||
// 0gChain signing account for SDK side
|
||||
privKeyBytes, err := hd.Secp256k1.Derive()(mnemonic, "", hdPath.String())
|
||||
require.NoErrorf(chain.t, err, "failed to derive private key from mnemonic for %s: %s", name, err)
|
||||
privKey := ðsecp256k1.PrivKey{Key: privKeyBytes}
|
||||
@ -97,8 +97,8 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
||||
chain.t.Fatalf("account with name %s already exists", name)
|
||||
}
|
||||
|
||||
// Kava signing account for SDK side
|
||||
kavaSigner := util.NewKavaSigner(
|
||||
// 0gChain signing account for SDK side
|
||||
zgChainSigner := util.NewZgChainSigner(
|
||||
chainId,
|
||||
chain.EncodingConfig,
|
||||
chain.Grpc.Query.Auth,
|
||||
@ -107,11 +107,11 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
||||
100,
|
||||
)
|
||||
|
||||
sdkReqChan := make(chan util.KavaMsgRequest)
|
||||
sdkResChan, err := kavaSigner.Run(sdkReqChan)
|
||||
sdkReqChan := make(chan util.ZgChainMsgRequest)
|
||||
sdkResChan, err := zgChainSigner.Run(sdkReqChan)
|
||||
require.NoErrorf(chain.t, err, "failed to start signer for account %s: %s", name, err)
|
||||
|
||||
// Kava signing account for EVM side
|
||||
// 0gChain signing account for EVM side
|
||||
evmChainId, err := emtypes.ParseChainID(chainId)
|
||||
require.NoErrorf(chain.t, err, "unable to parse ethermint-compatible chain id from %s", chainId)
|
||||
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes()))
|
||||
@ -141,21 +141,21 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
||||
evmReqChan: evmReqChan,
|
||||
evmResChan: evmResChan,
|
||||
|
||||
kavaSigner: kavaSigner,
|
||||
sdkReqChan: sdkReqChan,
|
||||
sdkResChan: sdkResChan,
|
||||
zgChainSigner: zgChainSigner,
|
||||
sdkReqChan: sdkReqChan,
|
||||
sdkResChan: sdkResChan,
|
||||
|
||||
EvmAuth: evmSigner.Auth,
|
||||
|
||||
EvmAddress: evmSigner.Address(),
|
||||
SdkAddress: kavaSigner.Address(),
|
||||
SdkAddress: zgChainSigner.Address(),
|
||||
}
|
||||
|
||||
return chain.accounts[name]
|
||||
}
|
||||
|
||||
// SignAndBroadcastKavaTx sends a request to the signer and awaits its response.
|
||||
func (a *SigningAccount) SignAndBroadcastKavaTx(req util.KavaMsgRequest) util.KavaMsgResponse {
|
||||
// SignAndBroadcastZgChainTx sends a request to the signer and awaits its response.
|
||||
func (a *SigningAccount) SignAndBroadcastZgChainTx(req util.ZgChainMsgRequest) util.ZgChainMsgResponse {
|
||||
a.l.Printf("broadcasting sdk tx. has data = %+v\n", req.Data)
|
||||
// send the request to signer
|
||||
a.sdkReqChan <- req
|
||||
@ -222,7 +222,7 @@ func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccou
|
||||
|
||||
acc := chain.AddNewSigningAccount(
|
||||
name,
|
||||
hd.CreateHDPath(app.Bip44CoinType, 0, 0),
|
||||
hd.CreateHDPath(chaincfg.Bip44CoinType, 0, 0),
|
||||
chain.ChainID,
|
||||
mnemonic,
|
||||
)
|
||||
@ -257,12 +257,12 @@ func (a *SigningAccount) NextNonce() (uint64, error) {
|
||||
}
|
||||
|
||||
// BankSend is a helper method for sending funds via x/bank's MsgSend
|
||||
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.KavaMsgResponse {
|
||||
return a.SignAndBroadcastKavaTx(
|
||||
util.KavaMsgRequest{
|
||||
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.ZgChainMsgResponse {
|
||||
return a.SignAndBroadcastZgChainTx(
|
||||
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 .001ukava
|
||||
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001a0gi
|
||||
Data: fmt.Sprintf("sending %s to %s", amount, to),
|
||||
},
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
kavaparams "github.com/0glabs/0g-chain/app/params"
|
||||
chainparams "github.com/0glabs/0g-chain/app/params"
|
||||
"github.com/0glabs/0g-chain/client/grpc"
|
||||
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
@ -41,11 +41,11 @@ type Chain struct {
|
||||
ContractAddrs map[string]common.Address
|
||||
erc20s map[common.Address]struct{}
|
||||
|
||||
EncodingConfig kavaparams.EncodingConfig
|
||||
EncodingConfig chainparams.EncodingConfig
|
||||
|
||||
TmSignClient tmclient.SignClient
|
||||
|
||||
Grpc *grpc.KavaGrpcClient
|
||||
Grpc *grpc.ZgChainGrpcClient
|
||||
}
|
||||
|
||||
// NewChain creates the query clients & signing account management for a chain run on a set of ports.
|
||||
@ -65,7 +65,7 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
||||
kr, err := keyring.New(
|
||||
sdk.KeyringServiceName(),
|
||||
keyring.BackendTest,
|
||||
util.KavaHomePath(),
|
||||
util.ZgChainHomePath(),
|
||||
nil,
|
||||
chain.EncodingConfig.Marshaler,
|
||||
evmhd.EthSecp256k1Option(),
|
||||
@ -77,7 +77,7 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
||||
|
||||
client, err := grpc.NewClient(details.GrpcUrl)
|
||||
if err != nil {
|
||||
chain.t.Fatalf("failed to create kava grpc client: %s", err)
|
||||
chain.t.Fatalf("failed to create 0g-chain grpc client: %s", err)
|
||||
}
|
||||
chain.Grpc = client
|
||||
|
||||
|
@ -27,7 +27,7 @@ type SuiteConfig struct {
|
||||
IncludeIbcTests bool
|
||||
|
||||
// The contract address of a deployed ERC-20 token
|
||||
KavaErc20Address string
|
||||
ZgChainErc20Address string
|
||||
|
||||
// When true, the chains will remain running after tests complete (pass or fail)
|
||||
SkipShutdown bool
|
||||
@ -36,26 +36,26 @@ type SuiteConfig struct {
|
||||
// KvtoolConfig wraps configuration options for running the end-to-end test suite against
|
||||
// a locally running chain. This config must be defined if E2E_RUN_KVTOOL_NETWORKS is true.
|
||||
type KvtoolConfig struct {
|
||||
// The kava.configTemplate flag to be passed to kvtool, usually "master".
|
||||
// The 0gchain.configTemplate flag to be passed to kvtool, usually "master".
|
||||
// This allows one to change the base genesis used to start the chain.
|
||||
KavaConfigTemplate string
|
||||
ZgChainConfigTemplate string
|
||||
|
||||
// Whether or not to run a chain upgrade & run post-upgrade tests. Use `suite.SkipIfUpgradeDisabled()` in post-upgrade tests.
|
||||
IncludeAutomatedUpgrade bool
|
||||
// Name of the upgrade, if upgrade is enabled.
|
||||
KavaUpgradeName string
|
||||
ZgChainUpgradeName string
|
||||
// Height upgrade will be applied to the test chain, if upgrade is enabled.
|
||||
KavaUpgradeHeight int64
|
||||
// Tag of kava docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
|
||||
KavaUpgradeBaseImageTag string
|
||||
ZgChainUpgradeHeight int64
|
||||
// Tag of 0gchain docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
|
||||
ZgChainUpgradeBaseImageTag string
|
||||
}
|
||||
|
||||
// LiveNetworkConfig wraps configuration options for running the end-to-end test suite
|
||||
// against a live network. It must be defined if E2E_RUN_KVTOOL_NETWORKS is false.
|
||||
type LiveNetworkConfig struct {
|
||||
KavaRpcUrl string
|
||||
KavaGrpcUrl string
|
||||
KavaEvmRpcUrl string
|
||||
ZgChainRpcUrl string
|
||||
ZgChainGrpcUrl string
|
||||
ZgChainEvmRpcUrl string
|
||||
|
||||
UpgradeHeight int64
|
||||
}
|
||||
@ -65,8 +65,8 @@ func ParseSuiteConfig() SuiteConfig {
|
||||
config := SuiteConfig{
|
||||
// this mnemonic is expected to be a funded account that can seed the funds for all
|
||||
// new accounts created during tests. it will be available under Accounts["whale"]
|
||||
FundedAccountMnemonic: nonemptyStringEnv("E2E_KAVA_FUNDED_ACCOUNT_MNEMONIC"),
|
||||
KavaErc20Address: nonemptyStringEnv("E2E_KAVA_ERC20_ADDRESS"),
|
||||
FundedAccountMnemonic: nonemptyStringEnv("E2E_0GCHAIN_FUNDED_ACCOUNT_MNEMONIC"),
|
||||
ZgChainErc20Address: nonemptyStringEnv("E2E_0GCHAIN_ERC20_ADDRESS"),
|
||||
IncludeIbcTests: mustParseBool("E2E_INCLUDE_IBC_TESTS"),
|
||||
}
|
||||
|
||||
@ -90,18 +90,18 @@ func ParseSuiteConfig() SuiteConfig {
|
||||
// ParseKvtoolConfig builds a KvtoolConfig from environment variables.
|
||||
func ParseKvtoolConfig() KvtoolConfig {
|
||||
config := KvtoolConfig{
|
||||
KavaConfigTemplate: nonemptyStringEnv("E2E_KVTOOL_KAVA_CONFIG_TEMPLATE"),
|
||||
ZgChainConfigTemplate: nonemptyStringEnv("E2E_KVTOOL_0GCHAIN_CONFIG_TEMPLATE"),
|
||||
IncludeAutomatedUpgrade: mustParseBool("E2E_INCLUDE_AUTOMATED_UPGRADE"),
|
||||
}
|
||||
|
||||
if config.IncludeAutomatedUpgrade {
|
||||
config.KavaUpgradeName = nonemptyStringEnv("E2E_KAVA_UPGRADE_NAME")
|
||||
config.KavaUpgradeBaseImageTag = nonemptyStringEnv("E2E_KAVA_UPGRADE_BASE_IMAGE_TAG")
|
||||
upgradeHeight, err := strconv.ParseInt(nonemptyStringEnv("E2E_KAVA_UPGRADE_HEIGHT"), 10, 64)
|
||||
config.ZgChainUpgradeName = nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_NAME")
|
||||
config.ZgChainUpgradeBaseImageTag = nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_BASE_IMAGE_TAG")
|
||||
upgradeHeight, err := strconv.ParseInt(nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_HEIGHT"), 10, 64)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("E2E_KAVA_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
panic(fmt.Sprintf("E2E_0GCHAIN_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
}
|
||||
config.KavaUpgradeHeight = upgradeHeight
|
||||
config.ZgChainUpgradeHeight = upgradeHeight
|
||||
}
|
||||
|
||||
return config
|
||||
@ -110,16 +110,16 @@ func ParseKvtoolConfig() KvtoolConfig {
|
||||
// ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.
|
||||
func ParseLiveNetworkConfig() LiveNetworkConfig {
|
||||
config := LiveNetworkConfig{
|
||||
KavaRpcUrl: nonemptyStringEnv("E2E_KAVA_RPC_URL"),
|
||||
KavaGrpcUrl: nonemptyStringEnv("E2E_KAVA_GRPC_URL"),
|
||||
KavaEvmRpcUrl: nonemptyStringEnv("E2E_KAVA_EVM_RPC_URL"),
|
||||
ZgChainRpcUrl: nonemptyStringEnv("E2E_0GCHAIN_RPC_URL"),
|
||||
ZgChainGrpcUrl: nonemptyStringEnv("E2E_0GCHAIN_GRPC_URL"),
|
||||
ZgChainEvmRpcUrl: nonemptyStringEnv("E2E_0GCHAIN_EVM_RPC_URL"),
|
||||
}
|
||||
|
||||
upgradeHeight := os.Getenv("E2E_KAVA_UPGRADE_HEIGHT")
|
||||
upgradeHeight := os.Getenv("E2E_0GCHAIN_UPGRADE_HEIGHT")
|
||||
if upgradeHeight != "" {
|
||||
parsedHeight, err := strconv.ParseInt(upgradeHeight, 10, 64)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("E2E_KAVA_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
panic(fmt.Sprintf("E2E_0GCHAIN_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
}
|
||||
|
||||
config.UpgradeHeight = parsedHeight
|
||||
|
@ -11,13 +11,13 @@ import (
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
// InitKavaEvmData is run after the chain is running, but before the tests are run.
|
||||
// InitZgChainEvmData is run after the chain is running, but before the tests are run.
|
||||
// It is used to initialize some EVM state, such as deploying contracts.
|
||||
func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
||||
func (suite *E2eTestSuite) InitZgChainEvmData() {
|
||||
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||
|
||||
// ensure funded account has nonzero erc20 balance
|
||||
balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
balance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
if balance.Cmp(big.NewInt(0)) != 1 {
|
||||
panic(fmt.Sprintf(
|
||||
"expected funded account (%s) to have erc20 balance of token %s",
|
||||
@ -27,7 +27,7 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
}
|
||||
|
||||
// expect the erc20 to be enabled for conversion to sdk.Coin
|
||||
params, err := suite.Kava.Grpc.Query.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
|
||||
params, err := suite.ZgChain.Grpc.Query.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to fetch evmutil params during init: %s", err))
|
||||
}
|
||||
@ -42,7 +42,7 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
if !found {
|
||||
panic(fmt.Sprintf("erc20 %s must be enabled for conversion to cosmos coin", erc20Addr))
|
||||
}
|
||||
suite.Kava.RegisterErc20(suite.DeployedErc20.Address)
|
||||
suite.ZgChain.RegisterErc20(suite.DeployedErc20.Address)
|
||||
|
||||
// // expect the erc20's cosmos denom to be a supported cdp collateral type
|
||||
// cdpParams, err := suite.Kava.Grpc.Query.Cdp.Params(context.Background(), &types.QueryParamsRequest{})
|
||||
@ -68,13 +68,13 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
"what's up!",
|
||||
)
|
||||
suite.NoError(err, "failed to deploy a contract to the EVM")
|
||||
suite.Kava.ContractAddrs["greeter"] = greeterAddr
|
||||
suite.ZgChain.ContractAddrs["greeter"] = greeterAddr
|
||||
}
|
||||
|
||||
// FundKavaErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.
|
||||
func (suite *E2eTestSuite) FundKavaErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
|
||||
// FundZgChainErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.
|
||||
func (suite *E2eTestSuite) FundZgChainErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
|
||||
// funded account should have erc20 balance
|
||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
||||
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||
res, err := whale.TransferErc20(suite.DeployedErc20.Address, toAddress, amount)
|
||||
suite.NoError(err)
|
||||
return res
|
||||
|
@ -10,14 +10,15 @@ import (
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
|
||||
const (
|
||||
FundedAccountName = "whale"
|
||||
// use coin type 60 so we are compatible with accounts from `kava add keys --eth <name>`
|
||||
// use coin type 60 so we are compatible with accounts from `0gchaind add keys --eth <name>`
|
||||
// these accounts use the ethsecp256k1 signing algorithm that allows the signing client
|
||||
// to manage both sdk & evm txs.
|
||||
Bip44CoinType = 60
|
||||
@ -27,13 +28,13 @@ const (
|
||||
)
|
||||
|
||||
// DeployedErc20 is a type that wraps the details of the pre-deployed erc20 used by the e2e test suite.
|
||||
// The Address comes from SuiteConfig.KavaErc20Address
|
||||
// The Address comes from SuiteConfig.ZgChainErc20Address
|
||||
// The CosmosDenom is fetched from the EnabledConversionPairs param of x/evmutil.
|
||||
// The tests expect the following:
|
||||
// - the funded account has a nonzero balance of the erc20
|
||||
// - the erc20 is enabled for conversion to sdk.Coin
|
||||
// - the corresponding sdk.Coin is enabled as a cdp collateral type
|
||||
// These requirements are checked in InitKavaEvmData().
|
||||
// These requirements are checked in InitZgChainEvmData().
|
||||
type DeployedErc20 struct {
|
||||
Address common.Address
|
||||
CosmosDenom string
|
||||
@ -41,15 +42,15 @@ type DeployedErc20 struct {
|
||||
CdpCollateralType string
|
||||
}
|
||||
|
||||
// E2eTestSuite is a testify test suite for running end-to-end integration tests on Kava.
|
||||
// E2eTestSuite is a testify test suite for running end-to-end integration tests on ZgChain.
|
||||
type E2eTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
config SuiteConfig
|
||||
runner runner.NodeRunner
|
||||
|
||||
Kava *Chain
|
||||
Ibc *Chain
|
||||
ZgChain *Chain
|
||||
Ibc *Chain
|
||||
|
||||
UpgradeHeight int64
|
||||
DeployedErc20 DeployedErc20
|
||||
@ -85,13 +86,13 @@ func (s costSummary) String() string {
|
||||
func (suite *E2eTestSuite) SetupSuite() {
|
||||
var err error
|
||||
fmt.Println("setting up test suite.")
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
suiteConfig := ParseSuiteConfig()
|
||||
suite.config = suiteConfig
|
||||
suite.DeployedErc20 = DeployedErc20{
|
||||
Address: common.HexToAddress(suiteConfig.KavaErc20Address),
|
||||
// Denom & CdpCollateralType are fetched in InitKavaEvmData()
|
||||
Address: common.HexToAddress(suiteConfig.ZgChainErc20Address),
|
||||
// Denom & CdpCollateralType are fetched in InitZgChainEvmData()
|
||||
}
|
||||
|
||||
// setup the correct NodeRunner for the given config
|
||||
@ -104,11 +105,11 @@ func (suite *E2eTestSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
chains := suite.runner.StartChains()
|
||||
kavachain := chains.MustGetChain("kava")
|
||||
suite.Kava, err = NewChain(suite.T(), kavachain, suiteConfig.FundedAccountMnemonic)
|
||||
zgchain := chains.MustGetChain("0gchain")
|
||||
suite.ZgChain, err = NewChain(suite.T(), zgchain, suiteConfig.FundedAccountMnemonic)
|
||||
if err != nil {
|
||||
suite.runner.Shutdown()
|
||||
suite.T().Fatalf("failed to create kava chain querier: %s", err)
|
||||
suite.T().Fatalf("failed to create 0g-chain querier: %s", err)
|
||||
}
|
||||
|
||||
if suiteConfig.IncludeIbcTests {
|
||||
@ -120,14 +121,14 @@ func (suite *E2eTestSuite) SetupSuite() {
|
||||
}
|
||||
}
|
||||
|
||||
suite.InitKavaEvmData()
|
||||
suite.InitZgChainEvmData()
|
||||
|
||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
||||
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||
suite.cost = costSummary{
|
||||
sdkAddress: whale.SdkAddress.String(),
|
||||
evmAddress: whale.EvmAddress.Hex(),
|
||||
sdkBalanceBefore: suite.Kava.QuerySdkForBalances(whale.SdkAddress),
|
||||
erc20BalanceBefore: suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress),
|
||||
sdkBalanceBefore: suite.ZgChain.QuerySdkForBalances(whale.SdkAddress),
|
||||
erc20BalanceBefore: suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress),
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,27 +137,27 @@ func (suite *E2eTestSuite) SetupSuite() {
|
||||
func (suite *E2eTestSuite) TearDownSuite() {
|
||||
fmt.Println("tearing down test suite.")
|
||||
|
||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
||||
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||
|
||||
if suite.enableRefunds {
|
||||
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
|
||||
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
suite.cost.sdkBalanceAfter = suite.ZgChain.QuerySdkForBalances(whale.SdkAddress)
|
||||
suite.cost.erc20BalanceAfter = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
fmt.Println("==BEFORE REFUNDS==")
|
||||
fmt.Println(suite.cost)
|
||||
|
||||
fmt.Println("attempting to return all unused funds")
|
||||
suite.Kava.ReturnAllFunds()
|
||||
suite.ZgChain.ReturnAllFunds()
|
||||
|
||||
fmt.Println("==AFTER REFUNDS==")
|
||||
}
|
||||
|
||||
// calculate & output cost summary for funded account
|
||||
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
|
||||
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
suite.cost.sdkBalanceAfter = suite.ZgChain.QuerySdkForBalances(whale.SdkAddress)
|
||||
suite.cost.erc20BalanceAfter = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
fmt.Println(suite.cost)
|
||||
|
||||
// close all account request channels
|
||||
suite.Kava.Shutdown()
|
||||
suite.ZgChain.Shutdown()
|
||||
if suite.Ibc != nil {
|
||||
suite.Ibc.Shutdown()
|
||||
}
|
||||
@ -167,19 +168,19 @@ func (suite *E2eTestSuite) TearDownSuite() {
|
||||
// SetupKvtoolNodeRunner is a helper method for building a KvtoolRunnerConfig from the suite config.
|
||||
func (suite *E2eTestSuite) SetupKvtoolNodeRunner() *runner.KvtoolRunner {
|
||||
// upgrade tests are only supported on kvtool networks
|
||||
suite.UpgradeHeight = suite.config.Kvtool.KavaUpgradeHeight
|
||||
suite.UpgradeHeight = suite.config.Kvtool.ZgChainUpgradeHeight
|
||||
suite.enableRefunds = false
|
||||
|
||||
runnerConfig := runner.KvtoolRunnerConfig{
|
||||
KavaConfigTemplate: suite.config.Kvtool.KavaConfigTemplate,
|
||||
ZgChainConfigTemplate: suite.config.Kvtool.ZgChainConfigTemplate,
|
||||
|
||||
IncludeIBC: suite.config.IncludeIbcTests,
|
||||
ImageTag: "local",
|
||||
|
||||
EnableAutomatedUpgrade: suite.config.Kvtool.IncludeAutomatedUpgrade,
|
||||
KavaUpgradeName: suite.config.Kvtool.KavaUpgradeName,
|
||||
KavaUpgradeHeight: suite.config.Kvtool.KavaUpgradeHeight,
|
||||
KavaUpgradeBaseImageTag: suite.config.Kvtool.KavaUpgradeBaseImageTag,
|
||||
EnableAutomatedUpgrade: suite.config.Kvtool.IncludeAutomatedUpgrade,
|
||||
ZgChainUpgradeName: suite.config.Kvtool.ZgChainUpgradeName,
|
||||
ZgChainUpgradeHeight: suite.config.Kvtool.ZgChainUpgradeHeight,
|
||||
ZgChainUpgradeBaseImageTag: suite.config.Kvtool.ZgChainUpgradeBaseImageTag,
|
||||
|
||||
SkipShutdown: suite.config.SkipShutdown,
|
||||
}
|
||||
@ -199,10 +200,10 @@ func (suite *E2eTestSuite) SetupLiveNetworkNodeRunner() *runner.LiveNodeRunner {
|
||||
suite.enableRefunds = true
|
||||
|
||||
runnerConfig := runner.LiveNodeRunnerConfig{
|
||||
KavaRpcUrl: suite.config.LiveNetwork.KavaRpcUrl,
|
||||
KavaGrpcUrl: suite.config.LiveNetwork.KavaGrpcUrl,
|
||||
KavaEvmRpcUrl: suite.config.LiveNetwork.KavaEvmRpcUrl,
|
||||
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
||||
ZgChainRpcUrl: suite.config.LiveNetwork.ZgChainRpcUrl,
|
||||
ZgChainGrpcUrl: suite.config.LiveNetwork.ZgChainGrpcUrl,
|
||||
ZgChainEvmRpcUrl: suite.config.LiveNetwork.ZgChainEvmRpcUrl,
|
||||
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
||||
}
|
||||
|
||||
return runner.NewLiveNodeRunner(runnerConfig)
|
||||
|
@ -8,13 +8,13 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
|
||||
func TestAddressConversion(t *testing.T) {
|
||||
app.SetSDKConfig()
|
||||
bech32Addr := sdk.MustAccAddressFromBech32("kava17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5")
|
||||
chaincfg.SetSDKConfig()
|
||||
bech32Addr := sdk.MustAccAddressFromBech32("0g17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5")
|
||||
hexAddr := common.HexToAddress("0xf354ee99e2bc863cE19d80b843353476394EbC35")
|
||||
require.Equal(t, bech32Addr, util.EvmToSdkAddress(hexAddr))
|
||||
require.Equal(t, hexAddr, util.SdkToEvmAddress(bech32Addr))
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// KavaHomePath returns the OS-specific filepath for the kava home directory
|
||||
// ZgChainHomePath returns the OS-specific filepath for the 0g-chain home directory
|
||||
// Assumes network is running with kvtool installed from the sub-repository in tests/e2e/kvtool
|
||||
func KavaHomePath() string {
|
||||
return filepath.Join("kvtool", "full_configs", "generated", "kava", "initstate", ".kava")
|
||||
func ZgChainHomePath() string {
|
||||
return filepath.Join("kvtool", "full_configs", "generated", "0gchaind", "initstate", ".0gchain")
|
||||
}
|
||||
|
@ -27,18 +27,18 @@ var (
|
||||
ErrUnsuccessfulTx = errors.New("tx committed but returned nonzero code")
|
||||
)
|
||||
|
||||
type KavaMsgRequest struct {
|
||||
type ZgChainMsgRequest struct {
|
||||
Msgs []sdk.Msg
|
||||
GasLimit uint64
|
||||
FeeAmount sdk.Coins
|
||||
Memo string
|
||||
// Arbitrary data to be referenced in the corresponding KavaMsgResponse, unused
|
||||
// in signing. This is mostly useful to match KavaMsgResponses with KavaMsgRequests.
|
||||
// Arbitrary data to be referenced in the corresponding ZgChainMsgResponse, unused
|
||||
// in signing. This is mostly useful to match ZgChainMsgResponses with ZgChainMsgRequests.
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
type KavaMsgResponse struct {
|
||||
Request KavaMsgRequest
|
||||
type ZgChainMsgResponse struct {
|
||||
Request ZgChainMsgRequest
|
||||
Tx authsigning.Tx
|
||||
TxBytes []byte
|
||||
Result sdk.TxResponse
|
||||
@ -55,8 +55,8 @@ const (
|
||||
txResetSequence
|
||||
)
|
||||
|
||||
// KavaSigner broadcasts msgs to a single kava node
|
||||
type KavaSigner struct {
|
||||
// ZgChainSigner broadcasts msgs to a single 0g-chain node
|
||||
type ZgChainSigner struct {
|
||||
chainID string
|
||||
encodingConfig params.EncodingConfig
|
||||
authClient authtypes.QueryClient
|
||||
@ -65,15 +65,15 @@ type KavaSigner struct {
|
||||
inflightTxLimit uint64
|
||||
}
|
||||
|
||||
func NewKavaSigner(
|
||||
func NewZgChainSigner(
|
||||
chainID string,
|
||||
encodingConfig params.EncodingConfig,
|
||||
authClient authtypes.QueryClient,
|
||||
txClient txtypes.ServiceClient,
|
||||
privKey cryptotypes.PrivKey,
|
||||
inflightTxLimit uint64) *KavaSigner {
|
||||
inflightTxLimit uint64) *ZgChainSigner {
|
||||
|
||||
return &KavaSigner{
|
||||
return &ZgChainSigner{
|
||||
chainID: chainID,
|
||||
encodingConfig: encodingConfig,
|
||||
authClient: authClient,
|
||||
@ -83,7 +83,7 @@ func NewKavaSigner(
|
||||
}
|
||||
}
|
||||
|
||||
func (s *KavaSigner) pollAccountState() <-chan authtypes.AccountI {
|
||||
func (s *ZgChainSigner) pollAccountState() <-chan authtypes.AccountI {
|
||||
accountState := make(chan authtypes.AccountI)
|
||||
|
||||
go func() {
|
||||
@ -109,7 +109,7 @@ func (s *KavaSigner) pollAccountState() <-chan authtypes.AccountI {
|
||||
return accountState
|
||||
}
|
||||
|
||||
func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse, error) {
|
||||
func (s *ZgChainSigner) Run(requests <-chan ZgChainMsgRequest) (<-chan ZgChainMsgResponse, error) {
|
||||
// poll account state in it's own goroutine
|
||||
// and send status updates to the signing goroutine
|
||||
//
|
||||
@ -117,15 +117,15 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
||||
// websocket events with a fallback to polling
|
||||
accountState := s.pollAccountState()
|
||||
|
||||
responses := make(chan KavaMsgResponse)
|
||||
responses := make(chan ZgChainMsgResponse)
|
||||
go func() {
|
||||
// wait until account is loaded to start signing
|
||||
account := <-accountState
|
||||
// store current request waiting to be broadcasted
|
||||
var currentRequest *KavaMsgRequest
|
||||
var currentRequest *ZgChainMsgRequest
|
||||
// keep track of all successfully broadcasted txs
|
||||
// index is sequence % inflightTxLimit
|
||||
inflight := make([]*KavaMsgResponse, s.inflightTxLimit)
|
||||
inflight := make([]*ZgChainMsgResponse, s.inflightTxLimit)
|
||||
// used for confirming sent txs only
|
||||
prevDeliverTxSeq := account.GetSequence()
|
||||
// tx sequence of already signed messages
|
||||
@ -252,7 +252,7 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
||||
|
||||
tx, txBytes, err := Sign(s.encodingConfig.TxConfig, s.privKey, txBuilder, signerData)
|
||||
|
||||
response = &KavaMsgResponse{
|
||||
response = &ZgChainMsgResponse{
|
||||
Request: *currentRequest,
|
||||
Tx: tx,
|
||||
TxBytes: txBytes,
|
||||
@ -376,7 +376,7 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
||||
}
|
||||
|
||||
// Address returns the address of the Signer
|
||||
func (s *KavaSigner) Address() sdk.AccAddress {
|
||||
func (s *ZgChainSigner) Address() sdk.AccAddress {
|
||||
return GetAccAddress(s.privKey)
|
||||
}
|
||||
|
||||
|
@ -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"
|
||||
@ -33,7 +34,7 @@ func (suite *ABCITestSuite) SetupTest() {
|
||||
|
||||
// Set up auth GenesisState
|
||||
_, addrs := app.GeneratePrivKeyAddressPairs(12)
|
||||
coins := sdk.NewCoins(c("bnb", 10000000000), c("ukava", 10000000000))
|
||||
coins := sdk.NewCoins(c("bnb", 10000000000), c(chaincfg.DisplayDenom, 10000000000))
|
||||
authGS := app.NewFundedGenStateWithSameCoins(tApp.AppCodec(), coins, addrs)
|
||||
// Initialize test app
|
||||
tApp.InitializeFromGenesisStates(authGS, NewBep3GenStateMulti(tApp.AppCodec(), addrs[11]))
|
||||
|
@ -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)
|
||||
|
@ -49,7 +49,7 @@ func GetCmdCreateAtomicSwap() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "create [to] [recipient-other-chain] [sender-other-chain] [timestamp] [coins] [height-span]",
|
||||
Short: "create a new atomic swap",
|
||||
Example: fmt.Sprintf("%s tx %s create kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj bnb1urfermcg92dwq36572cx4xg84wpk3lfpksr5g7 bnb1uky3me9ggqypmrsvxk7ur6hqkzq7zmv4ed4ng7 now 100bnb 270 --from validator",
|
||||
Example: fmt.Sprintf("%s tx %s create 0g1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj bnb1urfermcg92dwq36572cx4xg84wpk3lfpksr5g7 bnb1uky3me9ggqypmrsvxk7ur6hqkzq7zmv4ed4ng7 now 100bnb 270 --from validator",
|
||||
version.AppName, types.ModuleName),
|
||||
Args: cobra.ExactArgs(6),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
@ -58,7 +58,7 @@ func GetCmdCreateAtomicSwap() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
from := clientCtx.GetFromAddress() // same as Kava executor's deputy address
|
||||
from := clientCtx.GetFromAddress() // same as 0g-chain executor's deputy address
|
||||
to, err := sdk.AccAddressFromBech32(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -11,6 +11,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/bep3/keeper"
|
||||
"github.com/0glabs/0g-chain/x/bep3/types"
|
||||
)
|
||||
@ -25,8 +26,7 @@ type GenesisTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *GenesisTestSuite) SetupTest() {
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
tApp := app.NewTestApp()
|
||||
suite.ctx = tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
||||
|
@ -16,8 +16,8 @@ import (
|
||||
const (
|
||||
TestSenderOtherChain = "bnb1uky3me9ggqypmrsvxk7ur6hqkzq7zmv4ed4ng7"
|
||||
TestRecipientOtherChain = "bnb1urfermcg92dwq36572cx4xg84wpk3lfpksr5g7"
|
||||
TestDeputy = "kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj"
|
||||
TestUser = "kava1vry5lhegzlulehuutcr7nmdlmktw88awp0a39p"
|
||||
TestDeputy = "0g1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj"
|
||||
TestUser = "0g1vry5lhegzlulehuutcr7nmdlmktw88awp0a39p"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
tmtime "github.com/cometbft/cometbft/types/time"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/bep3/keeper"
|
||||
"github.com/0glabs/0g-chain/x/bep3/types"
|
||||
)
|
||||
@ -27,8 +28,7 @@ type AssetTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *AssetTestSuite) SetupTest() {
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
// Initialize test app and set context
|
||||
tApp := app.NewTestApp()
|
||||
|
@ -18,13 +18,13 @@ import (
|
||||
const (
|
||||
TestSenderOtherChain = "bnb1uky3me9ggqypmrsvxk7ur6hqkzq7zmv4ed4ng7"
|
||||
TestRecipientOtherChain = "bnb1urfermcg92dwq36572cx4xg84wpk3lfpksr5g7"
|
||||
TestDeputy = "kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj"
|
||||
TestDeputy = "0g1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj"
|
||||
)
|
||||
|
||||
var (
|
||||
DenomMap = map[int]string{0: "btc", 1: "eth", 2: "bnb", 3: "xrp", 4: "dai"}
|
||||
TestUser1 = sdk.AccAddress(crypto.AddressHash([]byte("KavaTestUser1")))
|
||||
TestUser2 = sdk.AccAddress(crypto.AddressHash([]byte("KavaTestUser2")))
|
||||
TestUser1 = sdk.AccAddress(crypto.AddressHash([]byte("0gTestUser1")))
|
||||
TestUser2 = sdk.AccAddress(crypto.AddressHash([]byte("0gTestUser2")))
|
||||
)
|
||||
|
||||
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
tmtime "github.com/cometbft/cometbft/types/time"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/bep3/keeper"
|
||||
"github.com/0glabs/0g-chain/x/bep3/types"
|
||||
)
|
||||
@ -27,8 +28,8 @@ type KeeperTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *KeeperTestSuite) SetupTest() {
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
suite.ResetChain()
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ func (suite *MsgServerTestSuite) SetupTest() {
|
||||
|
||||
// Set up genesis state and initialize
|
||||
_, addrs := app.GeneratePrivKeyAddressPairs(3)
|
||||
coins := sdk.NewCoins(c("bnb", 10000000000), c("ukava", 10000000000))
|
||||
coins := sdk.NewCoins(c("bnb", 10000000000), c("a0gi", 10000))
|
||||
authGS := app.NewFundedGenStateWithSameCoins(tApp.AppCodec(), coins, addrs)
|
||||
tApp.InitializeFromGenesisStates(authGS, NewBep3GenStateMulti(cdc, addrs[0]))
|
||||
|
||||
|
@ -13,6 +13,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"
|
||||
@ -40,8 +41,7 @@ const (
|
||||
)
|
||||
|
||||
func (suite *AtomicSwapTestSuite) SetupTest() {
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
// Initialize test app and set context
|
||||
tApp := app.NewTestApp()
|
||||
|
@ -22,7 +22,7 @@ func resetSwapForZeroHeight(swap types.AtomicSwap) types.AtomicSwap {
|
||||
case types.SWAP_DIRECTION_OUTGOING:
|
||||
// Open outgoing swaps should be extended to allow enough time to claim after the chain launches.
|
||||
// They cannot be expired as there could be an open/claimed bnb swap.
|
||||
swap.ExpireHeight = 1 + 24686 // default timeout used when sending swaps from kava
|
||||
swap.ExpireHeight = 1 + 24686 // default timeout used when sending swaps from 0g
|
||||
case types.SWAP_DIRECTION_UNSPECIFIED:
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown bep3 swap direction '%s'", dir))
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
app "github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/bep3/types"
|
||||
)
|
||||
|
||||
@ -25,7 +26,7 @@ type migrateTestSuite struct {
|
||||
}
|
||||
|
||||
func (s *migrateTestSuite) SetupTest() {
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
s.v16genstate = types.GenesisState{
|
||||
PreviousBlockTime: time.Date(2021, 4, 8, 15, 0, 0, 0, time.UTC),
|
||||
|
@ -31,8 +31,8 @@ func atomicSwap(index int) types.AtomicSwap {
|
||||
randomNumber, _ := types.GenerateSecureRandomNumber()
|
||||
randomNumberHash := types.CalculateRandomHash(randomNumber[:], timestamp)
|
||||
|
||||
swap := types.NewAtomicSwap(cs(c("bnb", 50000)), randomNumberHash, expireOffset, timestamp, kavaAddrs[0],
|
||||
kavaAddrs[1], binanceAddrs[0].String(), binanceAddrs[1].String(), 1, types.SWAP_STATUS_OPEN, true, types.SWAP_DIRECTION_INCOMING)
|
||||
swap := types.NewAtomicSwap(cs(c("bnb", 50000)), randomNumberHash, expireOffset, timestamp, zgAddrs[0],
|
||||
zgAddrs[1], binanceAddrs[0].String(), binanceAddrs[1].String(), 1, types.SWAP_STATUS_OPEN, true, types.SWAP_DIRECTION_INCOMING)
|
||||
|
||||
return swap
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
sdkmath "cosmossdk.io/math"
|
||||
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/types"
|
||||
)
|
||||
|
||||
@ -20,7 +20,7 @@ type GenesisTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *GenesisTestSuite) SetupTest() {
|
||||
coin := sdk.NewCoin("kava", sdk.OneInt())
|
||||
coin := sdk.NewCoin("a0gi", sdk.OneInt())
|
||||
suite.swaps = atomicSwaps(10)
|
||||
|
||||
supply := types.NewAssetSupply(coin, coin, coin, coin, time.Duration(0))
|
||||
@ -99,8 +99,8 @@ func (suite *GenesisTestSuite) TestValidate() {
|
||||
|
||||
for _, tc := range testCases {
|
||||
suite.Run(tc.name, func() {
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
var gs types.GenesisState
|
||||
if tc.name == "default" {
|
||||
gs = types.DefaultGenesisState()
|
||||
|
@ -33,7 +33,7 @@ var (
|
||||
_ sdk.Msg = &MsgCreateAtomicSwap{}
|
||||
_ sdk.Msg = &MsgClaimAtomicSwap{}
|
||||
_ sdk.Msg = &MsgRefundAtomicSwap{}
|
||||
AtomicSwapCoinsAccAddr = sdk.AccAddress(crypto.AddressHash([]byte("KavaAtomicSwapCoins")))
|
||||
AtomicSwapCoinsAccAddr = sdk.AccAddress(crypto.AddressHash([]byte("0gChainAtomicSwapCoins")))
|
||||
)
|
||||
|
||||
// NewMsgCreateAtomicSwap initializes a new MsgCreateAtomicSwap
|
||||
|
@ -8,30 +8,30 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/bep3/types"
|
||||
)
|
||||
|
||||
var (
|
||||
coinsSingle = sdk.NewCoins(sdk.NewInt64Coin("bnb", 50000))
|
||||
binanceAddrs = []sdk.AccAddress{}
|
||||
kavaAddrs = []sdk.AccAddress{}
|
||||
zgAddrs = []sdk.AccAddress{}
|
||||
randomNumberBytes = []byte{15}
|
||||
timestampInt64 = int64(100)
|
||||
randomNumberHash = tmbytes.HexBytes(types.CalculateRandomHash(randomNumberBytes, timestampInt64))
|
||||
)
|
||||
|
||||
func init() {
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
// Must be set after SetSDKConfig to use kava Bech32 prefix instead of cosmos
|
||||
// Must be set after SetSDKConfig to use 0g Bech32 prefix instead of cosmos
|
||||
binanceAddrs = []sdk.AccAddress{
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("BinanceTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("BinanceTest2"))),
|
||||
}
|
||||
kavaAddrs = []sdk.AccAddress{
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
||||
zgAddrs = []sdk.AccAddress{
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gTest2"))),
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,8 +40,7 @@ type MsgTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *MsgTestSuite) SetupTest() {
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
}
|
||||
|
||||
func (suite *MsgTestSuite) TestMsgCreateAtomicSwap() {
|
||||
@ -57,12 +56,12 @@ func (suite *MsgTestSuite) TestMsgCreateAtomicSwap() {
|
||||
heightSpan uint64
|
||||
expectPass bool
|
||||
}{
|
||||
{"normal cross-chain", binanceAddrs[0], kavaAddrs[0], kavaAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, coinsSingle, 500, true},
|
||||
{"without other chain fields", binanceAddrs[0], kavaAddrs[0], "", "", randomNumberHash.String(), timestampInt64, coinsSingle, 500, false},
|
||||
{"invalid amount", binanceAddrs[0], kavaAddrs[0], kavaAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, nil, 500, false},
|
||||
{"invalid from address", sdk.AccAddress{}, kavaAddrs[0], kavaAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, coinsSingle, 500, false},
|
||||
{"invalid to address", binanceAddrs[0], sdk.AccAddress{}, kavaAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, coinsSingle, 500, false},
|
||||
{"invalid rand hash", binanceAddrs[0], kavaAddrs[0], kavaAddrs[0].String(), binanceAddrs[0].String(), "ff", timestampInt64, coinsSingle, 500, false},
|
||||
{"normal cross-chain", binanceAddrs[0], zgAddrs[0], zgAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, coinsSingle, 500, true},
|
||||
{"without other chain fields", binanceAddrs[0], zgAddrs[0], "", "", randomNumberHash.String(), timestampInt64, coinsSingle, 500, false},
|
||||
{"invalid amount", binanceAddrs[0], zgAddrs[0], zgAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, nil, 500, false},
|
||||
{"invalid from address", sdk.AccAddress{}, zgAddrs[0], zgAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, coinsSingle, 500, false},
|
||||
{"invalid to address", binanceAddrs[0], sdk.AccAddress{}, zgAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, coinsSingle, 500, false},
|
||||
{"invalid rand hash", binanceAddrs[0], zgAddrs[0], zgAddrs[0].String(), binanceAddrs[0].String(), "ff", timestampInt64, coinsSingle, 500, false},
|
||||
}
|
||||
|
||||
for i, tc := range tests {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
bech32MainPrefix = "kava"
|
||||
bech32MainPrefix = "0g"
|
||||
)
|
||||
|
||||
// Parameter keys
|
||||
|
@ -10,6 +10,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/types"
|
||||
)
|
||||
|
||||
@ -20,8 +21,8 @@ type ParamsTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *ParamsTestSuite) SetupTest() {
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
_, addrs := app.GeneratePrivKeyAddressPairs(1)
|
||||
suite.addr = addrs[0]
|
||||
supply1 := types.SupplyLimit{
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func TestAssetSupplyValidate(t *testing.T) {
|
||||
coin := sdk.NewCoin("kava", sdk.OneInt())
|
||||
coin := sdk.NewCoin("a0gi", sdk.OneInt())
|
||||
invalidCoin := sdk.Coin{Denom: "Invalid Denom", Amount: sdkmath.NewInt(-1)}
|
||||
testCases := []struct {
|
||||
msg string
|
||||
|
@ -11,6 +11,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/types"
|
||||
)
|
||||
|
||||
@ -23,8 +24,8 @@ type AtomicSwapTestSuite struct {
|
||||
|
||||
func (suite *AtomicSwapTestSuite) SetupTest() {
|
||||
// Generate 10 addresses
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
_, addrs := app.GeneratePrivKeyAddressPairs(10)
|
||||
|
||||
// Generate 10 timestamps and random number hashes
|
||||
|
@ -35,15 +35,15 @@ const PARAMS_CHANGE_PROPOSAL_EXAMPLE = `
|
||||
|
||||
const COMMITTEE_CHANGE_PROPOSAL_EXAMPLE = `
|
||||
{
|
||||
"@type": "/kava.committee.v1beta1.CommitteeChangeProposal",
|
||||
"@type": "/0g-chain.committee.v1beta1.CommitteeChangeProposal",
|
||||
"title": "A Title",
|
||||
"description": "A proposal description.",
|
||||
"new_committee": {
|
||||
"@type": "/kava.committee.v1beta1.MemberCommittee",
|
||||
"@type": "/0g-chain.committee.v1beta1.MemberCommittee",
|
||||
"base_committee": {
|
||||
"id": "34",
|
||||
"description": "member committee",
|
||||
"members": ["kava1ze7y9qwdddejmy7jlw4cymqqlt2wh05yhwmrv2"],
|
||||
"members": ["0g1ze7y9qwdddejmy7jlw4cymqqlt2wh05yhwmrv2"],
|
||||
"permissions": [],
|
||||
"vote_threshold": "1.000000000000000000",
|
||||
"proposal_duration": "86400s",
|
||||
@ -55,7 +55,7 @@ const COMMITTEE_CHANGE_PROPOSAL_EXAMPLE = `
|
||||
|
||||
const COMMITTEE_DELETE_PROPOSAL_EXAMPLE = `
|
||||
{
|
||||
"@type": "/kava.committee.v1beta1.CommitteeDeleteProposal",
|
||||
"@type": "/0g-chain.committee.v1beta1.CommitteeDeleteProposal",
|
||||
"title": "A Title",
|
||||
"description": "A proposal description.",
|
||||
"committee_id": "1"
|
||||
|
@ -2,21 +2,11 @@ package keeper_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||
cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
||||
"github.com/0glabs/0g-chain/x/committee/types"
|
||||
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||
)
|
||||
|
||||
type PermissionTestSuite struct {
|
||||
@ -29,239 +19,239 @@ func (suite *PermissionTestSuite) SetupTest() {
|
||||
suite.cdc = app.AppCodec()
|
||||
}
|
||||
|
||||
func (suite *PermissionTestSuite) TestSubParamChangePermission_Allows() {
|
||||
// cdp CollateralParams
|
||||
testCPs := cdptypes.CollateralParams{
|
||||
{
|
||||
Denom: "bnb",
|
||||
Type: "bnb-a",
|
||||
LiquidationRatio: d("2.0"),
|
||||
DebtLimit: c("usdx", 1000000000000),
|
||||
StabilityFee: d("1.000000001547125958"),
|
||||
LiquidationPenalty: d("0.05"),
|
||||
AuctionSize: i(100),
|
||||
Prefix: 0x20,
|
||||
ConversionFactor: i(6),
|
||||
SpotMarketID: "bnb:usd",
|
||||
LiquidationMarketID: "bnb:usd",
|
||||
},
|
||||
{
|
||||
Denom: "btc",
|
||||
Type: "btc-a",
|
||||
LiquidationRatio: d("1.5"),
|
||||
DebtLimit: c("usdx", 1000000000),
|
||||
StabilityFee: d("1.000000001547125958"),
|
||||
LiquidationPenalty: d("0.10"),
|
||||
AuctionSize: i(1000),
|
||||
Prefix: 0x30,
|
||||
ConversionFactor: i(8),
|
||||
SpotMarketID: "btc:usd",
|
||||
LiquidationMarketID: "btc:usd",
|
||||
},
|
||||
}
|
||||
testCPUpdatedDebtLimit := make(cdptypes.CollateralParams, len(testCPs))
|
||||
copy(testCPUpdatedDebtLimit, testCPs)
|
||||
testCPUpdatedDebtLimit[0].DebtLimit = c("usdx", 5000000)
|
||||
// func (suite *PermissionTestSuite) TestSubParamChangePermission_Allows() {
|
||||
// // cdp CollateralParams
|
||||
// testCPs := cdptypes.CollateralParams{
|
||||
// {
|
||||
// Denom: "bnb",
|
||||
// Type: "bnb-a",
|
||||
// LiquidationRatio: d("2.0"),
|
||||
// DebtLimit: c("usdx", 1000000000000),
|
||||
// StabilityFee: d("1.000000001547125958"),
|
||||
// LiquidationPenalty: d("0.05"),
|
||||
// AuctionSize: i(100),
|
||||
// Prefix: 0x20,
|
||||
// ConversionFactor: i(6),
|
||||
// SpotMarketID: "bnb:usd",
|
||||
// LiquidationMarketID: "bnb:usd",
|
||||
// },
|
||||
// {
|
||||
// Denom: "btc",
|
||||
// Type: "btc-a",
|
||||
// LiquidationRatio: d("1.5"),
|
||||
// DebtLimit: c("usdx", 1000000000),
|
||||
// StabilityFee: d("1.000000001547125958"),
|
||||
// LiquidationPenalty: d("0.10"),
|
||||
// AuctionSize: i(1000),
|
||||
// Prefix: 0x30,
|
||||
// ConversionFactor: i(8),
|
||||
// SpotMarketID: "btc:usd",
|
||||
// LiquidationMarketID: "btc:usd",
|
||||
// },
|
||||
// }
|
||||
// testCPUpdatedDebtLimit := make(cdptypes.CollateralParams, len(testCPs))
|
||||
// copy(testCPUpdatedDebtLimit, testCPs)
|
||||
// testCPUpdatedDebtLimit[0].DebtLimit = c("usdx", 5000000)
|
||||
|
||||
// cdp DebtParam
|
||||
testDP := cdptypes.DebtParam{
|
||||
Denom: "usdx",
|
||||
ReferenceAsset: "usd",
|
||||
ConversionFactor: i(6),
|
||||
DebtFloor: i(10000000),
|
||||
}
|
||||
testDPUpdatedDebtFloor := testDP
|
||||
testDPUpdatedDebtFloor.DebtFloor = i(1000)
|
||||
// // cdp DebtParam
|
||||
// testDP := cdptypes.DebtParam{
|
||||
// Denom: "usdx",
|
||||
// ReferenceAsset: "usd",
|
||||
// ConversionFactor: i(6),
|
||||
// DebtFloor: i(10000000),
|
||||
// }
|
||||
// testDPUpdatedDebtFloor := testDP
|
||||
// testDPUpdatedDebtFloor.DebtFloor = i(1000)
|
||||
|
||||
// cdp Genesis
|
||||
testCDPParams := cdptypes.DefaultParams()
|
||||
testCDPParams.CollateralParams = testCPs
|
||||
testCDPParams.DebtParam = testDP
|
||||
testCDPParams.GlobalDebtLimit = testCPs[0].DebtLimit.Add(testCPs[0].DebtLimit) // correct global debt limit to pass genesis validation
|
||||
// // cdp Genesis
|
||||
// testCDPParams := cdptypes.DefaultParams()
|
||||
// testCDPParams.CollateralParams = testCPs
|
||||
// testCDPParams.DebtParam = testDP
|
||||
// testCDPParams.GlobalDebtLimit = testCPs[0].DebtLimit.Add(testCPs[0].DebtLimit) // correct global debt limit to pass genesis validation
|
||||
|
||||
testDeputy, err := sdk.AccAddressFromBech32("kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj")
|
||||
suite.Require().NoError(err)
|
||||
// bep3 Asset Params
|
||||
testAPs := bep3types.AssetParams{
|
||||
bep3types.AssetParam{
|
||||
Denom: "bnb",
|
||||
CoinID: 714,
|
||||
SupplyLimit: bep3types.SupplyLimit{
|
||||
Limit: sdkmath.NewInt(350000000000000),
|
||||
TimeLimited: false,
|
||||
TimeBasedLimit: sdk.ZeroInt(),
|
||||
TimePeriod: time.Hour,
|
||||
},
|
||||
Active: true,
|
||||
DeputyAddress: testDeputy,
|
||||
FixedFee: sdkmath.NewInt(1000),
|
||||
MinSwapAmount: sdk.OneInt(),
|
||||
MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
||||
MinBlockLock: bep3types.DefaultMinBlockLock,
|
||||
MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
||||
},
|
||||
bep3types.AssetParam{
|
||||
Denom: "inc",
|
||||
CoinID: 9999,
|
||||
SupplyLimit: bep3types.SupplyLimit{
|
||||
Limit: sdkmath.NewInt(100000000000000),
|
||||
TimeLimited: true,
|
||||
TimeBasedLimit: sdkmath.NewInt(50000000000),
|
||||
TimePeriod: time.Hour,
|
||||
},
|
||||
Active: false,
|
||||
DeputyAddress: testDeputy,
|
||||
FixedFee: sdkmath.NewInt(1000),
|
||||
MinSwapAmount: sdk.OneInt(),
|
||||
MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
||||
MinBlockLock: bep3types.DefaultMinBlockLock,
|
||||
MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
||||
},
|
||||
}
|
||||
testAPsUpdatedActive := make(bep3types.AssetParams, len(testAPs))
|
||||
copy(testAPsUpdatedActive, testAPs)
|
||||
testAPsUpdatedActive[1].Active = true
|
||||
// testDeputy, err := sdk.AccAddressFromBech32("0g1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj")
|
||||
// suite.Require().NoError(err)
|
||||
// // bep3 Asset Params
|
||||
// testAPs := bep3types.AssetParams{
|
||||
// bep3types.AssetParam{
|
||||
// Denom: "bnb",
|
||||
// CoinID: 714,
|
||||
// SupplyLimit: bep3types.SupplyLimit{
|
||||
// Limit: sdkmath.NewInt(350000000000000),
|
||||
// TimeLimited: false,
|
||||
// TimeBasedLimit: sdk.ZeroInt(),
|
||||
// TimePeriod: time.Hour,
|
||||
// },
|
||||
// Active: true,
|
||||
// DeputyAddress: testDeputy,
|
||||
// FixedFee: sdkmath.NewInt(1000),
|
||||
// MinSwapAmount: sdk.OneInt(),
|
||||
// MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
||||
// MinBlockLock: bep3types.DefaultMinBlockLock,
|
||||
// MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
||||
// },
|
||||
// bep3types.AssetParam{
|
||||
// Denom: "inc",
|
||||
// CoinID: 9999,
|
||||
// SupplyLimit: bep3types.SupplyLimit{
|
||||
// Limit: sdkmath.NewInt(100000000000000),
|
||||
// TimeLimited: true,
|
||||
// TimeBasedLimit: sdkmath.NewInt(50000000000),
|
||||
// TimePeriod: time.Hour,
|
||||
// },
|
||||
// Active: false,
|
||||
// DeputyAddress: testDeputy,
|
||||
// FixedFee: sdkmath.NewInt(1000),
|
||||
// MinSwapAmount: sdk.OneInt(),
|
||||
// MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
||||
// MinBlockLock: bep3types.DefaultMinBlockLock,
|
||||
// MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
||||
// },
|
||||
// }
|
||||
// testAPsUpdatedActive := make(bep3types.AssetParams, len(testAPs))
|
||||
// copy(testAPsUpdatedActive, testAPs)
|
||||
// testAPsUpdatedActive[1].Active = true
|
||||
|
||||
// bep3 Genesis
|
||||
testBep3Params := bep3types.DefaultParams()
|
||||
testBep3Params.AssetParams = testAPs
|
||||
// // bep3 Genesis
|
||||
// testBep3Params := bep3types.DefaultParams()
|
||||
// testBep3Params.AssetParams = testAPs
|
||||
|
||||
// pricefeed Markets
|
||||
testMs := pricefeedtypes.Markets{
|
||||
{
|
||||
MarketID: "bnb:usd",
|
||||
BaseAsset: "bnb",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: []sdk.AccAddress{},
|
||||
Active: true,
|
||||
},
|
||||
{
|
||||
MarketID: "btc:usd",
|
||||
BaseAsset: "btc",
|
||||
QuoteAsset: "usd",
|
||||
Oracles: []sdk.AccAddress{},
|
||||
Active: true,
|
||||
},
|
||||
}
|
||||
testMsUpdatedActive := make(pricefeedtypes.Markets, len(testMs))
|
||||
copy(testMsUpdatedActive, testMs)
|
||||
testMsUpdatedActive[1].Active = true
|
||||
// // pricefeed Markets
|
||||
// testMs := pricefeedtypes.Markets{
|
||||
// {
|
||||
// MarketID: "bnb:usd",
|
||||
// BaseAsset: "bnb",
|
||||
// QuoteAsset: "usd",
|
||||
// Oracles: []sdk.AccAddress{},
|
||||
// Active: true,
|
||||
// },
|
||||
// {
|
||||
// MarketID: "btc:usd",
|
||||
// BaseAsset: "btc",
|
||||
// QuoteAsset: "usd",
|
||||
// Oracles: []sdk.AccAddress{},
|
||||
// Active: true,
|
||||
// },
|
||||
// }
|
||||
// testMsUpdatedActive := make(pricefeedtypes.Markets, len(testMs))
|
||||
// copy(testMsUpdatedActive, testMs)
|
||||
// testMsUpdatedActive[1].Active = true
|
||||
|
||||
testcases := []struct {
|
||||
name string
|
||||
genState []app.GenesisState
|
||||
permission types.SubParamChangePermission
|
||||
pubProposal types.PubProposal
|
||||
expectAllowed bool
|
||||
}{
|
||||
{
|
||||
name: "normal",
|
||||
genState: []app.GenesisState{
|
||||
newPricefeedGenState([]string{"bnb", "btc"}, []sdk.Dec{d("15.01"), d("9500")}),
|
||||
newCDPGenesisState(testCDPParams),
|
||||
newBep3GenesisState(testBep3Params),
|
||||
},
|
||||
permission: types.SubParamChangePermission{
|
||||
AllowedParams: types.AllowedParams{
|
||||
{Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtThreshold)},
|
||||
{Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyCollateralParams)},
|
||||
{Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtParam)},
|
||||
{Subspace: bep3types.ModuleName, Key: string(bep3types.KeyAssetParams)},
|
||||
{Subspace: pricefeedtypes.ModuleName, Key: string(pricefeedtypes.KeyMarkets)},
|
||||
},
|
||||
AllowedCollateralParams: types.AllowedCollateralParams{
|
||||
{
|
||||
Type: "bnb-a",
|
||||
DebtLimit: true,
|
||||
StabilityFee: true,
|
||||
},
|
||||
{ // TODO currently even if a perm doesn't allow a change in one element it must still be present in list
|
||||
Type: "btc-a",
|
||||
},
|
||||
},
|
||||
AllowedDebtParam: types.AllowedDebtParam{
|
||||
DebtFloor: true,
|
||||
},
|
||||
AllowedAssetParams: types.AllowedAssetParams{
|
||||
{
|
||||
Denom: "bnb",
|
||||
},
|
||||
{
|
||||
Denom: "inc",
|
||||
Active: true,
|
||||
},
|
||||
},
|
||||
AllowedMarkets: types.AllowedMarkets{
|
||||
{
|
||||
MarketID: "bnb:usd",
|
||||
},
|
||||
{
|
||||
MarketID: "btc:usd",
|
||||
Active: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
pubProposal: paramstypes.NewParameterChangeProposal(
|
||||
"A Title",
|
||||
"A description for this proposal.",
|
||||
[]paramstypes.ParamChange{
|
||||
{
|
||||
Subspace: cdptypes.ModuleName,
|
||||
Key: string(cdptypes.KeyDebtThreshold),
|
||||
Value: string(suite.cdc.MustMarshalJSON(i(1234))),
|
||||
},
|
||||
{
|
||||
Subspace: cdptypes.ModuleName,
|
||||
Key: string(cdptypes.KeyCollateralParams),
|
||||
Value: string(suite.cdc.MustMarshalJSON(testCPUpdatedDebtLimit)),
|
||||
},
|
||||
{
|
||||
Subspace: cdptypes.ModuleName,
|
||||
Key: string(cdptypes.KeyDebtParam),
|
||||
Value: string(suite.cdc.MustMarshalJSON(testDPUpdatedDebtFloor)),
|
||||
},
|
||||
{
|
||||
Subspace: bep3types.ModuleName,
|
||||
Key: string(bep3types.KeyAssetParams),
|
||||
Value: string(suite.cdc.MustMarshalJSON(testAPsUpdatedActive)),
|
||||
},
|
||||
{
|
||||
Subspace: pricefeedtypes.ModuleName,
|
||||
Key: string(pricefeedtypes.KeyMarkets),
|
||||
Value: string(suite.cdc.MustMarshalJSON(testMsUpdatedActive)),
|
||||
},
|
||||
},
|
||||
),
|
||||
expectAllowed: true,
|
||||
},
|
||||
{
|
||||
name: "not allowed (wrong pubproposal type)",
|
||||
permission: types.SubParamChangePermission{},
|
||||
pubProposal: govtypes.NewTextProposal("A Title", "A description for this proposal."),
|
||||
expectAllowed: false,
|
||||
},
|
||||
{
|
||||
name: "not allowed (nil pubproposal)",
|
||||
permission: types.SubParamChangePermission{},
|
||||
pubProposal: nil,
|
||||
expectAllowed: false,
|
||||
},
|
||||
// TODO more cases
|
||||
}
|
||||
// testcases := []struct {
|
||||
// name string
|
||||
// genState []app.GenesisState
|
||||
// permission types.SubParamChangePermission
|
||||
// pubProposal types.PubProposal
|
||||
// expectAllowed bool
|
||||
// }{
|
||||
// {
|
||||
// name: "normal",
|
||||
// genState: []app.GenesisState{
|
||||
// newPricefeedGenState([]string{"bnb", "btc"}, []sdk.Dec{d("15.01"), d("9500")}),
|
||||
// newCDPGenesisState(testCDPParams),
|
||||
// newBep3GenesisState(testBep3Params),
|
||||
// },
|
||||
// permission: types.SubParamChangePermission{
|
||||
// AllowedParams: types.AllowedParams{
|
||||
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtThreshold)},
|
||||
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyCollateralParams)},
|
||||
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtParam)},
|
||||
// {Subspace: bep3types.ModuleName, Key: string(bep3types.KeyAssetParams)},
|
||||
// {Subspace: pricefeedtypes.ModuleName, Key: string(pricefeedtypes.KeyMarkets)},
|
||||
// },
|
||||
// AllowedCollateralParams: types.AllowedCollateralParams{
|
||||
// {
|
||||
// Type: "bnb-a",
|
||||
// DebtLimit: true,
|
||||
// StabilityFee: true,
|
||||
// },
|
||||
// { // TODO currently even if a perm doesn't allow a change in one element it must still be present in list
|
||||
// Type: "btc-a",
|
||||
// },
|
||||
// },
|
||||
// AllowedDebtParam: types.AllowedDebtParam{
|
||||
// DebtFloor: true,
|
||||
// },
|
||||
// AllowedAssetParams: types.AllowedAssetParams{
|
||||
// {
|
||||
// Denom: "bnb",
|
||||
// },
|
||||
// {
|
||||
// Denom: "inc",
|
||||
// Active: true,
|
||||
// },
|
||||
// },
|
||||
// AllowedMarkets: types.AllowedMarkets{
|
||||
// {
|
||||
// MarketID: "bnb:usd",
|
||||
// },
|
||||
// {
|
||||
// MarketID: "btc:usd",
|
||||
// Active: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// pubProposal: paramstypes.NewParameterChangeProposal(
|
||||
// "A Title",
|
||||
// "A description for this proposal.",
|
||||
// []paramstypes.ParamChange{
|
||||
// {
|
||||
// Subspace: cdptypes.ModuleName,
|
||||
// Key: string(cdptypes.KeyDebtThreshold),
|
||||
// Value: string(suite.cdc.MustMarshalJSON(i(1234))),
|
||||
// },
|
||||
// {
|
||||
// Subspace: cdptypes.ModuleName,
|
||||
// Key: string(cdptypes.KeyCollateralParams),
|
||||
// Value: string(suite.cdc.MustMarshalJSON(testCPUpdatedDebtLimit)),
|
||||
// },
|
||||
// {
|
||||
// Subspace: cdptypes.ModuleName,
|
||||
// Key: string(cdptypes.KeyDebtParam),
|
||||
// Value: string(suite.cdc.MustMarshalJSON(testDPUpdatedDebtFloor)),
|
||||
// },
|
||||
// {
|
||||
// Subspace: bep3types.ModuleName,
|
||||
// Key: string(bep3types.KeyAssetParams),
|
||||
// Value: string(suite.cdc.MustMarshalJSON(testAPsUpdatedActive)),
|
||||
// },
|
||||
// {
|
||||
// Subspace: pricefeedtypes.ModuleName,
|
||||
// Key: string(pricefeedtypes.KeyMarkets),
|
||||
// Value: string(suite.cdc.MustMarshalJSON(testMsUpdatedActive)),
|
||||
// },
|
||||
// },
|
||||
// ),
|
||||
// expectAllowed: true,
|
||||
// },
|
||||
// {
|
||||
// name: "not allowed (wrong pubproposal type)",
|
||||
// permission: types.SubParamChangePermission{},
|
||||
// pubProposal: govtypes.NewTextProposal("A Title", "A description for this proposal."),
|
||||
// expectAllowed: false,
|
||||
// },
|
||||
// {
|
||||
// name: "not allowed (nil pubproposal)",
|
||||
// permission: types.SubParamChangePermission{},
|
||||
// pubProposal: nil,
|
||||
// expectAllowed: false,
|
||||
// },
|
||||
// // TODO more cases
|
||||
// }
|
||||
|
||||
for _, tc := range testcases {
|
||||
suite.Run(tc.name, func() {
|
||||
tApp := app.NewTestApp()
|
||||
ctx := tApp.NewContext(true, abci.Header{})
|
||||
tApp.InitializeFromGenesisStates(tc.genState...)
|
||||
// for _, tc := range testcases {
|
||||
// suite.Run(tc.name, func() {
|
||||
// tApp := app.NewTestApp()
|
||||
// ctx := tApp.NewContext(true, abci.Header{})
|
||||
// tApp.InitializeFromGenesisStates(tc.genState...)
|
||||
|
||||
suite.Equal(
|
||||
tc.expectAllowed,
|
||||
tc.permission.Allows(ctx, tApp.Codec(), tApp.GetParamsKeeper(), tc.pubProposal),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
// suite.Equal(
|
||||
// tc.expectAllowed,
|
||||
// tc.permission.Allows(ctx, tApp.Codec(), tApp.GetParamsKeeper(), tc.pubProposal),
|
||||
// )
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
func TestPermissionTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(PermissionTestSuite))
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
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 +62,7 @@ func (suite *MsgServerTestSuite) SetupTest() {
|
||||
[]types.Proposal{},
|
||||
[]types.Vote{},
|
||||
)
|
||||
suite.communityPoolAmt = sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1000)))
|
||||
suite.communityPoolAmt = sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1000)))
|
||||
suite.app.InitializeFromGenesisStates(
|
||||
app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(testGenesis)},
|
||||
// TODO: not used?
|
||||
|
@ -7,6 +7,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/committee/keeper"
|
||||
"github.com/0glabs/0g-chain/x/committee/types"
|
||||
)
|
||||
@ -25,8 +26,8 @@ type Suite struct {
|
||||
|
||||
// SetupTest instantiates a new app, keepers, and sets suite state
|
||||
func (suite *Suite) SetupTest() {
|
||||
config := sdk.GetConfig()
|
||||
app.SetBech32AddressPrefixes(config)
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
suite.App = app.NewTestApp()
|
||||
suite.Keeper = suite.App.GetCommitteeKeeper()
|
||||
suite.BankKeeper = suite.App.GetBankKeeper()
|
||||
|
@ -47,38 +47,38 @@ func init() {
|
||||
RegisterProposalTypeCodec(govv1beta1.TextProposal{}, "cosmos-sdk/TextProposal")
|
||||
RegisterProposalTypeCodec(upgradetypes.SoftwareUpgradeProposal{}, "cosmos-sdk/SoftwareUpgradeProposal")
|
||||
RegisterProposalTypeCodec(upgradetypes.CancelSoftwareUpgradeProposal{}, "cosmos-sdk/CancelSoftwareUpgradeProposal")
|
||||
// RegisterProposalTypeCodec(communitytypes.CommunityCDPRepayDebtProposal{}, "kava/CommunityCDPRepayDebtProposal")
|
||||
// RegisterProposalTypeCodec(communitytypes.CommunityCDPWithdrawCollateralProposal{}, "kava/CommunityCDPWithdrawCollateralProposal")
|
||||
// RegisterProposalTypeCodec(communitytypes.CommunityPoolLendWithdrawProposal{}, "kava/CommunityPoolLendWithdrawProposal")
|
||||
// RegisterProposalTypeCodec(kavadisttypes.CommunityPoolMultiSpendProposal{}, "kava/CommunityPoolMultiSpendProposal")
|
||||
// RegisterProposalTypeCodec(communitytypes.CommunityCDPRepayDebtProposal{}, "0gchain/CommunityCDPRepayDebtProposal")
|
||||
// RegisterProposalTypeCodec(communitytypes.CommunityCDPWithdrawCollateralProposal{}, "0gchain/CommunityCDPWithdrawCollateralProposal")
|
||||
// RegisterProposalTypeCodec(communitytypes.CommunityPoolLendWithdrawProposal{}, "0gchain/CommunityPoolLendWithdrawProposal")
|
||||
// RegisterProposalTypeCodec(kavadisttypes.CommunityPoolMultiSpendProposal{}, "0gchain/CommunityPoolMultiSpendProposal")
|
||||
}
|
||||
|
||||
// RegisterLegacyAminoCodec registers all the necessary types and interfaces for the module.
|
||||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||
// Proposals
|
||||
cdc.RegisterInterface((*PubProposal)(nil), nil)
|
||||
cdc.RegisterConcrete(CommitteeChangeProposal{}, "kava/CommitteeChangeProposal", nil)
|
||||
cdc.RegisterConcrete(CommitteeDeleteProposal{}, "kava/CommitteeDeleteProposal", nil)
|
||||
cdc.RegisterConcrete(CommitteeChangeProposal{}, "0gchain/CommitteeChangeProposal", nil)
|
||||
cdc.RegisterConcrete(CommitteeDeleteProposal{}, "0gchain/CommitteeDeleteProposal", nil)
|
||||
|
||||
// Committees
|
||||
cdc.RegisterInterface((*Committee)(nil), nil)
|
||||
cdc.RegisterConcrete(BaseCommittee{}, "kava/BaseCommittee", nil)
|
||||
cdc.RegisterConcrete(MemberCommittee{}, "kava/MemberCommittee", nil)
|
||||
cdc.RegisterConcrete(TokenCommittee{}, "kava/TokenCommittee", nil)
|
||||
cdc.RegisterConcrete(BaseCommittee{}, "0gchain/BaseCommittee", nil)
|
||||
cdc.RegisterConcrete(MemberCommittee{}, "0gchain/MemberCommittee", nil)
|
||||
cdc.RegisterConcrete(TokenCommittee{}, "0gchain/TokenCommittee", nil)
|
||||
|
||||
// Permissions
|
||||
cdc.RegisterInterface((*Permission)(nil), nil)
|
||||
cdc.RegisterConcrete(GodPermission{}, "kava/GodPermission", nil)
|
||||
cdc.RegisterConcrete(TextPermission{}, "kava/TextPermission", nil)
|
||||
cdc.RegisterConcrete(SoftwareUpgradePermission{}, "kava/SoftwareUpgradePermission", nil)
|
||||
cdc.RegisterConcrete(ParamsChangePermission{}, "kava/ParamsChangePermission", nil)
|
||||
cdc.RegisterConcrete(CommunityCDPRepayDebtPermission{}, "kava/CommunityCDPRepayDebtPermission", nil)
|
||||
cdc.RegisterConcrete(CommunityCDPWithdrawCollateralPermission{}, "kava/CommunityCDPWithdrawCollateralPermission", nil)
|
||||
cdc.RegisterConcrete(CommunityPoolLendWithdrawPermission{}, "kava/CommunityPoolLendWithdrawPermission", nil)
|
||||
cdc.RegisterConcrete(GodPermission{}, "0gchain/GodPermission", nil)
|
||||
cdc.RegisterConcrete(TextPermission{}, "0gchain/TextPermission", nil)
|
||||
cdc.RegisterConcrete(SoftwareUpgradePermission{}, "0gchain/SoftwareUpgradePermission", nil)
|
||||
cdc.RegisterConcrete(ParamsChangePermission{}, "0gchain/ParamsChangePermission", nil)
|
||||
cdc.RegisterConcrete(CommunityCDPRepayDebtPermission{}, "0gchain/CommunityCDPRepayDebtPermission", nil)
|
||||
cdc.RegisterConcrete(CommunityCDPWithdrawCollateralPermission{}, "0gchain/CommunityCDPWithdrawCollateralPermission", nil)
|
||||
cdc.RegisterConcrete(CommunityPoolLendWithdrawPermission{}, "0gchain/CommunityPoolLendWithdrawPermission", nil)
|
||||
|
||||
// Msgs
|
||||
legacy.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "kava/MsgSubmitProposal")
|
||||
legacy.RegisterAminoMsg(cdc, &MsgVote{}, "kava/MsgVote")
|
||||
legacy.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "0gchain/MsgSubmitProposal")
|
||||
legacy.RegisterAminoMsg(cdc, &MsgVote{}, "0gchain/MsgVote")
|
||||
}
|
||||
|
||||
// RegisterProposalTypeCodec allows external modules to register their own pubproposal types on the
|
||||
@ -96,7 +96,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||
|
||||
registry.RegisterInterface(
|
||||
"kava.committee.v1beta1.Committee",
|
||||
"0gchain.committee.v1beta1.Committee",
|
||||
(*Committee)(nil),
|
||||
&BaseCommittee{},
|
||||
&TokenCommittee{},
|
||||
@ -104,7 +104,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||
)
|
||||
|
||||
registry.RegisterInterface(
|
||||
"kava.committee.v1beta1.Permission",
|
||||
"0gchain.committee.v1beta1.Permission",
|
||||
(*Permission)(nil),
|
||||
&GodPermission{},
|
||||
&TextPermission{},
|
||||
@ -118,7 +118,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
||||
// Need to register PubProposal here since we use this as alias for the x/gov Content interface for all the proposal implementations used in this module.
|
||||
// Note that all proposals supported by x/committee needed to be registered here, including the proposals from x/gov.
|
||||
registry.RegisterInterface(
|
||||
"kava.committee.v1beta1.PubProposal",
|
||||
"0gchain.committee.v1beta1.PubProposal",
|
||||
(*PubProposal)(nil),
|
||||
&Proposal{},
|
||||
&distrtypes.CommunityPoolSpendProposal{},
|
||||
|
@ -15,10 +15,10 @@ import (
|
||||
const MaxCommitteeDescriptionLength int = 512
|
||||
|
||||
const (
|
||||
BaseCommitteeType = "kava/BaseCommittee"
|
||||
MemberCommitteeType = "kava/MemberCommittee" // Committee is composed of member addresses that vote to enact proposals within their permissions
|
||||
TokenCommitteeType = "kava/TokenCommittee" // Committee is composed of token holders with voting power determined by total token balance
|
||||
BondDenom = "ukava"
|
||||
BaseCommitteeType = "0g-chain/BaseCommittee"
|
||||
MemberCommitteeType = "0g-chain/MemberCommittee" // Committee is composed of member addresses that vote to enact proposals within their permissions
|
||||
TokenCommitteeType = "0g-chain/TokenCommittee" // Committee is composed of token holders with voting power determined by total token balance
|
||||
BondDenom = "neuron"
|
||||
)
|
||||
|
||||
// Marshal needed for protobuf compatibility.
|
||||
|
@ -17,9 +17,9 @@ import (
|
||||
|
||||
func TestBaseCommittee(t *testing.T) {
|
||||
addresses := []sdk.AccAddress{
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest3"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest2"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest3"))),
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
@ -205,9 +205,9 @@ func TestBaseCommittee(t *testing.T) {
|
||||
|
||||
func TestMemberCommittee(t *testing.T) {
|
||||
addresses := []sdk.AccAddress{
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest3"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest2"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest3"))),
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
@ -251,9 +251,9 @@ func TestMemberCommittee(t *testing.T) {
|
||||
// TestTokenCommittee tests unique TokenCommittee functionality
|
||||
func TestTokenCommittee(t *testing.T) {
|
||||
addresses := []sdk.AccAddress{
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest3"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest2"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest3"))),
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
|
@ -17,11 +17,11 @@ import (
|
||||
func TestGenesisState_Validate(t *testing.T) {
|
||||
testTime := time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||
addresses := []sdk.AccAddress{
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest3"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest4"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest5"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest2"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest3"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest4"))),
|
||||
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest5"))),
|
||||
}
|
||||
|
||||
testGenesis := types.NewGenesisState(
|
||||
|
@ -20,7 +20,7 @@ func MustNewMsgSubmitProposal(pubProposal PubProposal, proposer sdk.AccAddress,
|
||||
}
|
||||
|
||||
func TestMsgSubmitProposal_ValidateBasic(t *testing.T) {
|
||||
addr := sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1")))
|
||||
addr := sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1")))
|
||||
tests := []struct {
|
||||
name string
|
||||
msg *MsgSubmitProposal
|
||||
@ -57,7 +57,7 @@ func TestMsgSubmitProposal_ValidateBasic(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMsgVote_ValidateBasic(t *testing.T) {
|
||||
addr := sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1")))
|
||||
addr := sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1")))
|
||||
tests := []struct {
|
||||
name string
|
||||
msg MsgVote
|
||||
|
@ -53,7 +53,7 @@ func TestUnpackPermissions_Failure(t *testing.T) {
|
||||
// "repay x/community cdp debt",
|
||||
// "repays debt on a cdp position",
|
||||
// "collateral-type",
|
||||
// sdk.NewInt64Coin("ukava", 1e10),
|
||||
// sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e10),
|
||||
// ),
|
||||
// allowed: true,
|
||||
// },
|
||||
@ -90,7 +90,7 @@ func TestUnpackPermissions_Failure(t *testing.T) {
|
||||
// proposal: communitytypes.NewCommunityPoolLendWithdrawProposal(
|
||||
// "withdraw lend position",
|
||||
// "this fake proposal withdraws a lend position for the community pool",
|
||||
// sdk.NewCoins(sdk.NewCoin("ukava", sdk.NewInt(1e10))),
|
||||
// sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdk.NewInt(1e10))),
|
||||
// ),
|
||||
// allowed: true,
|
||||
// },
|
||||
@ -128,7 +128,7 @@ func TestUnpackPermissions_Failure(t *testing.T) {
|
||||
// "withdraw x/community cdp collateral",
|
||||
// "yes",
|
||||
// "collateral-type",
|
||||
// sdk.NewInt64Coin("ukava", 1e10),
|
||||
// sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e10),
|
||||
// ),
|
||||
// allowed: true,
|
||||
// },
|
||||
|
@ -46,12 +46,12 @@ func ParseOrQueryConversionPairAddress(
|
||||
|
||||
if err := sdk.ValidateDenom(addrOrDenom); err != nil {
|
||||
return common.Address{}, fmt.Errorf(
|
||||
"Kava ERC20 '%s' is not a valid hex address or denom",
|
||||
"0gChain ERC20 '%s' is not a valid hex address or denom",
|
||||
addrOrDenom,
|
||||
)
|
||||
}
|
||||
|
||||
// Valid denom, try looking up as denom to get corresponding Kava ERC20 address
|
||||
// Valid denom, try looking up as denom to get corresponding 0gChain ERC20 address
|
||||
paramsRes, err := queryClient.Params(
|
||||
context.Background(),
|
||||
&types.QueryParamsRequest{},
|
||||
@ -67,7 +67,7 @@ func ParseOrQueryConversionPairAddress(
|
||||
}
|
||||
|
||||
return common.Address{}, fmt.Errorf(
|
||||
"Kava ERC20 '%s' is not a valid hex address or denom (did not match any denoms in queried enabled conversion pairs)",
|
||||
"0gChain ERC20 '%s' is not a valid hex address or denom (did not match any denoms in queried enabled conversion pairs)",
|
||||
addrOrDenom,
|
||||
)
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func GetTxCmd() *cobra.Command {
|
||||
|
||||
func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "convert-evm-erc20-from-coin [Kava EVM address] [coin]",
|
||||
Use: "convert-evm-erc20-from-coin [0gChain EVM address] [coin]",
|
||||
Short: "EVM-native asset: converts a coin on Cosmos co-chain to an ERC20 on EVM co-chain",
|
||||
Example: fmt.Sprintf(
|
||||
`%s tx %s convert-evm-erc20-from-coin 0x7Bbf300890857b8c241b219C6a489431669b3aFA 500000000erc20/usdc --from <key> --gas 2000000`,
|
||||
@ -81,10 +81,10 @@ func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
||||
|
||||
func getCmdConvertEvmERC20ToCoin() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "convert-evm-erc20-to-coin [Kava receiver address] [Kava ERC20 address] [amount]",
|
||||
Use: "convert-evm-erc20-to-coin [0gChain receiver address] [0gChain ERC20 address] [amount]",
|
||||
Short: "EVM-native asset: converts an ERC20 on EVM co-chain to a coin on Cosmos co-chain",
|
||||
Example: fmt.Sprintf(`
|
||||
%[1]s tx %[2]s convert-evm-erc20-to-coin kava10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t 0xeA7100edA2f805356291B0E55DaD448599a72C6d 1000000000000000 --from <key> --gas 1000000
|
||||
%[1]s tx %[2]s convert-evm-erc20-to-coin 0g10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t 0xeA7100edA2f805356291B0E55DaD448599a72C6d 1000000000000000 --from <key> --gas 1000000
|
||||
`, version.AppName, types.ModuleName,
|
||||
),
|
||||
Args: cobra.ExactArgs(3),
|
||||
@ -163,11 +163,11 @@ func getCmdMsgConvertCosmosCoinToERC20() *cobra.Command {
|
||||
|
||||
func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "convert-cosmos-coin-from-erc20 [receiver_kava_address] [amount] [flags]",
|
||||
Use: "convert-cosmos-coin-from-erc20 [receiver_0g_address] [amount] [flags]",
|
||||
Short: "Cosmos-native asset: converts an ERC20 on EVM co-chain back to a coin on Cosmos co-chain",
|
||||
Example: fmt.Sprintf(
|
||||
`Convert ERC20 representation of 500 ATOM back to a Cosmos coin, sending to kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a:
|
||||
%s tx %s convert-cosmos-coin-from-erc20 kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a 500000000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 --from <key> --gas 2000000`,
|
||||
`Convert ERC20 representation of 500 ATOM back to a Cosmos coin, sending to 0g1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a:
|
||||
%s tx %s convert-cosmos-coin-from-erc20 0g1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a 500000000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 --from <key> --gas 2000000`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
@ -179,7 +179,7 @@ func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
||||
|
||||
receiver, err := sdk.AccAddressFromBech32(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("receiver '%s' is an invalid kava address", args[0])
|
||||
return fmt.Errorf("receiver '%s' is an invalid 0g-chain address", args[0])
|
||||
}
|
||||
|
||||
amount, err := sdk.ParseCoinNormalized(args[1])
|
||||
|
@ -98,7 +98,7 @@ func (s *genesisTestSuite) TestExportGenesis() {
|
||||
params.AllowedCosmosDenoms = []types.AllowedCosmosCoinERC20Token{
|
||||
{
|
||||
CosmosDenom: "hard",
|
||||
Name: "Kava EVM HARD",
|
||||
Name: "0G EVM HARD",
|
||||
Symbol: "HARD",
|
||||
Decimals: 6,
|
||||
},
|
||||
|
@ -9,56 +9,49 @@ import (
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// EvmDenom is the gas denom used by the evm
|
||||
EvmDenom = "akava"
|
||||
|
||||
// CosmosDenom is the gas denom used by the kava app
|
||||
CosmosDenom = "ukava"
|
||||
)
|
||||
|
||||
// ConversionMultiplier is the conversion multiplier between akava and ukava
|
||||
var ConversionMultiplier = sdkmath.NewInt(1_000_000_000_000)
|
||||
// ConversionMultiplier is the conversion multiplier between neuron and a0gi
|
||||
var ConversionMultiplier = sdkmath.NewInt(chaincfg.ConversionMultiplier)
|
||||
|
||||
var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
||||
|
||||
// EvmBankKeeper is a BankKeeper wrapper for the x/evm module to allow the use
|
||||
// of the 18 decimal akava coin on the evm.
|
||||
// x/evm consumes gas and send coins by minting and burning akava coins in its module
|
||||
// of the 18 decimal neuron coin on the evm.
|
||||
// x/evm consumes gas and send coins by minting and burning neuron coins in its module
|
||||
// account and then sending the funds to the target account.
|
||||
// This keeper uses both the ukava coin and a separate akava balance to manage the
|
||||
// This keeper uses both the a0gi coin and a separate neuron balance to manage the
|
||||
// extra percision needed by the evm.
|
||||
type EvmBankKeeper struct {
|
||||
akavaKeeper Keeper
|
||||
bk types.BankKeeper
|
||||
ak types.AccountKeeper
|
||||
baseKeeper Keeper
|
||||
bk types.BankKeeper
|
||||
ak types.AccountKeeper
|
||||
}
|
||||
|
||||
func NewEvmBankKeeper(akavaKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
||||
func NewEvmBankKeeper(baseKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
||||
return EvmBankKeeper{
|
||||
akavaKeeper: akavaKeeper,
|
||||
bk: bk,
|
||||
ak: ak,
|
||||
baseKeeper: baseKeeper,
|
||||
bk: bk,
|
||||
ak: ak,
|
||||
}
|
||||
}
|
||||
|
||||
// GetBalance returns the total **spendable** balance of akava for a given account by address.
|
||||
// GetBalance returns the total **spendable** balance of neuron for a given account by address.
|
||||
func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
||||
if denom != EvmDenom {
|
||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", EvmDenom))
|
||||
if denom != chaincfg.BaseDenom {
|
||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.BaseDenom))
|
||||
}
|
||||
|
||||
spendableCoins := k.bk.SpendableCoins(ctx, addr)
|
||||
ukava := spendableCoins.AmountOf(CosmosDenom)
|
||||
akava := k.akavaKeeper.GetBalance(ctx, addr)
|
||||
total := ukava.Mul(ConversionMultiplier).Add(akava)
|
||||
return sdk.NewCoin(EvmDenom, total)
|
||||
a0gi := spendableCoins.AmountOf(chaincfg.DisplayDenom)
|
||||
neuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||
total := a0gi.Mul(ConversionMultiplier).Add(neuron)
|
||||
return sdk.NewCoin(chaincfg.BaseDenom, total)
|
||||
}
|
||||
|
||||
// SendCoins transfers akava coins from a AccAddress to an AccAddress.
|
||||
// SendCoins transfers neuron 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
|
||||
@ -66,101 +59,101 @@ func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, rec
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// SendCoinsFromModuleToAccount transfers akava coins from a ModuleAccount to an AccAddress.
|
||||
// SendCoinsFromModuleToAccount transfers neuron 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 {
|
||||
ukava, akava, err := SplitAkavaCoins(amt)
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ukava.Amount.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(ukava)); err != nil {
|
||||
if a0gi.Amount.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
senderAddr := k.GetModuleAddress(senderModule)
|
||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, senderAddr, akava); err != nil {
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := k.akavaKeeper.SendBalance(ctx, senderAddr, recipientAddr, akava); err != nil {
|
||||
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// SendCoinsFromAccountToModule transfers akava coins from an AccAddress to a ModuleAccount.
|
||||
// SendCoinsFromAccountToModule transfers neuron 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 {
|
||||
ukava, akavaNeeded, err := SplitAkavaCoins(amt)
|
||||
a0gi, neuronNeeded, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ukava.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(ukava)); err != nil {
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, senderAddr, akavaNeeded); err != nil {
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
recipientAddr := k.GetModuleAddress(recipientModule)
|
||||
if err := k.akavaKeeper.SendBalance(ctx, senderAddr, recipientAddr, akavaNeeded); err != nil {
|
||||
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuronNeeded); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// MintCoins mints akava coins by minting the equivalent ukava coins and any remaining akava coins.
|
||||
// MintCoins mints neuron coins by minting the equivalent a0gi coins and any remaining neuron 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 {
|
||||
ukava, akava, err := SplitAkavaCoins(amt)
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ukava.IsPositive() {
|
||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(ukava)); err != nil {
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
recipientAddr := k.GetModuleAddress(moduleName)
|
||||
if err := k.akavaKeeper.AddBalance(ctx, recipientAddr, akava); err != nil {
|
||||
if err := k.baseKeeper.AddBalance(ctx, recipientAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// BurnCoins burns akava coins by burning the equivalent ukava coins and any remaining akava coins.
|
||||
// BurnCoins burns neuron coins by burning the equivalent a0gi coins and any remaining neuron 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 {
|
||||
ukava, akava, err := SplitAkavaCoins(amt)
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ukava.IsPositive() {
|
||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(ukava)); err != nil {
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
moduleAddr := k.GetModuleAddress(moduleName)
|
||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, moduleAddr, akava); err != nil {
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, moduleAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.akavaKeeper.RemoveBalance(ctx, moduleAddr, akava)
|
||||
return k.baseKeeper.RemoveBalance(ctx, moduleAddr, neuron)
|
||||
}
|
||||
|
||||
// IsSendEnabledCoins checks the coins provided and returns an ErrSendDisabled
|
||||
@ -173,51 +166,51 @@ func (k EvmBankKeeper) IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) er
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// ConvertOneUkavaToAkavaIfNeeded converts 1 ukava to akava for an address if
|
||||
// its akava balance is smaller than the akavaNeeded amount.
|
||||
func (k EvmBankKeeper) ConvertOneUkavaToAkavaIfNeeded(ctx sdk.Context, addr sdk.AccAddress, akavaNeeded sdkmath.Int) error {
|
||||
akavaBal := k.akavaKeeper.GetBalance(ctx, addr)
|
||||
if akavaBal.GTE(akavaNeeded) {
|
||||
// ConvertOneA0giToNeuronIfNeeded converts 1 a0gi to neuron for an address if
|
||||
// its neuron balance is smaller than the neuronNeeded amount.
|
||||
func (k EvmBankKeeper) ConvertOneA0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error {
|
||||
neuronBal := k.baseKeeper.GetBalance(ctx, addr)
|
||||
if neuronBal.GTE(neuronNeeded) {
|
||||
return nil
|
||||
}
|
||||
|
||||
ukavaToStore := sdk.NewCoins(sdk.NewCoin(CosmosDenom, sdk.OneInt()))
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, ukavaToStore); err != nil {
|
||||
a0giToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdk.OneInt()))
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, a0giToStore); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add 1ukava equivalent of akava to addr
|
||||
akavaToReceive := ConversionMultiplier
|
||||
if err := k.akavaKeeper.AddBalance(ctx, addr, akavaToReceive); err != nil {
|
||||
// add 1a0gi equivalent of neuron to addr
|
||||
neuronToReceive := ConversionMultiplier
|
||||
if err := k.baseKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConvertAkavaToUkava converts all available akava to ukava for a given AccAddress.
|
||||
func (k EvmBankKeeper) ConvertAkavaToUkava(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||
totalAkava := k.akavaKeeper.GetBalance(ctx, addr)
|
||||
ukava, _, err := SplitAkavaCoins(sdk.NewCoins(sdk.NewCoin(EvmDenom, totalAkava)))
|
||||
// ConvertNeuronToA0gi converts all available neuron to a0gi for a given AccAddress.
|
||||
func (k EvmBankKeeper) ConvertNeuronToA0gi(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||
totalNeuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||
a0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, totalNeuron)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// do nothing if account does not have enough akava for a single ukava
|
||||
ukavaToReceive := ukava.Amount
|
||||
if !ukavaToReceive.IsPositive() {
|
||||
// do nothing if account does not have enough neuron for a single a0gi
|
||||
a0giToReceive := a0gi.Amount
|
||||
if !a0giToReceive.IsPositive() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// remove akava used for converting to ukava
|
||||
akavaToBurn := ukavaToReceive.Mul(ConversionMultiplier)
|
||||
finalBal := totalAkava.Sub(akavaToBurn)
|
||||
if err := k.akavaKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||
// remove neuron used for converting to a0gi
|
||||
neuronToBurn := a0giToReceive.Mul(ConversionMultiplier)
|
||||
finalBal := totalNeuron.Sub(neuronToBurn)
|
||||
if err := k.baseKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fromAddr := k.GetModuleAddress(types.ModuleName)
|
||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(ukava)); err != nil {
|
||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -232,35 +225,35 @@ func (k EvmBankKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
|
||||
return addr
|
||||
}
|
||||
|
||||
// SplitAkavaCoins splits akava coins to the equivalent ukava coins and any remaining akava balance.
|
||||
// An error will be returned if the coins are not valid or if the coins are not the akava denom.
|
||||
func SplitAkavaCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
akava := sdk.ZeroInt()
|
||||
ukava := sdk.NewCoin(CosmosDenom, sdk.ZeroInt())
|
||||
// SplitNeuronCoins splits neuron coins to the equivalent a0gi coins and any remaining neuron balance.
|
||||
// An error will be returned if the coins are not valid or if the coins are not the neuron denom.
|
||||
func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
neuron := sdk.ZeroInt()
|
||||
a0gi := sdk.NewCoin(chaincfg.DisplayDenom, sdk.ZeroInt())
|
||||
|
||||
if len(coins) == 0 {
|
||||
return ukava, akava, nil
|
||||
return a0gi, neuron, nil
|
||||
}
|
||||
|
||||
if err := ValidateEvmCoins(coins); err != nil {
|
||||
return ukava, akava, err
|
||||
return a0gi, neuron, err
|
||||
}
|
||||
|
||||
// note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate.
|
||||
coin := coins[0]
|
||||
remainingBalance := coin.Amount.Mod(ConversionMultiplier)
|
||||
if remainingBalance.IsPositive() {
|
||||
akava = remainingBalance
|
||||
neuron = remainingBalance
|
||||
}
|
||||
ukavaAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||
if ukavaAmount.IsPositive() {
|
||||
ukava = sdk.NewCoin(CosmosDenom, ukavaAmount)
|
||||
a0giAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||
if a0giAmount.IsPositive() {
|
||||
a0gi = sdk.NewCoin(chaincfg.DisplayDenom, a0giAmount)
|
||||
}
|
||||
|
||||
return ukava, akava, nil
|
||||
return a0gi, neuron, nil
|
||||
}
|
||||
|
||||
// ValidateEvmCoins validates the coins from evm is valid and is the EvmDenom (akava).
|
||||
// ValidateEvmCoins validates the coins from evm is valid and is the chaincfg.BaseDenom (neuron).
|
||||
func ValidateEvmCoins(coins sdk.Coins) error {
|
||||
if len(coins) == 0 {
|
||||
return nil
|
||||
@ -271,9 +264,9 @@ func ValidateEvmCoins(coins sdk.Coins) error {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
|
||||
}
|
||||
|
||||
// validate that coin denom is akava
|
||||
if len(coins) != 1 || coins[0].Denom != EvmDenom {
|
||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", EvmDenom)
|
||||
// validate that coin denom is neuron
|
||||
if len(coins) != 1 || coins[0].Denom != chaincfg.BaseDenom {
|
||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.BaseDenom)
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
|
||||
"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"
|
||||
@ -27,8 +28,8 @@ func (suite *evmBankKeeperTestSuite) SetupTest() {
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
||||
startingCoins := sdk.NewCoins(sdk.NewInt64Coin("ukava", 10))
|
||||
startingAkava := sdkmath.NewInt(100)
|
||||
startingCoins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10))
|
||||
startingNeuron := sdkmath.NewInt(100)
|
||||
|
||||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
@ -38,20 +39,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], startingAkava)
|
||||
err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingNeuron)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "akava")
|
||||
suite.Require().Equal(startingAkava, coin.Amount)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
suite.Require().Equal(startingNeuron, coin.Amount)
|
||||
|
||||
ctx := suite.Ctx.WithBlockTime(now.Add(12 * time.Hour))
|
||||
coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], "akava")
|
||||
coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
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], "ukava")
|
||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
})
|
||||
suite.Require().Panics(func() {
|
||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "busd")
|
||||
@ -65,39 +66,39 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
expAmount sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"ukava with akava",
|
||||
"a0gi with neuron",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 100),
|
||||
sdk.NewInt64Coin("ukava", 10),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 10),
|
||||
),
|
||||
sdkmath.NewInt(10_000_000_000_100),
|
||||
},
|
||||
{
|
||||
"just akava",
|
||||
"just neuron",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 100),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin("busd", 100),
|
||||
),
|
||||
sdkmath.NewInt(100),
|
||||
},
|
||||
{
|
||||
"just ukava",
|
||||
"just a0gi",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("ukava", 10),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 10),
|
||||
sdk.NewInt64Coin("busd", 100),
|
||||
),
|
||||
sdkmath.NewInt(10_000_000_000_000),
|
||||
},
|
||||
{
|
||||
"no ukava or akava",
|
||||
"no a0gi or neuron",
|
||||
sdk.NewCoins(),
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"with avaka that is more than 1 ukava",
|
||||
"with avaka that is more than 1 a0gi",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 20_000_000_000_220),
|
||||
sdk.NewInt64Coin("ukava", 11),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 20_000_000_000_220),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 11),
|
||||
),
|
||||
sdkmath.NewInt(31_000_000_000_220),
|
||||
},
|
||||
@ -107,8 +108,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingAmount)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "akava")
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAmount)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
suite.Require().Equal(tt.expAmount, coin.Amount)
|
||||
})
|
||||
}
|
||||
@ -116,8 +117,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
startingModuleCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 200),
|
||||
sdk.NewInt64Coin("ukava", 100),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||
)
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -127,102 +128,102 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
hasErr bool
|
||||
}{
|
||||
{
|
||||
"send more than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_010)),
|
||||
"send more than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 10),
|
||||
sdk.NewInt64Coin("ukava", 12),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 10),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 12),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send less than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
||||
"send less than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 122),
|
||||
sdk.NewInt64Coin("ukava", 0),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 122),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 0),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send an exact amount of ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
||||
"send an exact amount of a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 0o0),
|
||||
sdk.NewInt64Coin("ukava", 98),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 0o0),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 98),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send no akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
||||
"send no neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 0),
|
||||
sdk.NewInt64Coin("ukava", 0),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 0),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 0),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"errors if sending other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough total akava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_001_000)),
|
||||
"errors if not enough total neuron to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough ukava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
||||
"errors if not enough a0gi to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"converts receiver's akava to ukava if there's enough akava after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_000_000_000_200)),
|
||||
"converts receiver's neuron to a0gi if there's enough neuron after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_000_200)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 999_999_999_900),
|
||||
sdk.NewInt64Coin("ukava", 1),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 999_999_999_900),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 100),
|
||||
sdk.NewInt64Coin("ukava", 101),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 101),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts all of receiver's akava to ukava even if somehow receiver has more than 1ukava of akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_100)),
|
||||
"converts all of receiver's neuron to a0gi even if somehow receiver has more than 1a0gi of neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_100)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 5_999_999_999_990),
|
||||
sdk.NewInt64Coin("ukava", 1),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 5_999_999_999_990),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 90),
|
||||
sdk.NewInt64Coin("ukava", 19),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 90),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 19),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"swap 1 ukava for akava if module account doesn't have enough akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_000_000_001_000)),
|
||||
"swap 1 a0gi for neuron if module account doesn't have enough neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_001_000)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 200),
|
||||
sdk.NewInt64Coin("ukava", 1),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 1200),
|
||||
sdk.NewInt64Coin("ukava", 100),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 1200),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||
),
|
||||
false,
|
||||
},
|
||||
@ -232,11 +233,11 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingAccBal)
|
||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingModuleCoins)
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAccBal)
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||
|
||||
// fund our module with some ukava to account for converting extra akava back to ukava
|
||||
suite.FundModuleAccountWithKava(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
||||
// fund our module with some a0gi to account for converting extra neuron back to a0gi
|
||||
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||
|
||||
err := suite.EvmBankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, evmtypes.ModuleName, suite.Addrs[0], tt.sendCoins)
|
||||
if tt.hasErr {
|
||||
@ -246,24 +247,24 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check ukava
|
||||
ukavaSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
||||
// check a0gi
|
||||
a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||
|
||||
// check akava
|
||||
actualAkava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf("akava").Int64(), actualAkava.Int64())
|
||||
// check neuron
|
||||
actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
startingAccCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 200),
|
||||
sdk.NewInt64Coin("ukava", 100),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||
)
|
||||
startingModuleCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 100_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000),
|
||||
)
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -273,36 +274,36 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
hasErr bool
|
||||
}{
|
||||
{
|
||||
"send more than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_010)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 190), sdk.NewInt64Coin("ukava", 88)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_010), sdk.NewInt64Coin("ukava", 12)),
|
||||
"send more than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 190), sdk.NewInt64Coin(chaincfg.DisplayDenom, 88)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_010), sdk.NewInt64Coin(chaincfg.DisplayDenom, 12)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send less than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 78), sdk.NewInt64Coin("ukava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_122), sdk.NewInt64Coin("ukava", 0)),
|
||||
"send less than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 78), sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_122), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send an exact amount of ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 2)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 98)),
|
||||
"send an exact amount of a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 2)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 98)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send no akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 0)),
|
||||
"send no neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"errors if sending other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
@ -310,39 +311,39 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
},
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough total akava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_001_000)),
|
||||
"errors if not enough total neuron to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough ukava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
||||
"errors if not enough a0gi to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"converts 1 ukava to akava if not enough akava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_001_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 999_000_000_200), sdk.NewInt64Coin("ukava", 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 101_000_000_000), sdk.NewInt64Coin("ukava", 99)),
|
||||
"converts 1 a0gi to neuron if not enough neuron 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.DisplayDenom, 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 101_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 99)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts receiver's akava to ukava if there's enough akava after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 5_900_000_000_200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 94)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 6)),
|
||||
"converts receiver's neuron to a0gi if there's enough neuron 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.DisplayDenom, 94)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 6)),
|
||||
false,
|
||||
},
|
||||
}
|
||||
@ -350,8 +351,8 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
suite.FundAccountWithKava(suite.Addrs[0], startingAccCoins)
|
||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingModuleCoins)
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], startingAccCoins)
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||
|
||||
err := suite.EvmBankKeeper.SendCoinsFromAccountToModule(suite.Ctx, suite.Addrs[0], evmtypes.ModuleName, tt.sendCoins)
|
||||
if tt.hasErr {
|
||||
@ -362,67 +363,67 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
}
|
||||
|
||||
// check sender balance
|
||||
ukavaSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
||||
actualAkava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf("akava").Int64(), actualAkava.Int64())
|
||||
a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||
actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||
|
||||
// check module balance
|
||||
moduleAddr := suite.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
|
||||
ukavaSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, "ukava")
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
||||
actualAkava = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf("akava").Int64(), actualAkava.Int64())
|
||||
a0giSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||
actualNeuron = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
startingUkava := sdkmath.NewInt(100)
|
||||
startingA0gi := sdkmath.NewInt(100)
|
||||
tests := []struct {
|
||||
name string
|
||||
burnCoins sdk.Coins
|
||||
expUkava sdkmath.Int
|
||||
expAkava sdkmath.Int
|
||||
hasErr bool
|
||||
akavaStart sdkmath.Int
|
||||
name string
|
||||
burnCoins sdk.Coins
|
||||
expA0gi sdkmath.Int
|
||||
expNeuron sdkmath.Int
|
||||
hasErr bool
|
||||
neuronStart sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"burn more than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
||||
"burn more than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 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 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
||||
"burn less than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
sdkmath.NewInt(100),
|
||||
sdkmath.NewInt(878),
|
||||
false,
|
||||
sdkmath.NewInt(1000),
|
||||
},
|
||||
{
|
||||
"burn an exact amount of ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
||||
"burn an exact amount of a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
sdkmath.NewInt(2),
|
||||
sdkmath.NewInt(10),
|
||||
false,
|
||||
sdkmath.NewInt(10),
|
||||
},
|
||||
{
|
||||
"burn no akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
||||
startingUkava,
|
||||
"burn no neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
startingA0gi,
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"errors if burning other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
startingUkava,
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
startingA0gi,
|
||||
sdkmath.NewInt(100),
|
||||
true,
|
||||
sdkmath.NewInt(100),
|
||||
@ -430,41 +431,41 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
},
|
||||
startingUkava,
|
||||
startingA0gi,
|
||||
sdk.ZeroInt(),
|
||||
true,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"errors if burn amount is negative",
|
||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-100)}},
|
||||
startingUkava,
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||
startingA0gi,
|
||||
sdkmath.NewInt(50),
|
||||
true,
|
||||
sdkmath.NewInt(50),
|
||||
},
|
||||
{
|
||||
"errors if not enough akava to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_999_000_000_000)),
|
||||
"errors if not enough neuron to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 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 ukava to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
||||
"errors if not enough a0gi to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
sdkmath.NewInt(100),
|
||||
sdk.ZeroInt(),
|
||||
true,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"converts 1 ukava to akava if not enough akava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
||||
"converts 1 a0gi to neuron if not enough neuron to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(87),
|
||||
sdkmath.NewInt(980_000_000_000),
|
||||
false,
|
||||
@ -476,10 +477,10 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
startingCoins := sdk.NewCoins(
|
||||
sdk.NewCoin("ukava", startingUkava),
|
||||
sdk.NewCoin("akava", tt.akavaStart),
|
||||
sdk.NewCoin(chaincfg.DisplayDenom, startingA0gi),
|
||||
sdk.NewCoin(chaincfg.BaseDenom, tt.neuronStart),
|
||||
)
|
||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingCoins)
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingCoins)
|
||||
|
||||
err := suite.EvmBankKeeper.BurnCoins(suite.Ctx, evmtypes.ModuleName, tt.burnCoins)
|
||||
if tt.hasErr {
|
||||
@ -489,53 +490,53 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check ukava
|
||||
ukavaActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ukava")
|
||||
suite.Require().Equal(tt.expUkava, ukavaActual.Amount)
|
||||
// check a0gi
|
||||
a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expA0gi, a0giActual.Amount)
|
||||
|
||||
// check akava
|
||||
akavaActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.expAkava, akavaActual)
|
||||
// check neuron
|
||||
neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.expNeuron, neuronActual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
tests := []struct {
|
||||
name string
|
||||
mintCoins sdk.Coins
|
||||
ukava sdkmath.Int
|
||||
akava sdkmath.Int
|
||||
hasErr bool
|
||||
akavaStart sdkmath.Int
|
||||
name string
|
||||
mintCoins sdk.Coins
|
||||
a0gi sdkmath.Int
|
||||
neuron sdkmath.Int
|
||||
hasErr bool
|
||||
neuronStart sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"mint more than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
||||
"mint more than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(21_000_000_002),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint less than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 901_000_000_001)),
|
||||
"mint less than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 901_000_000_001)),
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(901_000_000_001),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint an exact amount of ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 123_000_000_000_000_000)),
|
||||
"mint an exact amount of a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 123_000_000_000_000_000)),
|
||||
sdkmath.NewInt(123_000),
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint no akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
||||
"mint no neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
sdk.ZeroInt(),
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
@ -543,7 +544,7 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
},
|
||||
{
|
||||
"errors if minting other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(100),
|
||||
true,
|
||||
@ -552,8 +553,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
},
|
||||
sdk.ZeroInt(),
|
||||
sdk.ZeroInt(),
|
||||
@ -562,23 +563,23 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
},
|
||||
{
|
||||
"errors if mint amount is negative",
|
||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-100)}},
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(50),
|
||||
true,
|
||||
sdkmath.NewInt(50),
|
||||
},
|
||||
{
|
||||
"adds to existing akava balance",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
||||
"adds to existing neuron balance",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(21_000_000_102),
|
||||
false,
|
||||
sdkmath.NewInt(100),
|
||||
},
|
||||
{
|
||||
"convert akava balance to ukava if it exceeds 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_999_000_000_000)),
|
||||
"convert neuron balance to a0gi if it exceeds 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_999_000_000_000)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(1_200_000_001),
|
||||
false,
|
||||
@ -589,8 +590,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
suite.FundModuleAccountWithKava(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin("akava", tt.akavaStart)))
|
||||
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, tt.neuronStart)))
|
||||
|
||||
err := suite.EvmBankKeeper.MintCoins(suite.Ctx, evmtypes.ModuleName, tt.mintCoins)
|
||||
if tt.hasErr {
|
||||
@ -600,13 +601,13 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check ukava
|
||||
ukavaActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ukava")
|
||||
suite.Require().Equal(tt.ukava, ukavaActual.Amount)
|
||||
// check a0gi
|
||||
a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.a0gi, a0giActual.Amount)
|
||||
|
||||
// check akava
|
||||
akavaActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.akava, akavaActual)
|
||||
// check neuron
|
||||
neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.neuron, neuronActual)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -619,22 +620,22 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
||||
}{
|
||||
{
|
||||
"valid coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"dup coins",
|
||||
sdk.Coins{sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("akava", 500)},
|
||||
sdk.Coins{sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin(chaincfg.BaseDenom, 500)},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"not evm coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 500)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"negative coins",
|
||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-500)}},
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-500)}},
|
||||
true,
|
||||
},
|
||||
}
|
||||
@ -650,8 +651,8 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
||||
akavaNeeded := sdkmath.NewInt(200)
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertOneA0giToNeuronIfNeeded() {
|
||||
neuronNeeded := sdkmath.NewInt(200)
|
||||
tests := []struct {
|
||||
name string
|
||||
startingCoins sdk.Coins
|
||||
@ -659,21 +660,21 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
||||
success bool
|
||||
}{
|
||||
{
|
||||
"not enough ukava for conversion",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
||||
"not enough a0gi for conversion",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts 1 ukava to akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 9), sdk.NewInt64Coin("akava", 1_000_000_000_100)),
|
||||
"converts 1 a0gi to neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 9), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_100)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"conversion not needed",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||
true,
|
||||
},
|
||||
}
|
||||
@ -681,67 +682,67 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingCoins)
|
||||
err := suite.EvmBankKeeper.ConvertOneUkavaToAkavaIfNeeded(suite.Ctx, suite.Addrs[0], akavaNeeded)
|
||||
moduleKava := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), "ukava")
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||
err := suite.EvmBankKeeper.ConvertOneA0giToNeuronIfNeeded(suite.Ctx, suite.Addrs[0], neuronNeeded)
|
||||
moduleZgChain := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), chaincfg.DisplayDenom)
|
||||
if tt.success {
|
||||
suite.Require().NoError(err)
|
||||
if tt.startingCoins.AmountOf("akava").LT(akavaNeeded) {
|
||||
suite.Require().Equal(sdk.OneInt(), moduleKava.Amount)
|
||||
if tt.startingCoins.AmountOf(chaincfg.BaseDenom).LT(neuronNeeded) {
|
||||
suite.Require().Equal(sdk.OneInt(), moduleZgChain.Amount)
|
||||
}
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
suite.Require().Equal(sdk.ZeroInt(), moduleKava.Amount)
|
||||
suite.Require().Equal(sdk.ZeroInt(), moduleZgChain.Amount)
|
||||
}
|
||||
|
||||
akava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
||||
ukava := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
||||
neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||
a0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertAkavaToUkava() {
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertNeuronToA0gi() {
|
||||
tests := []struct {
|
||||
name string
|
||||
startingCoins sdk.Coins
|
||||
expectedCoins sdk.Coins
|
||||
}{
|
||||
{
|
||||
"not enough ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100), sdk.NewInt64Coin("ukava", 0)),
|
||||
"not enough a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||
},
|
||||
{
|
||||
"converts akava for 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 1_000_000_000_003)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 11), sdk.NewInt64Coin("akava", 3)),
|
||||
"converts neuron for 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_003)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 11), sdk.NewInt64Coin(chaincfg.BaseDenom, 3)),
|
||||
},
|
||||
{
|
||||
"converts more than 1 ukava of akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 18), sdk.NewInt64Coin("akava", 123)),
|
||||
"converts more than 1 a0gi of neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 18), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||
suite.Require().NoError(err)
|
||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingCoins)
|
||||
err = suite.EvmBankKeeper.ConvertAkavaToUkava(suite.Ctx, suite.Addrs[0])
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||
err = suite.EvmBankKeeper.ConvertNeuronToA0gi(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().NoError(err)
|
||||
akava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
||||
ukava := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
||||
neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||
a0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
||||
func (suite *evmBankKeeperTestSuite) TestSplitNeuronCoins() {
|
||||
tests := []struct {
|
||||
name string
|
||||
coins sdk.Coins
|
||||
@ -750,7 +751,7 @@ func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
||||
}{
|
||||
{
|
||||
"invalid coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 500)),
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
@ -761,33 +762,33 @@ func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
||||
false,
|
||||
},
|
||||
{
|
||||
"ukava & akava coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 8), sdk.NewInt64Coin("akava", 123)),
|
||||
"a0gi & neuron coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 8), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"only akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_123)),
|
||||
"only neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"only ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 5_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 5)),
|
||||
"only a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 5)),
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
ukava, akava, err := keeper.SplitAkavaCoins(tt.coins)
|
||||
a0gi, neuron, err := keeper.SplitNeuronCoins(tt.coins)
|
||||
if tt.shouldErr {
|
||||
suite.Require().Error(err)
|
||||
} else {
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func (suite *convertCosmosCoinToERC20Suite) TestConvertCosmosCoinToERC20() {
|
||||
caller, key := testutil.RandomEvmAccount()
|
||||
query := func(method string, args ...interface{}) ([]interface{}, error) {
|
||||
return suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
key,
|
||||
contractAddress,
|
||||
@ -90,7 +90,7 @@ func (suite *convertCosmosCoinToERC20Suite) TestConvertCosmosCoinToERC20() {
|
||||
// make the denom allowed for conversion
|
||||
params := suite.Keeper.GetParams(suite.Ctx)
|
||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||
)
|
||||
suite.Keeper.SetParams(suite.Ctx, params)
|
||||
|
||||
@ -215,7 +215,7 @@ func (suite *convertCosmosCoinFromERC20Suite) SetupTest() {
|
||||
caller, key := testutil.RandomEvmAccount()
|
||||
suite.query = func(method string, args ...interface{}) ([]interface{}, error) {
|
||||
return suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
key,
|
||||
suite.contractAddress,
|
||||
|
@ -68,10 +68,10 @@ func (k Keeper) DeployTestMintableERC20Contract(
|
||||
return types.NewInternalEVMAddress(contractAddr), nil
|
||||
}
|
||||
|
||||
// DeployKavaWrappedCosmosCoinERC20Contract validates token details and then deploys an ERC20
|
||||
// DeployZgChainWrappedCosmosCoinERC20Contract validates token details and then deploys an ERC20
|
||||
// contract with the token metadata.
|
||||
// This method does NOT check if a token for the provided SdkDenom has already been deployed.
|
||||
func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
||||
func (k Keeper) DeployZgChainWrappedCosmosCoinERC20Contract(
|
||||
ctx sdk.Context,
|
||||
token types.AllowedCosmosCoinERC20Token,
|
||||
) (types.InternalEVMAddress, error) {
|
||||
@ -79,7 +79,7 @@ func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
||||
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to deploy erc20 for sdk denom %s", token.CosmosDenom)
|
||||
}
|
||||
|
||||
packedAbi, err := types.ERC20KavaWrappedCosmosCoinContract.ABI.Pack(
|
||||
packedAbi, err := types.ERC20ZgChainWrappedCosmosCoinContract.ABI.Pack(
|
||||
"", // Empty string for contract constructor
|
||||
token.Name,
|
||||
token.Symbol,
|
||||
@ -89,13 +89,13 @@ func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
||||
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to pack token with details %+v", token)
|
||||
}
|
||||
|
||||
data := make([]byte, len(types.ERC20KavaWrappedCosmosCoinContract.Bin)+len(packedAbi))
|
||||
data := make([]byte, len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin)+len(packedAbi))
|
||||
copy(
|
||||
data[:len(types.ERC20KavaWrappedCosmosCoinContract.Bin)],
|
||||
types.ERC20KavaWrappedCosmosCoinContract.Bin,
|
||||
data[:len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin)],
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.Bin,
|
||||
)
|
||||
copy(
|
||||
data[len(types.ERC20KavaWrappedCosmosCoinContract.Bin):],
|
||||
data[len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin):],
|
||||
packedAbi,
|
||||
)
|
||||
|
||||
@ -126,7 +126,7 @@ func (k *Keeper) GetOrDeployCosmosCoinERC20Contract(
|
||||
}
|
||||
|
||||
// deploy a new contract
|
||||
contractAddress, err := k.DeployKavaWrappedCosmosCoinERC20Contract(ctx, tokenInfo)
|
||||
contractAddress, err := k.DeployZgChainWrappedCosmosCoinERC20Contract(ctx, tokenInfo)
|
||||
if err != nil {
|
||||
return contractAddress, err
|
||||
}
|
||||
@ -170,7 +170,7 @@ func (k Keeper) BurnERC20(
|
||||
) error {
|
||||
_, err := k.CallEVM(
|
||||
ctx,
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
types.ModuleEVMAddress,
|
||||
contractAddr,
|
||||
erc20BurnMethod,
|
||||
@ -213,7 +213,7 @@ func (k Keeper) QueryERC20TotalSupply(
|
||||
) (*big.Int, error) {
|
||||
res, err := k.CallEVM(
|
||||
ctx,
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
types.ModuleEVMAddress,
|
||||
contractAddr,
|
||||
erc20TotalSupplyMethod,
|
||||
|
@ -107,11 +107,11 @@ func (suite *ERC20TestSuite) TestQueryERC20TotalSupply() {
|
||||
})
|
||||
}
|
||||
|
||||
func (suite *ERC20TestSuite) TestDeployKavaWrappedCosmosCoinERC20Contract() {
|
||||
func (suite *ERC20TestSuite) TestDeployZgChainWrappedCosmosCoinERC20Contract() {
|
||||
suite.Run("fails to deploy invalid contract", func() {
|
||||
// empty other fields means this token is invalid.
|
||||
invalidToken := types.AllowedCosmosCoinERC20Token{CosmosDenom: "nope"}
|
||||
_, err := suite.Keeper.DeployKavaWrappedCosmosCoinERC20Contract(suite.Ctx, invalidToken)
|
||||
_, err := suite.Keeper.DeployZgChainWrappedCosmosCoinERC20Contract(suite.Ctx, invalidToken)
|
||||
suite.ErrorContains(err, "token's name cannot be empty")
|
||||
})
|
||||
|
||||
@ -119,13 +119,13 @@ func (suite *ERC20TestSuite) TestDeployKavaWrappedCosmosCoinERC20Contract() {
|
||||
caller, privKey := testutil.RandomEvmAccount()
|
||||
|
||||
token := types.NewAllowedCosmosCoinERC20Token("hard", "EVM HARD", "HARD", 6)
|
||||
addr, err := suite.Keeper.DeployKavaWrappedCosmosCoinERC20Contract(suite.Ctx, token)
|
||||
addr, err := suite.Keeper.DeployZgChainWrappedCosmosCoinERC20Contract(suite.Ctx, token)
|
||||
suite.NoError(err)
|
||||
suite.NotNil(addr)
|
||||
|
||||
callContract := func(method string, args ...interface{}) ([]interface{}, error) {
|
||||
return suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
privKey,
|
||||
addr,
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
@ -50,7 +51,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant {
|
||||
})
|
||||
|
||||
bankAddr := authtypes.NewModuleAddress(types.ModuleName)
|
||||
bankBalance := bankK.GetBalance(ctx, bankAddr, CosmosDenom).Amount.Mul(ConversionMultiplier)
|
||||
bankBalance := bankK.GetBalance(ctx, bankAddr, chaincfg.DisplayDenom).Amount.Mul(ConversionMultiplier)
|
||||
|
||||
broken = totalMinorBalances.GT(bankBalance)
|
||||
|
||||
|
@ -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"
|
||||
@ -46,10 +47,10 @@ func (suite *invariantTestSuite) SetupValidState() {
|
||||
keeper.ConversionMultiplier.QuoRaw(2),
|
||||
))
|
||||
}
|
||||
suite.FundModuleAccountWithKava(
|
||||
suite.FundModuleAccountWithZgChain(
|
||||
types.ModuleName,
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin("ukava", sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||
sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||
),
|
||||
)
|
||||
|
||||
@ -159,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 ukava to avoid breaking other invariants
|
||||
amt := sdk.NewCoins(sdk.NewInt64Coin(keeper.CosmosDenom, 1))
|
||||
// add same number of a0gi to avoid breaking other invariants
|
||||
amt := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1))
|
||||
suite.Require().NoError(
|
||||
suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, amt),
|
||||
)
|
||||
@ -190,7 +191,7 @@ func (suite *invariantTestSuite) TestSendToModuleAccountNotAllowed() {
|
||||
ToAddress: maccAddress.String(),
|
||||
Amount: coins,
|
||||
})
|
||||
suite.ErrorContains(err, "kava1w9vxuke5dz6hyza2j932qgmxltnfxwl78u920k is not allowed to receive funds: unauthorized")
|
||||
suite.ErrorContains(err, "0g1w9vxuke5dz6hyza2j932qgmxltnfxwl78u920k is not allowed to receive funds: unauthorized")
|
||||
}
|
||||
|
||||
func (suite *invariantTestSuite) TestCosmosCoinsFullyBackedInvariant() {
|
||||
|
@ -115,7 +115,7 @@ func (k Keeper) SetAccount(ctx sdk.Context, account types.Account) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBalance returns the total balance of akava for a given account by address.
|
||||
// GetBalance returns the total balance of neuron 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 akava for a given account by address.
|
||||
// SetBalance sets the total balance of neuron 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 akava balance from sender addr to recipient addr.
|
||||
// SendBalance transfers the neuron 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 akava: %d", amt)
|
||||
return fmt.Errorf("cannot send a negative amount of neuron: %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 akava balance of an address.
|
||||
// AddBalance increments the neuron 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 akava balance of an address.
|
||||
// RemoveBalance decrements the neuron 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)
|
||||
@ -184,7 +184,7 @@ func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.
|
||||
return k.SetBalance(ctx, addr, finalBal)
|
||||
}
|
||||
|
||||
// SetDeployedCosmosCoinContract stores a single deployed ERC20KavaWrappedCosmosCoin contract address
|
||||
// SetDeployedCosmosCoinContract stores a single deployed ERC20ZgChainWrappedCosmosCoin contract address
|
||||
func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string, contractAddress types.InternalEVMAddress) error {
|
||||
if err := sdk.ValidateDenom(cosmosDenom); err != nil {
|
||||
return errorsmod.Wrap(types.ErrInvalidCosmosDenom, cosmosDenom)
|
||||
@ -203,7 +203,7 @@ func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom stri
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetDeployedCosmosCoinContract gets a deployed ERC20KavaWrappedCosmosCoin contract address by cosmos denom
|
||||
// SetDeployedCosmosCoinContract gets a deployed ERC20ZgChainWrappedCosmosCoin contract address by cosmos denom
|
||||
// Returns the stored address and a bool indicating if it was found or not
|
||||
func (k *Keeper) GetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string) (types.InternalEVMAddress, bool) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
@ -26,7 +26,7 @@ var _ types.MsgServer = msgServer{}
|
||||
////////////////////////////
|
||||
|
||||
// ConvertCoinToERC20 handles a MsgConvertCoinToERC20 message to convert
|
||||
// sdk.Coin to Kava EVM tokens.
|
||||
// sdk.Coin to 0gChain EVM tokens.
|
||||
func (s msgServer) ConvertCoinToERC20(
|
||||
goCtx context.Context,
|
||||
msg *types.MsgConvertCoinToERC20,
|
||||
@ -64,7 +64,7 @@ func (s msgServer) ConvertCoinToERC20(
|
||||
}
|
||||
|
||||
// ConvertERC20ToCoin handles a MsgConvertERC20ToCoin message to convert
|
||||
// sdk.Coin to Kava EVM tokens.
|
||||
// sdk.Coin to 0gChain EVM tokens.
|
||||
func (s msgServer) ConvertERC20ToCoin(
|
||||
goCtx context.Context,
|
||||
msg *types.MsgConvertERC20ToCoin,
|
||||
|
@ -34,7 +34,7 @@ func TestMsgServerSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *MsgServerSuite) TestConvertCoinToERC20() {
|
||||
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||
invoker, err := sdk.AccAddressFromBech32("0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
err = suite.App.FundAccount(suite.Ctx, invoker, sdk.NewCoins(sdk.NewCoin("erc20/usdc", sdkmath.NewInt(10000))))
|
||||
@ -282,7 +282,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
||||
// make the denom allowed for conversion
|
||||
params := suite.Keeper.GetParams(suite.Ctx)
|
||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||
)
|
||||
suite.Keeper.SetParams(suite.Ctx, params)
|
||||
|
||||
@ -331,7 +331,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
||||
{
|
||||
name: "invalid - bad initiator",
|
||||
msg: types.NewMsgConvertCosmosCoinToERC20(
|
||||
"invalid-kava-address",
|
||||
"invalid-0g-address",
|
||||
testutil.RandomEvmAddress().Hex(),
|
||||
sdk.NewInt64Coin(allowedDenom, 1e4),
|
||||
),
|
||||
@ -452,7 +452,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_AlreadyDeployedContrac
|
||||
// make the denom allowed for conversion
|
||||
params := suite.Keeper.GetParams(suite.Ctx)
|
||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||
)
|
||||
suite.Keeper.SetParams(suite.Ctx, params)
|
||||
|
||||
@ -499,7 +499,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_AlreadyDeployedContrac
|
||||
// check total supply
|
||||
caller, key := testutil.RandomEvmAccount()
|
||||
totalSupply, err := suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
key,
|
||||
contractAddress,
|
||||
@ -639,7 +639,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinFromERC20() {
|
||||
// expect erc20 total supply to reflect new value
|
||||
caller, key := testutil.RandomEvmAccount()
|
||||
totalSupply, err := suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
key,
|
||||
contractAddress,
|
||||
|
@ -66,9 +66,9 @@ func (suite *keeperTestSuite) TestGetAllowedTokenMetadata() {
|
||||
|
||||
atom := types.NewAllowedCosmosCoinERC20Token(
|
||||
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
|
||||
"Kava EVM ATOM", "ATOM", 6,
|
||||
"0gChain EVM ATOM", "ATOM", 6,
|
||||
)
|
||||
hard := types.NewAllowedCosmosCoinERC20Token("hard", "Kava EVM Hard", "HARD", 6)
|
||||
hard := types.NewAllowedCosmosCoinERC20Token("hard", "0gChain EVM Hard", "HARD", 6)
|
||||
|
||||
// init state with some allowed tokens
|
||||
params := suite.Keeper.GetParams(suite.Ctx)
|
||||
|
@ -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"
|
||||
)
|
||||
@ -81,14 +82,14 @@ func (suite *Suite) SetupTest() {
|
||||
suite.Addrs = addrs
|
||||
|
||||
evmGenesis := evmtypes.DefaultGenesisState()
|
||||
evmGenesis.Params.EvmDenom = "akava"
|
||||
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("ukava", 1000_000_000_000_000_000))
|
||||
coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 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()),
|
||||
@ -184,29 +185,29 @@ func (suite *Suite) ModuleBalance(denom string) sdk.Int {
|
||||
return suite.App.GetModuleAccountBalance(suite.Ctx, types.ModuleName, denom)
|
||||
}
|
||||
|
||||
func (suite *Suite) FundAccountWithKava(addr sdk.AccAddress, coins sdk.Coins) {
|
||||
ukava := coins.AmountOf("ukava")
|
||||
if ukava.IsPositive() {
|
||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin("ukava", ukava)))
|
||||
func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) {
|
||||
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||
if a0gi.IsPositive() {
|
||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
akava := coins.AmountOf("akava")
|
||||
if akava.IsPositive() {
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, akava)
|
||||
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||
if neuron.IsPositive() {
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *Suite) FundModuleAccountWithKava(moduleName string, coins sdk.Coins) {
|
||||
ukava := coins.AmountOf("ukava")
|
||||
if ukava.IsPositive() {
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin("ukava", ukava)))
|
||||
func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) {
|
||||
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||
if a0gi.IsPositive() {
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
akava := coins.AmountOf("akava")
|
||||
if akava.IsPositive() {
|
||||
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||
if neuron.IsPositive() {
|
||||
addr := suite.AccountKeeper.GetModuleAddress(moduleName)
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, akava)
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
}
|
||||
@ -217,7 +218,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress {
|
||||
suite.App.FundModuleAccount(
|
||||
suite.Ctx,
|
||||
types.ModuleName,
|
||||
sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(0))),
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18))
|
||||
@ -318,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(
|
||||
"ukava",
|
||||
chaincfg.DisplayDenom,
|
||||
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
|
||||
)))
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// InternalEVMAddress is a type alias of common.Address to represent an address
|
||||
// on the Kava EVM.
|
||||
// on the 0gChain EVM.
|
||||
type InternalEVMAddress struct {
|
||||
common.Address
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ var (
|
||||
// ERC20MintableBurnableAddress is the erc20 module address
|
||||
ERC20MintableBurnableAddress common.Address
|
||||
|
||||
//go:embed ethermint_json/ERC20KavaWrappedCosmosCoin.json
|
||||
ERC20KavaWrappedCosmosCoinJSON []byte
|
||||
//go:embed ethermint_json/ERC20ZgChainWrappedCosmosCoin.json
|
||||
ERC20ZgChainWrappedCosmosCoinJSON []byte
|
||||
|
||||
// ERC20KavaWrappedCosmosCoinContract is the compiled erc20 contract
|
||||
ERC20KavaWrappedCosmosCoinContract evmtypes.CompiledContract
|
||||
// ERC20ZgChainWrappedCosmosCoinContract is the compiled erc20 contract
|
||||
ERC20ZgChainWrappedCosmosCoinContract evmtypes.CompiledContract
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -53,12 +53,12 @@ func init() {
|
||||
panic("loading ERC20MintableBurnable contract failed")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(ERC20KavaWrappedCosmosCoinJSON, &ERC20KavaWrappedCosmosCoinContract)
|
||||
err = json.Unmarshal(ERC20ZgChainWrappedCosmosCoinJSON, &ERC20ZgChainWrappedCosmosCoinContract)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to unmarshal ERC20KavaWrappedCosmosCoinJSON: %s. %s", err, string(ERC20KavaWrappedCosmosCoinJSON)))
|
||||
panic(fmt.Sprintf("failed to unmarshal ERC20ZgChainWrappedCosmosCoinJSON: %s. %s", err, string(ERC20ZgChainWrappedCosmosCoinJSON)))
|
||||
}
|
||||
|
||||
if len(ERC20KavaWrappedCosmosCoinContract.Bin) == 0 {
|
||||
panic("loading ERC20KavaWrappedCosmosCoin contract failed")
|
||||
if len(ERC20ZgChainWrappedCosmosCoinContract.Bin) == 0 {
|
||||
panic("loading ERC20ZgChainWrappedCosmosCoin contract failed")
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user