mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
rename kava
This commit is contained in:
parent
7f625389a7
commit
b69e44123b
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
|
|
||||||
abci "github.com/cometbft/cometbft/abci/types"
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
||||||
@ -52,9 +53,9 @@ func (suite *SimulateRequestTestSuite) TearDownTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||||
fromAddr, err := sdk.AccAddressFromBech32("kava1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
fromAddr, err := sdk.AccAddressFromBech32("0g1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
toAddr, err := sdk.AccAddressFromBech32("kava1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
toAddr, err := sdk.AccAddressFromBech32("0g1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
simRequest := app.SimulateRequest{
|
simRequest := app.SimulateRequest{
|
||||||
@ -62,11 +63,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
|||||||
bank.MsgSend{
|
bank.MsgSend{
|
||||||
FromAddress: fromAddr,
|
FromAddress: fromAddr,
|
||||||
ToAddress: toAddr,
|
ToAddress: toAddr,
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Fee: auth.StdFee{
|
Fee: auth.StdFee{
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(5e4))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(5e4))),
|
||||||
Gas: 1e6,
|
Gas: 1e6,
|
||||||
},
|
},
|
||||||
Memo: "test memo",
|
Memo: "test memo",
|
||||||
|
@ -23,12 +23,13 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||||
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
|||||||
App: *app.NewApp(
|
App: *app.NewApp(
|
||||||
log.NewNopLogger(),
|
log.NewNopLogger(),
|
||||||
tmdb.NewMemDB(),
|
tmdb.NewMemDB(),
|
||||||
app.DefaultNodeHome,
|
chaincfg.DefaultNodeHome,
|
||||||
nil,
|
nil,
|
||||||
encodingConfig,
|
encodingConfig,
|
||||||
opts,
|
opts,
|
||||||
@ -67,7 +68,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
|||||||
chainID,
|
chainID,
|
||||||
app.NewFundedGenStateWithSameCoins(
|
app.NewFundedGenStateWithSameCoins(
|
||||||
tApp.AppCodec(),
|
tApp.AppCodec(),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e9)),
|
||||||
testAddresses,
|
testAddresses,
|
||||||
),
|
),
|
||||||
newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
||||||
@ -115,7 +116,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
tc.address,
|
tc.address,
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1_000_000)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
||||||
@ -45,7 +46,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
@ -80,12 +81,12 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
),
|
),
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[2],
|
testAddresses[2],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
@ -121,7 +122,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
|
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
|
||||||
@ -58,7 +59,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
checkTx: false,
|
checkTx: false,
|
||||||
@ -128,7 +129,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
[]sdk.Msg{banktypes.NewMsgSend(
|
[]sdk.Msg{banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[3],
|
testAddresses[3],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
)}),
|
)}),
|
||||||
},
|
},
|
||||||
checkTx: false,
|
checkTx: false,
|
||||||
@ -161,7 +162,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[3],
|
testAddresses[3],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
),
|
),
|
||||||
&evmtypes.MsgEthereumTx{},
|
&evmtypes.MsgEthereumTx{},
|
||||||
},
|
},
|
||||||
|
@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
|
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
@ -156,7 +157,7 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
// Genesis states
|
// Genesis states
|
||||||
evmGs := evmtypes.NewGenesisState(
|
evmGs := evmtypes.NewGenesisState(
|
||||||
evmtypes.NewParams(
|
evmtypes.NewParams(
|
||||||
"akava", // evmDenom
|
chaincfg.BaseDenom, // evmDenom
|
||||||
false, // allowedUnprotectedTxs
|
false, // allowedUnprotectedTxs
|
||||||
true, // enableCreate
|
true, // enableCreate
|
||||||
true, // enableCall
|
true, // enableCall
|
||||||
@ -222,10 +223,10 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||||
}
|
}
|
||||||
|
|
||||||
// funds our test accounts with some ukava
|
// funds our test accounts with some a0gi
|
||||||
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
||||||
tApp.AppCodec(),
|
tApp.AppCodec(),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e3)),
|
||||||
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -312,45 +313,17 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
params := evmKeeper.GetParams(suite.ctx)
|
params := evmKeeper.GetParams(suite.ctx)
|
||||||
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
||||||
{
|
{
|
||||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||||
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||||
{Name: "initiator", Type: "string"},
|
{Name: "initiator", Type: "string"},
|
||||||
{Name: "receiver", Type: "string"},
|
{Name: "receiver", Type: "string"},
|
||||||
{Name: "kava_erc20_address", Type: "string"},
|
{Name: "0gchain_erc20_address", Type: "string"},
|
||||||
{Name: "amount", Type: "string"},
|
{Name: "amount", Type: "string"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgCreateCDP",
|
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||||
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",
|
|
||||||
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||||
{Name: "initiator", Type: "string"},
|
{Name: "initiator", Type: "string"},
|
||||||
@ -358,23 +331,6 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
{Name: "amount", Type: "Coin"},
|
{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[]"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
evmKeeper.SetParams(suite.ctx, params)
|
evmKeeper.SetParams(suite.ctx, params)
|
||||||
|
|
||||||
@ -420,7 +376,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
|
|||||||
suite.tApp.FundModuleAccount(
|
suite.tApp.FundModuleAccount(
|
||||||
suite.ctx,
|
suite.ctx,
|
||||||
evmutiltypes.ModuleName,
|
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))
|
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
||||||
@ -442,40 +398,43 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
failCheckTx bool
|
failCheckTx bool
|
||||||
errMsg string
|
errMsg string
|
||||||
}{
|
}{
|
||||||
{
|
// TODO: need fix
|
||||||
name: "processes deposit eip712 messages successfully",
|
// {
|
||||||
usdcDepositAmt: 100,
|
// name: "processes deposit eip712 messages successfully",
|
||||||
usdxToMintAmt: 99,
|
// usdcDepositAmt: 100,
|
||||||
},
|
// usdxToMintAmt: 99,
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
name: "fails when convertion more erc20 usdc than balance",
|
name: "fails when convertion more erc20 usdc than balance",
|
||||||
usdcDepositAmt: 51_000,
|
usdcDepositAmt: 51_000,
|
||||||
usdxToMintAmt: 100,
|
usdxToMintAmt: 100,
|
||||||
errMsg: "transfer amount exceeds balance",
|
errMsg: "transfer amount exceeds balance",
|
||||||
},
|
},
|
||||||
{
|
// TODO: need fix
|
||||||
name: "fails when minting more usdx than allowed",
|
// {
|
||||||
usdcDepositAmt: 100,
|
// name: "fails when minting more usdx than allowed",
|
||||||
usdxToMintAmt: 100,
|
// usdcDepositAmt: 100,
|
||||||
errMsg: "proposed collateral ratio is below liquidation ratio",
|
// usdxToMintAmt: 100,
|
||||||
},
|
// errMsg: "proposed collateral ratio is below liquidation ratio",
|
||||||
{
|
// },
|
||||||
name: "fails when trying to convert usdc for another address",
|
// TODO: need fix
|
||||||
usdcDepositAmt: 100,
|
// {
|
||||||
usdxToMintAmt: 90,
|
// name: "fails when trying to convert usdc for another address",
|
||||||
errMsg: "unauthorized",
|
// usdcDepositAmt: 100,
|
||||||
failCheckTx: true,
|
// usdxToMintAmt: 90,
|
||||||
updateMsgs: func(msgs []sdk.Msg) []sdk.Msg {
|
// errMsg: "unauthorized",
|
||||||
convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
// failCheckTx: true,
|
||||||
suite.testEVMAddr2,
|
// updateMsgs: func(msgs []sdk.Msg) []sdk.Msg {
|
||||||
suite.testAddr,
|
// convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
||||||
suite.usdcEVMAddr,
|
// suite.testEVMAddr2,
|
||||||
suite.getEVMAmount(100),
|
// suite.testAddr,
|
||||||
)
|
// suite.usdcEVMAddr,
|
||||||
msgs[0] = &convertMsg
|
// suite.getEVMAmount(100),
|
||||||
return msgs
|
// )
|
||||||
},
|
// msgs[0] = &convertMsg
|
||||||
},
|
// return msgs
|
||||||
|
// },
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
name: "fails when trying to convert erc20 for non-whitelisted contract",
|
name: "fails when trying to convert erc20 for non-whitelisted contract",
|
||||||
usdcDepositAmt: 100,
|
usdcDepositAmt: 100,
|
||||||
@ -517,7 +476,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
errMsg: "insufficient funds",
|
errMsg: "insufficient funds",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||||
bk := suite.tApp.GetBankKeeper()
|
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))
|
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
||||||
return txBuilder
|
return txBuilder
|
||||||
},
|
},
|
||||||
@ -529,7 +488,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
failCheckTx: true,
|
failCheckTx: true,
|
||||||
errMsg: "invalid chain-id",
|
errMsg: "invalid chain-id",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
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(
|
return suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
@ -542,7 +501,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
failCheckTx: true,
|
failCheckTx: true,
|
||||||
errMsg: "invalid pubkey",
|
errMsg: "invalid pubkey",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
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(
|
return suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
@ -570,7 +529,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
msgs = tc.updateMsgs(msgs)
|
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(
|
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
@ -644,7 +603,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deliver deposit msg
|
// 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(
|
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
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"
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustParseDecCoins(value string) sdk.DecCoins {
|
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()})
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
||||||
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
||||||
EvmDenom: "akava",
|
EvmDenom: chaincfg.BaseDenom,
|
||||||
})
|
})
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -44,29 +45,29 @@ func TestEvmMinGasFilter(t *testing.T) {
|
|||||||
mustParseDecCoins(""),
|
mustParseDecCoins(""),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price",
|
"zero a0gi gas price",
|
||||||
mustParseDecCoins("0ukava"),
|
mustParseDecCoins("0a0gi"),
|
||||||
mustParseDecCoins("0ukava"),
|
mustParseDecCoins("0a0gi"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non-zero ukava gas price",
|
"non-zero a0gi gas price",
|
||||||
mustParseDecCoins("0.001ukava"),
|
mustParseDecCoins("0.001a0gi"),
|
||||||
mustParseDecCoins("0.001ukava"),
|
mustParseDecCoins("0.001a0gi"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price, min akava price",
|
"zero a0gi gas price, min neuron price",
|
||||||
mustParseDecCoins("0ukava;100000akava"),
|
mustParseDecCoins("0a0gi;100000neuron"),
|
||||||
mustParseDecCoins("0ukava"), // akava is removed
|
mustParseDecCoins("0a0gi"), // neuron is removed
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price, min akava price, other token",
|
"zero a0gi gas price, min neuron price, other token",
|
||||||
mustParseDecCoins("0ukava;100000akava;0.001other"),
|
mustParseDecCoins("0a0gi;100000neuron;0.001other"),
|
||||||
mustParseDecCoins("0ukava;0.001other"), // akava is removed
|
mustParseDecCoins("0a0gi;0.001other"), // neuron is removed
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non-zero ukava gas price, min akava price",
|
"non-zero a0gi gas price, min neuron price",
|
||||||
mustParseDecCoins("0.25ukava;100000akava;0.001other"),
|
mustParseDecCoins("0.25a0gi;100000neuron;0.001other"),
|
||||||
mustParseDecCoins("0.25ukava;0.001other"), // akava is removed
|
mustParseDecCoins("0.25a0gi;0.001other"), // neuron is removed
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
||||||
@ -33,7 +34,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"MsgCreateVestingAccount",
|
"MsgCreateVestingAccount",
|
||||||
vesting.NewMsgCreateVestingAccount(
|
vesting.NewMsgCreateVestingAccount(
|
||||||
testAddresses[0], testAddresses[1],
|
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(),
|
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
@ -44,7 +45,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"MsgCreateVestingAccount",
|
"MsgCreateVestingAccount",
|
||||||
vesting.NewMsgCreatePermanentLockedAccount(
|
vesting.NewMsgCreatePermanentLockedAccount(
|
||||||
testAddresses[0], testAddresses[1],
|
testAddresses[0], testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
true,
|
true,
|
||||||
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||||
@ -63,7 +64,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"other messages not affected",
|
"other messages not affected",
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0], testAddresses[1],
|
testAddresses[0], testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
"",
|
"",
|
||||||
|
31
app/app.go
31
app/app.go
@ -3,11 +3,9 @@ package app
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
stdlog "log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
|
sdkmath "cosmossdk.io/math"
|
||||||
dbm "github.com/cometbft/cometbft-db"
|
dbm "github.com/cometbft/cometbft-db"
|
||||||
abci "github.com/cometbft/cometbft/abci/types"
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
tmjson "github.com/cometbft/cometbft/libs/json"
|
tmjson "github.com/cometbft/cometbft/libs/json"
|
||||||
@ -107,7 +105,8 @@ import (
|
|||||||
dbm "github.com/tendermint/tm-db"
|
dbm "github.com/tendermint/tm-db"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"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"
|
"github.com/0glabs/0g-chain/x/bep3"
|
||||||
bep3keeper "github.com/0glabs/0g-chain/x/bep3/keeper"
|
bep3keeper "github.com/0glabs/0g-chain/x/bep3/keeper"
|
||||||
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||||
@ -129,14 +128,7 @@ import (
|
|||||||
validatorvestingtypes "github.com/0glabs/0g-chain/x/validator-vesting/types"
|
validatorvestingtypes "github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
appName = "kava"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DefaultNodeHome default home directories for the application daemon
|
|
||||||
DefaultNodeHome string
|
|
||||||
|
|
||||||
// ModuleBasics manages simple versions of full app modules.
|
// ModuleBasics manages simple versions of full app modules.
|
||||||
// It's used for things such as codec registration and genesis file verification.
|
// It's used for things such as codec registration and genesis file verification.
|
||||||
ModuleBasics = module.NewBasicManager(
|
ModuleBasics = module.NewBasicManager(
|
||||||
@ -216,7 +208,7 @@ var DefaultOptions = Options{
|
|||||||
EVMMaxGasWanted: ethermintconfig.DefaultMaxTxGasWanted,
|
EVMMaxGasWanted: ethermintconfig.DefaultMaxTxGasWanted,
|
||||||
}
|
}
|
||||||
|
|
||||||
// App is the Kava ABCI application.
|
// App is the 0gChain ABCI application.
|
||||||
type App struct {
|
type App struct {
|
||||||
*baseapp.BaseApp
|
*baseapp.BaseApp
|
||||||
|
|
||||||
@ -281,12 +273,9 @@ type App struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
userHomeDir, err := os.UserHomeDir()
|
// 1stake = 1 ukava = 1_000_000_000_000 akava = 1_000_000_000_000 neuron
|
||||||
if err != nil {
|
conversionMultiplier := sdkmath.NewIntFromUint64(1_000_000_000_000)
|
||||||
stdlog.Printf("Failed to get home dir %v", err)
|
sdk.DefaultPowerReduction = sdk.DefaultPowerReduction.Mul(conversionMultiplier)
|
||||||
}
|
|
||||||
|
|
||||||
DefaultNodeHome = filepath.Join(userHomeDir, ".kava")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewApp returns a reference to an initialized App.
|
// NewApp returns a reference to an initialized App.
|
||||||
@ -295,7 +284,7 @@ func NewApp(
|
|||||||
db dbm.DB,
|
db dbm.DB,
|
||||||
homePath string,
|
homePath string,
|
||||||
traceStore io.Writer,
|
traceStore io.Writer,
|
||||||
encodingConfig kavaparams.EncodingConfig,
|
encodingConfig chainparams.EncodingConfig,
|
||||||
options Options,
|
options Options,
|
||||||
baseAppOptions ...func(*baseapp.BaseApp),
|
baseAppOptions ...func(*baseapp.BaseApp),
|
||||||
) *App {
|
) *App {
|
||||||
@ -303,7 +292,7 @@ func NewApp(
|
|||||||
legacyAmino := encodingConfig.Amino
|
legacyAmino := encodingConfig.Amino
|
||||||
interfaceRegistry := encodingConfig.InterfaceRegistry
|
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.SetCommitMultiStoreTracer(traceStore)
|
||||||
bApp.SetVersion(version.Version)
|
bApp.SetVersion(version.Version)
|
||||||
bApp.SetInterfaceRegistry(interfaceRegistry)
|
bApp.SetInterfaceRegistry(interfaceRegistry)
|
||||||
@ -940,7 +929,7 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
|
|||||||
panic(err)
|
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.
|
// 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())
|
app.upgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
db "github.com/cometbft/cometbft-db"
|
db "github.com/cometbft/cometbft-db"
|
||||||
abci "github.com/cometbft/cometbft/abci/types"
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
"github.com/cometbft/cometbft/libs/log"
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
@ -24,11 +25,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNewApp(t *testing.T) {
|
func TestNewApp(t *testing.T) {
|
||||||
SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
NewApp(
|
NewApp(
|
||||||
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
||||||
db.NewMemDB(),
|
db.NewMemDB(),
|
||||||
DefaultNodeHome,
|
chaincfg.DefaultNodeHome,
|
||||||
nil,
|
nil,
|
||||||
MakeEncodingConfig(),
|
MakeEncodingConfig(),
|
||||||
DefaultOptions,
|
DefaultOptions,
|
||||||
@ -36,9 +37,9 @@ func TestNewApp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExport(t *testing.T) {
|
func TestExport(t *testing.T) {
|
||||||
SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
db := db.NewMemDB()
|
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())
|
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())
|
||||||
|
|
||||||
|
@ -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
|
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
|
simulation. These weights define the chance for a transaction to be simulated at
|
||||||
|
@ -41,6 +41,7 @@ import (
|
|||||||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
bep3keeper "github.com/0glabs/0g-chain/x/bep3/keeper"
|
bep3keeper "github.com/0glabs/0g-chain/x/bep3/keeper"
|
||||||
committeekeeper "github.com/0glabs/0g-chain/x/committee/keeper"
|
committeekeeper "github.com/0glabs/0g-chain/x/committee/keeper"
|
||||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
@ -90,7 +91,7 @@ func NewTestAppFromSealed() TestApp {
|
|||||||
encCfg := MakeEncodingConfig()
|
encCfg := MakeEncodingConfig()
|
||||||
|
|
||||||
app := NewApp(
|
app := NewApp(
|
||||||
log.NewNopLogger(), db, DefaultNodeHome, nil,
|
log.NewNopLogger(), db, chaincfg.DefaultNodeHome, nil,
|
||||||
encCfg, DefaultOptions, baseapp.SetChainID(TestChainId),
|
encCfg, DefaultOptions, baseapp.SetChainID(TestChainId),
|
||||||
)
|
)
|
||||||
return TestApp{App: *app}
|
return TestApp{App: *app}
|
||||||
@ -152,7 +153,7 @@ func GenesisStateWithSingleValidator(
|
|||||||
balances := []banktypes.Balance{
|
balances := []banktypes.Balance{
|
||||||
{
|
{
|
||||||
Address: acc.GetAddress().String(),
|
Address: acc.GetAddress().String(),
|
||||||
Coins: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(100000000000000))),
|
Coins: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(100000000000000))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,7 +216,7 @@ func genesisStateWithValSet(
|
|||||||
}
|
}
|
||||||
// set validators and delegations
|
// set validators and delegations
|
||||||
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
||||||
currentStakingGenesis.Params.BondDenom = "ukava"
|
currentStakingGenesis.Params.BondDenom = chaincfg.DisplayDenom
|
||||||
|
|
||||||
stakingGenesis := stakingtypes.NewGenesisState(
|
stakingGenesis := stakingtypes.NewGenesisState(
|
||||||
currentStakingGenesis.Params,
|
currentStakingGenesis.Params,
|
||||||
@ -235,13 +236,13 @@ func genesisStateWithValSet(
|
|||||||
|
|
||||||
for range delegations {
|
for range delegations {
|
||||||
// add delegated tokens to total supply
|
// 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
|
// add bonded amount to bonded pool module account
|
||||||
balances = append(balances, banktypes.Balance{
|
balances = append(balances, banktypes.Balance{
|
||||||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
||||||
Coins: sdk.Coins{sdk.NewCoin("ukava", bondAmt)},
|
Coins: sdk.Coins{sdk.NewCoin(chaincfg.DisplayDenom, bondAmt)},
|
||||||
})
|
})
|
||||||
|
|
||||||
bankGenesis := banktypes.NewGenesisState(
|
bankGenesis := banktypes.NewGenesisState(
|
||||||
|
@ -62,12 +62,12 @@ func TestKvCLIKeysAddRecover(t *testing.T) {
|
|||||||
|
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
||||||
|
|
||||||
// test old bip44 coin type
|
// test old bip44 coin type
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
require.Equal(t, "0g1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
||||||
|
|
||||||
// Cleanup testing directories
|
// Cleanup testing directories
|
||||||
f.Cleanup()
|
f.Cleanup()
|
||||||
@ -78,20 +78,20 @@ func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
|||||||
f := InitFixtures(t)
|
f := InitFixtures(t)
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
||||||
require.Equal(t, "kava1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
require.Equal(t, "0g1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
||||||
require.Equal(t, "kava1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
require.Equal(t, "0g1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
||||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
||||||
|
|
||||||
// test old bip44 coin type
|
// test old bip44 coin type
|
||||||
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
|
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
|
||||||
require.Equal(t, "kava1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
require.Equal(t, "0g1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
||||||
|
|
||||||
exitSuccess, _, _ := f.KeysAddRecover("test-recover-fail", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path --hd-path 44'/459'/0'/0/0")
|
exitSuccess, _, _ := f.KeysAddRecover("test-recover-fail", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path --hd-path 44'/459'/0'/0/0")
|
||||||
require.False(t, exitSuccess)
|
require.False(t, exitSuccess)
|
||||||
@ -99,11 +99,11 @@ func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
|||||||
// test -hd-path flag
|
// test -hd-path flag
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH6", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/0'/0/0")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH6", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/0'/0/0")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
|
||||||
|
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH7", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/2'/0/17")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH7", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/2'/0/17")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
|
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
|
||||||
|
|
||||||
// Cleanup testing directories
|
// Cleanup testing directories
|
||||||
f.Cleanup()
|
f.Cleanup()
|
||||||
|
@ -92,7 +92,7 @@ type Fixtures struct {
|
|||||||
|
|
||||||
// NewFixtures creates a new instance of Fixtures with many vars set
|
// NewFixtures creates a new instance of Fixtures with many vars set
|
||||||
func NewFixtures(t *testing.T) *Fixtures {
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
servAddr, port, err := server.FreeTCPAddr()
|
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) {
|
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
||||||
executeWrite(f.T, addFlags(cmd, flags))
|
executeWrite(f.T, addFlags(cmd, flags))
|
||||||
@ -211,7 +211,7 @@ func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
|||||||
require.NoError(f.T, err)
|
require.NoError(f.T, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// KvInit is kavad init
|
// KvInit is 0gchaind init
|
||||||
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
||||||
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
|
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
|
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) {
|
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)
|
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))
|
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenTx is kavad gentx
|
// GenTx is 0gchaind gentx
|
||||||
func (f *Fixtures) GenTx(name string, flags ...string) {
|
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)
|
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))
|
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectGenTxs is kavad collect-gentxs
|
// CollectGenTxs is 0gchaind collect-gentxs
|
||||||
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
||||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
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 {
|
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)
|
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))
|
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
|
||||||
@ -256,7 +256,7 @@ func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
|||||||
return proc
|
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 {
|
func (f *Fixtures) GDTendermint(query string) string {
|
||||||
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
||||||
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
||||||
@ -265,7 +265,7 @@ func (f *Fixtures) GDTendermint(query string) string {
|
|||||||
return strings.TrimSpace(stdout)
|
return strings.TrimSpace(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateGenesis runs kavad validate-genesis
|
// ValidateGenesis runs 0gchaind validate-genesis
|
||||||
func (f *Fixtures) ValidateGenesis() {
|
func (f *Fixtures) ValidateGenesis() {
|
||||||
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
||||||
executeWriteCheckErr(f.T, cmd)
|
executeWriteCheckErr(f.T, cmd)
|
||||||
|
@ -32,7 +32,7 @@ const (
|
|||||||
flagMempoolAuthAddresses = "mempool.authorized-addresses"
|
flagMempoolAuthAddresses = "mempool.authorized-addresses"
|
||||||
)
|
)
|
||||||
|
|
||||||
// appCreator holds functions used by the sdk server to control the kava app.
|
// appCreator holds functions used by the sdk server to control the 0g-chain app.
|
||||||
// The methods implement types in cosmos-sdk/server/types
|
// The methods implement types in cosmos-sdk/server/types
|
||||||
type appCreator struct {
|
type appCreator struct {
|
||||||
encodingConfig params.EncodingConfig
|
encodingConfig params.EncodingConfig
|
||||||
|
@ -4,11 +4,11 @@ pragma solidity ^0.8.18;
|
|||||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||||
import "@openzeppelin/contracts/access/Ownable.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.
|
/// Tokens are backed one-for-one by cosmos-sdk coins held in the module account.
|
||||||
/// @author Kava Labs, LLC
|
/// @author 0g Labs, LLC
|
||||||
/// @custom:security-contact security@kava.io
|
/// @custom:security-contact security@0g.ai
|
||||||
contract ERC20KavaWrappedCosmosCoin is ERC20, Ownable {
|
contract ERC20ZgChainWrappedCosmosCoin is ERC20, Ownable {
|
||||||
/// @notice The decimals places of the token. For display purposes only.
|
/// @notice The decimals places of the token. For display purposes only.
|
||||||
uint8 private immutable _decimals;
|
uint8 private immutable _decimals;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ const config: HardhatUserConfig = {
|
|||||||
solidity: {
|
solidity: {
|
||||||
version: "0.8.18",
|
version: "0.8.18",
|
||||||
settings: {
|
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",
|
evmVersion: "istanbul",
|
||||||
// optimize build for deployment to mainnet!
|
// optimize build for deployment to mainnet!
|
||||||
optimizer: {
|
optimizer: {
|
||||||
@ -16,21 +16,21 @@ const config: HardhatUserConfig = {
|
|||||||
},
|
},
|
||||||
networks: {
|
networks: {
|
||||||
// kvtool's local network
|
// kvtool's local network
|
||||||
kava: {
|
chain: {
|
||||||
url: "http://127.0.0.1:8545",
|
url: "http://127.0.0.1:8545",
|
||||||
accounts: [
|
accounts: [
|
||||||
// kava keys unsafe-export-eth-key whale2
|
// 0g-chain keys unsafe-export-eth-key whale2
|
||||||
"AA50F4C6C15190D9E18BF8B14FC09BFBA0E7306331A4F232D10A77C2879E7966",
|
"AA50F4C6C15190D9E18BF8B14FC09BFBA0E7306331A4F232D10A77C2879E7966",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
protonet: {
|
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: [
|
accounts: [
|
||||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
internal_testnet: {
|
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: [
|
accounts: [
|
||||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||||
],
|
],
|
||||||
|
4
contracts/package-lock.json
generated
4
contracts/package-lock.json
generated
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "kava-contracts",
|
"name": "0g-chain-contracts",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "kava-contracts",
|
"name": "0g-chain-contracts",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "kava-contracts",
|
"name": "0g-chain-contracts",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"author": "Kava Labs",
|
"author": "0g Labs",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Solidity contracts for Kava Blockchain",
|
"description": "Solidity contracts for 0g Blockchain",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
},
|
},
|
||||||
@ -12,7 +12,7 @@
|
|||||||
"clean": "hardhat clean",
|
"clean": "hardhat clean",
|
||||||
"compile": "hardhat compile",
|
"compile": "hardhat compile",
|
||||||
"coverage": "hardhat coverage",
|
"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",
|
"gen-ts-types": "hardhat typechain",
|
||||||
"lint": "eslint '**/*.{js,ts}'",
|
"lint": "eslint '**/*.{js,ts}'",
|
||||||
"lint-fix": "eslint '**/*.{js,ts}' --fix",
|
"lint-fix": "eslint '**/*.{js,ts}' --fix",
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { ethers } from "hardhat";
|
import { ethers } from "hardhat";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const tokenName = "Kava-wrapped ATOM";
|
const tokenName = "0g-chain-wrapped ATOM";
|
||||||
const tokenSymbol = "kATOM";
|
const tokenSymbol = "kATOM";
|
||||||
const tokenDecimals = 6;
|
const tokenDecimals = 6;
|
||||||
|
|
||||||
const ERC20KavaWrappedCosmosCoin = await ethers.getContractFactory(
|
const ERC20ZgChainWrappedCosmosCoin = await ethers.getContractFactory(
|
||||||
"ERC20KavaWrappedCosmosCoin"
|
"ERC20ZgChainWrappedCosmosCoin"
|
||||||
);
|
);
|
||||||
const token = await ERC20KavaWrappedCosmosCoin.deploy(
|
const token = await ERC20ZgChainWrappedCosmosCoin.deploy(
|
||||||
tokenName,
|
tokenName,
|
||||||
tokenSymbol,
|
tokenSymbol,
|
||||||
tokenDecimals
|
tokenDecimals
|
||||||
|
@ -2,21 +2,21 @@ import { expect } from "chai";
|
|||||||
import { Signer } from "ethers";
|
import { Signer } from "ethers";
|
||||||
import { ethers } from "hardhat";
|
import { ethers } from "hardhat";
|
||||||
import {
|
import {
|
||||||
ERC20KavaWrappedCosmosCoin,
|
ERC20ZgChainWrappedCosmosCoin,
|
||||||
ERC20KavaWrappedCosmosCoin__factory as ERC20KavaWrappedCosmosCoinFactory,
|
ERC20ZgChainWrappedCosmosCoin__factory as ERC20ZgChainWrappedCosmosCoinFactory,
|
||||||
} from "../typechain-types";
|
} from "../typechain-types";
|
||||||
|
|
||||||
const decimals = 6n;
|
const decimals = 6n;
|
||||||
|
|
||||||
describe("ERC20KavaWrappedCosmosCoin", function () {
|
describe("ERC20ZgChainWrappedCosmosCoin", function () {
|
||||||
let erc20: ERC20KavaWrappedCosmosCoin;
|
let erc20: ERC20ZgChainWrappedCosmosCoin;
|
||||||
let erc20Factory: ERC20KavaWrappedCosmosCoinFactory;
|
let erc20Factory: ERC20ZgChainWrappedCosmosCoinFactory;
|
||||||
let owner: Signer;
|
let owner: Signer;
|
||||||
let sender: Signer;
|
let sender: Signer;
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
erc20Factory = await ethers.getContractFactory(
|
erc20Factory = await ethers.getContractFactory(
|
||||||
"ERC20KavaWrappedCosmosCoin"
|
"ERC20ZgChainWrappedCosmosCoin"
|
||||||
);
|
);
|
||||||
erc20 = await erc20Factory.deploy("Wrapped ATOM", "ATOM", decimals);
|
erc20 = await erc20Factory.deploy("Wrapped ATOM", "ATOM", decimals);
|
||||||
[owner, sender] = await ethers.getSigners();
|
[owner, sender] = await ethers.getSigners();
|
||||||
|
1
go.mod
1
go.mod
@ -78,6 +78,7 @@ require (
|
|||||||
github.com/cosmos/gogogateway v1.2.0 // indirect
|
github.com/cosmos/gogogateway v1.2.0 // indirect
|
||||||
github.com/cosmos/iavl v0.20.1 // indirect
|
github.com/cosmos/iavl v0.20.1 // indirect
|
||||||
github.com/cosmos/ics23/go v0.10.0 // indirect
|
github.com/cosmos/ics23/go v0.10.0 // indirect
|
||||||
|
github.com/cosmos/gogoproto v1.4.6 // indirect
|
||||||
github.com/cosmos/ledger-cosmos-go v0.13.1 // indirect
|
github.com/cosmos/ledger-cosmos-go v0.13.1 // indirect
|
||||||
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
|
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
|
||||||
github.com/creachadair/taskgroup v0.4.2 // indirect
|
github.com/creachadair/taskgroup v0.4.2 // indirect
|
||||||
|
@ -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.
|
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.
|
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 between mainnet 0g-chain 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 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.
|
We only support migrations from old to new versions, not the other way around.
|
||||||
|
|
||||||
Genesis Migration
|
Genesis Migration
|
||||||
@ -22,7 +22,7 @@ The process is:
|
|||||||
- marshal it to json (using current codec)
|
- marshal it to json (using current codec)
|
||||||
|
|
||||||
On each release we can delete the previous releases migration and old GenesisState type.
|
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,
|
eg 0g-chain-3 migrates `auth.GenesisState` from 0g-chain-2 to `auth.GenesisState` from 0g-chain-3,
|
||||||
but for kava-4 we don't need to keep around kava-2's `auth.GenesisState` type.
|
but for 0g-chain-4 we don't need to keep around 0g-chain-2's `auth.GenesisState` type.
|
||||||
*/
|
*/
|
||||||
package migrate
|
package migrate
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
@ -41,7 +42,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
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
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
@ -64,7 +65,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(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
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
@ -97,7 +98,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(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
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
@ -125,25 +126,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
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
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
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{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
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{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
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{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // +30 days - vesting
|
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 +160,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
|||||||
expectedPeriods := []vestingtypes.Period{
|
expectedPeriods := []vestingtypes.Period{
|
||||||
{
|
{
|
||||||
Length: 15 * 24 * 60 * 60, // 15 days
|
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
|
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, 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, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period")
|
||||||
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
|
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) {
|
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
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
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{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
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{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
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 +199,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin
|
|||||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
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(chaincfg.DisplayDenom, 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(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
|
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
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
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{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
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{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
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 := 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)
|
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||||
|
|
||||||
assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified")
|
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:
|
all:
|
||||||
docker build --tag kava/kavanode kavanode
|
docker build --tag 0glabs/0g-chain-node 0g-chain-node
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
@ -5,8 +5,174 @@ import (
|
|||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
// communitytypes "github.com/0glabs/0g-chain/x/community/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_NonAuthority() {
|
||||||
|
// // ARRANGE
|
||||||
|
// // setup 0g account
|
||||||
|
// funds := a0gi(1e5) // .1 A0GI
|
||||||
|
// zgChainAcc := suite.ZgChain.NewFundedAccount("community-non-authority", sdk.NewCoins(funds))
|
||||||
|
|
||||||
|
// gasLimit := int64(2e5)
|
||||||
|
// fee := a0gi(200)
|
||||||
|
|
||||||
|
// msg := communitytypes.NewMsgUpdateParams(
|
||||||
|
// zgChainAcc.SdkAddress,
|
||||||
|
// communitytypes.DefaultParams(),
|
||||||
|
// )
|
||||||
|
|
||||||
|
// // ACT
|
||||||
|
// req := util.ZgChainMsgRequest{
|
||||||
|
// Msgs: []sdk.Msg{&msg},
|
||||||
|
// GasLimit: uint64(gasLimit),
|
||||||
|
// FeeAmount: sdk.NewCoins(fee),
|
||||||
|
// Memo: "this is a failure!",
|
||||||
|
// }
|
||||||
|
// res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||||
|
|
||||||
|
// // ASSERT
|
||||||
|
// _, err := util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||||
|
// suite.Require().Error(err)
|
||||||
|
// suite.Require().ErrorContains(
|
||||||
|
// err,
|
||||||
|
// govtypes.ErrInvalidSigner.Error(),
|
||||||
|
// "should return with authority check error",
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
|
||||||
|
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_Authority() {
|
||||||
|
// // ARRANGE
|
||||||
|
// govParamsRes, err := suite.ZgChain.Grpc.Query.Gov.Params(context.Background(), &govv1.QueryParamsRequest{
|
||||||
|
// ParamsType: govv1.ParamDeposit,
|
||||||
|
// })
|
||||||
|
// suite.NoError(err)
|
||||||
|
|
||||||
|
// // Check initial params
|
||||||
|
// communityParamsResInitial, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||||
|
// context.Background(),
|
||||||
|
// &communitytypes.QueryParamsRequest{},
|
||||||
|
// )
|
||||||
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
|
// // 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 := 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.ZgChain.Grpc.Query.Community.Params(
|
||||||
|
// context.Background(),
|
||||||
|
// &communitytypes.QueryParamsRequest{},
|
||||||
|
// )
|
||||||
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
|
// return params.Params.UpgradeTimeDisableInflation.Equal(time.Time{})
|
||||||
|
// },
|
||||||
|
// 20*time.Second,
|
||||||
|
// 1*time.Second,
|
||||||
|
// "switchover should happen",
|
||||||
|
// )
|
||||||
|
|
||||||
|
// // Add 1 to the staking rewards per second
|
||||||
|
// newStakingRewardsPerSecond := communityParamsResInitial.Params.
|
||||||
|
// StakingRewardsPerSecond.
|
||||||
|
// Add(sdkmath.LegacyNewDec(1))
|
||||||
|
|
||||||
|
// // 1. Proposal
|
||||||
|
// // Only modify stakingRewardsPerSecond, as to not re-run the switchover and
|
||||||
|
// // to not influence other tests
|
||||||
|
// updateParamsMsg := communitytypes.NewMsgUpdateParams(
|
||||||
|
// authtypes.NewModuleAddress(govtypes.ModuleName), // authority
|
||||||
|
// communitytypes.NewParams(
|
||||||
|
// time.Time{}, // after switchover, is empty
|
||||||
|
// newStakingRewardsPerSecond, // only modify stakingRewardsPerSecond
|
||||||
|
// communityParamsResInitial.Params.UpgradeTimeSetStakingRewardsPerSecond,
|
||||||
|
// ),
|
||||||
|
// )
|
||||||
|
|
||||||
|
// // Make sure we're actually changing the params
|
||||||
|
// suite.NotEqual(
|
||||||
|
// updateParamsMsg.Params,
|
||||||
|
// communityParamsResInitial.Params,
|
||||||
|
// "new params should be different from existing",
|
||||||
|
// )
|
||||||
|
|
||||||
|
// proposalMsg, err := govv1.NewMsgSubmitProposal(
|
||||||
|
// []sdk.Msg{&updateParamsMsg},
|
||||||
|
// govParamsRes.Params.MinDeposit,
|
||||||
|
// zgChainAcc.SdkAddress.String(),
|
||||||
|
// "community-update-params",
|
||||||
|
// "title",
|
||||||
|
// "summary",
|
||||||
|
// )
|
||||||
|
// suite.NoError(err)
|
||||||
|
|
||||||
|
// req := util.ZgChainMsgRequest{
|
||||||
|
// Msgs: []sdk.Msg{proposalMsg},
|
||||||
|
// GasLimit: uint64(gasLimit),
|
||||||
|
// FeeAmount: sdk.NewCoins(fee),
|
||||||
|
// Memo: "this is a proposal please accept me",
|
||||||
|
// }
|
||||||
|
// res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||||
|
// suite.Require().NoError(res.Err)
|
||||||
|
|
||||||
|
// // Wait for proposal to be submitted
|
||||||
|
// 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
|
||||||
|
// var govRes govv1.MsgSubmitProposalResponse
|
||||||
|
// suite.decodeTxMsgResponse(txRes, &govRes)
|
||||||
|
|
||||||
|
// // 2. Vote for proposal from whale account
|
||||||
|
// whale := suite.ZgChain.GetAccount(testutil.FundedAccountName)
|
||||||
|
// voteMsg := govv1.NewMsgVote(
|
||||||
|
// whale.SdkAddress,
|
||||||
|
// govRes.ProposalId,
|
||||||
|
// govv1.OptionYes,
|
||||||
|
// "",
|
||||||
|
// )
|
||||||
|
|
||||||
|
// voteReq := util.ZgChainMsgRequest{
|
||||||
|
// Msgs: []sdk.Msg{voteMsg},
|
||||||
|
// GasLimit: uint64(gasLimit),
|
||||||
|
// FeeAmount: sdk.NewCoins(fee),
|
||||||
|
// Memo: "voting",
|
||||||
|
// }
|
||||||
|
// voteRes := whale.SignAndBroadcastZgChainTx(voteReq)
|
||||||
|
// suite.Require().NoError(voteRes.Err)
|
||||||
|
|
||||||
|
// _, 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.ZgChain.Grpc.Query.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
||||||
|
// ProposalId: govRes.ProposalId,
|
||||||
|
// })
|
||||||
|
// suite.NoError(err)
|
||||||
|
|
||||||
|
// return proposalRes.Proposal.Status == govv1.StatusPassed
|
||||||
|
// }, 60*time.Second, 1*time.Second)
|
||||||
|
|
||||||
|
// // Check parameters are updated
|
||||||
|
// communityParamsRes, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||||
|
// context.Background(),
|
||||||
|
// &communitytypes.QueryParamsRequest{},
|
||||||
|
// )
|
||||||
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
|
// suite.Equal(updateParamsMsg.Params, communityParamsRes.Params)
|
||||||
|
// }
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) decodeTxMsgResponse(txRes *sdk.TxResponse, ptr codec.ProtoMarshaler) {
|
func (suite *IntegrationTestSuite) decodeTxMsgResponse(txRes *sdk.TxResponse, ptr codec.ProtoMarshaler) {
|
||||||
// convert txRes.Data hex string to bytes
|
// convert txRes.Data hex string to bytes
|
||||||
txResBytes, err := hex.DecodeString(txRes.Data)
|
txResBytes, err := hex.DecodeString(txRes.Data)
|
||||||
@ -14,10 +180,10 @@ func (suite *IntegrationTestSuite) decodeTxMsgResponse(txRes *sdk.TxResponse, pt
|
|||||||
|
|
||||||
// Unmarshal data to TxMsgData
|
// Unmarshal data to TxMsgData
|
||||||
var txMsgData sdk.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)
|
suite.T().Logf("txData.MsgResponses: %v", txMsgData.MsgResponses)
|
||||||
|
|
||||||
// Parse MsgResponse
|
// 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)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
@ -24,24 +24,21 @@ func setupConvertToCoinTest(
|
|||||||
) (denom string, initialFunds sdk.Coins, user *testutil.SigningAccount) {
|
) (denom string, initialFunds sdk.Coins, user *testutil.SigningAccount) {
|
||||||
// we expect a denom to be registered to the allowed denoms param
|
// we expect a denom to be registered to the allowed denoms param
|
||||||
// and for the funded account to have a balance for that denom
|
// and for the funded account to have a balance for that denom
|
||||||
params, err := suite.Kava.Grpc.Query.Evmutil.Params(
|
params, err := suite.ZgChain.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
|
||||||
context.Background(),
|
|
||||||
&evmutiltypes.QueryParamsRequest{},
|
|
||||||
)
|
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.GreaterOrEqual(
|
suite.GreaterOrEqual(
|
||||||
len(params.Params.AllowedCosmosDenoms), 1,
|
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]
|
tokenInfo := params.Params.AllowedCosmosDenoms[0]
|
||||||
denom = tokenInfo.CosmosDenom
|
denom = tokenInfo.CosmosDenom
|
||||||
initialFunds = sdk.NewCoins(
|
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
|
sdk.NewInt64Coin(denom, initialCosmosCoinConversionDenomFunds), // conversion-enabled cosmos coin
|
||||||
)
|
)
|
||||||
|
|
||||||
user = suite.Kava.NewFundedAccount(accountName, initialFunds)
|
user = suite.ZgChain.NewFundedAccount(accountName, initialFunds)
|
||||||
|
|
||||||
return denom, initialFunds, user
|
return denom, initialFunds, user
|
||||||
}
|
}
|
||||||
@ -63,20 +60,20 @@ func (suite *IntegrationTestSuite) setupAccountWithCosmosCoinERC20Balance(
|
|||||||
user.EvmAddress.Hex(),
|
user.EvmAddress.Hex(),
|
||||||
convertAmount,
|
convertAmount,
|
||||||
)
|
)
|
||||||
tx := util.KavaMsgRequest{
|
tx := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{&msg},
|
Msgs: []sdk.Msg{&msg},
|
||||||
GasLimit: 4e5,
|
GasLimit: 4e5,
|
||||||
FeeAmount: sdk.NewCoins(ukava(400)),
|
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(400))),
|
||||||
Data: "converting sdk coin to erc20",
|
Data: "converting sdk coin to erc20",
|
||||||
}
|
}
|
||||||
res := user.SignAndBroadcastKavaTx(tx)
|
res := user.SignAndBroadcastZgChainTx(tx)
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// adjust sdk balance
|
// adjust sdk balance
|
||||||
sdkBalance = sdkBalance.Sub(convertAmount)
|
sdkBalance = sdkBalance.Sub(convertAmount)
|
||||||
|
|
||||||
// query for the deployed contract
|
// query for the deployed contract
|
||||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
deployedContracts, err := suite.ZgChain.Evmutil.DeployedCosmosCoinContracts(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||||
)
|
)
|
||||||
@ -92,7 +89,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
|||||||
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter")
|
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter")
|
||||||
|
|
||||||
convertAmount := int64(5e3)
|
convertAmount := int64(5e3)
|
||||||
initialModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
initialModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
// CONVERT COSMOS COIN -> ERC20
|
// CONVERT COSMOS COIN -> ERC20
|
||||||
@ -102,17 +99,17 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
|||||||
user.EvmAddress.Hex(),
|
user.EvmAddress.Hex(),
|
||||||
sdk.NewInt64Coin(denom, convertAmount),
|
sdk.NewInt64Coin(denom, convertAmount),
|
||||||
)
|
)
|
||||||
tx := util.KavaMsgRequest{
|
tx := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{&convertToErc20Msg},
|
Msgs: []sdk.Msg{&convertToErc20Msg},
|
||||||
GasLimit: 2e6,
|
GasLimit: 2e6,
|
||||||
FeeAmount: sdk.NewCoins(ukava(2000)),
|
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(2000))),
|
||||||
Data: "converting sdk coin to erc20",
|
Data: "converting sdk coin to erc20",
|
||||||
}
|
}
|
||||||
res := user.SignAndBroadcastKavaTx(tx)
|
res := user.SignAndBroadcastZgChainTx(tx)
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// query for the deployed contract
|
// query for the deployed contract
|
||||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
deployedContracts, err := suite.ZgChain.Evmutil.DeployedCosmosCoinContracts(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||||
)
|
)
|
||||||
@ -122,17 +119,17 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
|||||||
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
||||||
|
|
||||||
// check erc20 balance
|
// 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")
|
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
||||||
|
|
||||||
// check cosmos coin is deducted from account
|
// check cosmos coin is deducted from account
|
||||||
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
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)
|
suite.Equal(expectedFunds, balance)
|
||||||
|
|
||||||
// check that module account has sdk coins
|
// check that module account has sdk coins
|
||||||
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
||||||
actualModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
actualModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
@ -144,26 +141,26 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
|||||||
sdk.NewInt64Coin(denom, convertAmount),
|
sdk.NewInt64Coin(denom, convertAmount),
|
||||||
)
|
)
|
||||||
|
|
||||||
tx = util.KavaMsgRequest{
|
tx = util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{&convertFromErc20Msg},
|
Msgs: []sdk.Msg{&convertFromErc20Msg},
|
||||||
GasLimit: 2e5,
|
GasLimit: 2e5,
|
||||||
FeeAmount: sdk.NewCoins(ukava(200)),
|
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||||
Data: "converting erc20 to cosmos coin",
|
Data: "converting erc20 to cosmos coin",
|
||||||
}
|
}
|
||||||
res = user.SignAndBroadcastKavaTx(tx)
|
res = user.SignAndBroadcastZgChainTx(tx)
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// check erc20 balance
|
// 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")
|
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
||||||
|
|
||||||
// check cosmos coin is added back to account
|
// check cosmos coin is added back to account
|
||||||
expectedFunds = initialFunds.AmountOf(denom)
|
expectedFunds = initialFunds.AmountOf(denom)
|
||||||
balance = suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
balance = suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||||
suite.Equal(expectedFunds, balance)
|
suite.Equal(expectedFunds, balance)
|
||||||
|
|
||||||
// check that module account has sdk coins deducted
|
// 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)
|
suite.Equal(initialModuleBalance, actualModuleBalance)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +169,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
|||||||
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter-eip712")
|
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter-eip712")
|
||||||
|
|
||||||
convertAmount := int64(5e3)
|
convertAmount := int64(5e3)
|
||||||
initialModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
initialModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
// CONVERT COSMOS COIN -> ERC20
|
// CONVERT COSMOS COIN -> ERC20
|
||||||
@ -184,28 +181,28 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
|||||||
)
|
)
|
||||||
tx := suite.NewEip712TxBuilder(
|
tx := suite.NewEip712TxBuilder(
|
||||||
user,
|
user,
|
||||||
suite.Kava,
|
suite.ZgChain,
|
||||||
2e6,
|
2e6,
|
||||||
sdk.NewCoins(ukava(1e4)),
|
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||||
[]sdk.Msg{&convertToErc20Msg},
|
[]sdk.Msg{&convertToErc20Msg},
|
||||||
"this is a memo",
|
"this is a memo",
|
||||||
).GetTx()
|
).GetTx()
|
||||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// submit the eip712 message to the chain.
|
// submit the eip712 message to the chain.
|
||||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
res, err := suite.ZgChain.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||||
TxBytes: txBytes,
|
TxBytes: txBytes,
|
||||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
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.Tx, res.TxResponse.TxHash, 12*time.Second)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// query for the deployed contract
|
// query for the deployed contract
|
||||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
deployedContracts, err := suite.ZgChain.Evmutil.DeployedCosmosCoinContracts(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||||
)
|
)
|
||||||
@ -215,17 +212,17 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
|||||||
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
||||||
|
|
||||||
// check erc20 balance
|
// 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")
|
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
||||||
|
|
||||||
// check cosmos coin is deducted from account
|
// check cosmos coin is deducted from account
|
||||||
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
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)
|
suite.Equal(expectedFunds, balance)
|
||||||
|
|
||||||
// check that module account has sdk coins
|
// check that module account has sdk coins
|
||||||
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
||||||
actualModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
actualModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
@ -238,37 +235,37 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
|||||||
)
|
)
|
||||||
tx = suite.NewEip712TxBuilder(
|
tx = suite.NewEip712TxBuilder(
|
||||||
user,
|
user,
|
||||||
suite.Kava,
|
suite.ZgChain,
|
||||||
2e5,
|
2e5,
|
||||||
sdk.NewCoins(ukava(200)),
|
sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||||
[]sdk.Msg{&convertFromErc20Msg},
|
[]sdk.Msg{&convertFromErc20Msg},
|
||||||
"",
|
"",
|
||||||
).GetTx()
|
).GetTx()
|
||||||
txBytes, err = suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
txBytes, err = suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// submit the eip712 message to the chain
|
// submit the eip712 message to the chain
|
||||||
res, err = suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
res, err = suite.ZgChain.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||||
TxBytes: txBytes,
|
TxBytes: txBytes,
|
||||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
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.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// check erc20 balance
|
// 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")
|
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
||||||
|
|
||||||
// check cosmos coin is added back to account
|
// check cosmos coin is added back to account
|
||||||
expectedFunds = initialFunds.AmountOf(denom)
|
expectedFunds = initialFunds.AmountOf(denom)
|
||||||
balance = suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
balance = suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||||
suite.Equal(expectedFunds, balance)
|
suite.Equal(expectedFunds, balance)
|
||||||
|
|
||||||
// check that module account has sdk coins deducted
|
// 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)
|
suite.Equal(initialModuleBalance, actualModuleBalance)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,8 +331,8 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
|||||||
"cosmo-coin-converter-complex-alice", initialAliceAmount,
|
"cosmo-coin-converter-complex-alice", initialAliceAmount,
|
||||||
)
|
)
|
||||||
|
|
||||||
gasMoney := sdk.NewCoins(ukava(1e5))
|
gasMoney := sdk.NewCoins(a0gi(big.NewInt(1e5)))
|
||||||
bob := suite.Kava.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
bob := suite.ZgChain.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
||||||
amount := big.NewInt(1e3) // test assumes this is half of alice's balance.
|
amount := big.NewInt(1e3) // test assumes this is half of alice's balance.
|
||||||
|
|
||||||
// bob can't move alice's funds
|
// bob can't move alice's funds
|
||||||
@ -400,10 +397,10 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
|||||||
suite.Require().NoError(res.Err)
|
suite.Require().NoError(res.Err)
|
||||||
|
|
||||||
// alice should have amount deducted
|
// 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")
|
suite.BigIntsEqual(big.NewInt(initialAliceAmount-amount.Int64()), erc20Balance, "alice has unexpected erc20 balance")
|
||||||
// bob should have amount added
|
// 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")
|
suite.BigIntsEqual(amount, erc20Balance, "bob has unexpected erc20 balance")
|
||||||
|
|
||||||
// convert bob's new funds back to an sdk.Coin
|
// convert bob's new funds back to an sdk.Coin
|
||||||
@ -412,24 +409,24 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
|||||||
bob.SdkAddress.String(),
|
bob.SdkAddress.String(),
|
||||||
sdk.NewInt64Coin(denom, amount.Int64()),
|
sdk.NewInt64Coin(denom, amount.Int64()),
|
||||||
)
|
)
|
||||||
convertTx := util.KavaMsgRequest{
|
convertTx := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{&convertMsg},
|
Msgs: []sdk.Msg{&convertMsg},
|
||||||
GasLimit: 2e5,
|
GasLimit: 2e5,
|
||||||
FeeAmount: sdk.NewCoins(ukava(200)),
|
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||||
Data: "bob converts his new erc20 to an sdk.Coin",
|
Data: "bob converts his new erc20 to an sdk.Coin",
|
||||||
}
|
}
|
||||||
convertRes := bob.SignAndBroadcastKavaTx(convertTx)
|
convertRes := bob.SignAndBroadcastZgChainTx(convertTx)
|
||||||
suite.NoError(convertRes.Err)
|
suite.NoError(convertRes.Err)
|
||||||
|
|
||||||
// bob should have no more erc20 balance
|
// 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")
|
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected no erc20 balance for bob")
|
||||||
// bob should have sdk balance
|
// 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)
|
suite.Equal(sdk.NewIntFromBigInt(amount), balance)
|
||||||
|
|
||||||
// alice should have the remaining 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")
|
suite.BigIntsEqual(amount, erc20Balance, "expected alice to have half initial funds remaining")
|
||||||
|
|
||||||
// convert alice's remaining balance back to sdk coins
|
// convert alice's remaining balance back to sdk coins
|
||||||
@ -438,6 +435,6 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
|||||||
alice.SdkAddress.String(),
|
alice.SdkAddress.String(),
|
||||||
sdk.NewInt64Coin(denom, amount.Int64()),
|
sdk.NewInt64Coin(denom, amount.Int64()),
|
||||||
)
|
)
|
||||||
convertRes = alice.SignAndBroadcastKavaTx(convertTx)
|
convertRes = alice.SignAndBroadcastZgChainTx(convertTx)
|
||||||
suite.NoError(convertRes.Err)
|
suite.NoError(convertRes.Err)
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"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/e2e/contracts/greeter"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
@ -21,10 +21,10 @@ func (suite *IntegrationTestSuite) TestEthCallToGreeterContract() {
|
|||||||
// this test manipulates state of the Greeter contract which means other tests shouldn't use it.
|
// this test manipulates state of the Greeter contract which means other tests shouldn't use it.
|
||||||
|
|
||||||
// setup funded account to interact with contract
|
// 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"]
|
greeterAddr := suite.ZgChain.ContractAddrs["greeter"]
|
||||||
contract, err := greeter.NewGreeter(greeterAddr, suite.Kava.EvmClient)
|
contract, err := greeter.NewGreeter(greeterAddr, suite.ZgChain.EvmClient)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
beforeGreeting, err := contract.Greet(nil)
|
beforeGreeting, err := contract.Greet(nil)
|
||||||
@ -34,7 +34,7 @@ func (suite *IntegrationTestSuite) TestEthCallToGreeterContract() {
|
|||||||
tx, err := contract.SetGreeting(user.EvmAuth, updatedGreeting)
|
tx, err := contract.SetGreeting(user.EvmAuth, updatedGreeting)
|
||||||
suite.NoError(err)
|
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)
|
suite.NoError(err)
|
||||||
|
|
||||||
afterGreeting, err := contract.Greet(nil)
|
afterGreeting, err := contract.Greet(nil)
|
||||||
@ -49,14 +49,14 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
|||||||
amount := big.NewInt(1)
|
amount := big.NewInt(1)
|
||||||
|
|
||||||
// make unauthenticated eth_call query to check balance
|
// 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
|
// make authenticate eth_call to transfer tokens
|
||||||
res := suite.FundKavaErc20Balance(randoReceiver, amount)
|
res := suite.FundZgChainErc20Balance(randoReceiver, amount)
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// make another unauthenticated eth_call query to check new balance
|
// 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(big.NewInt(0), beforeBalance, "expected before balance to be zero")
|
||||||
suite.BigIntsEqual(amount, afterBalance, "unexpected post-transfer balance")
|
suite.BigIntsEqual(amount, afterBalance, "unexpected post-transfer balance")
|
||||||
@ -64,42 +64,42 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
|||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||||
// create new funded account
|
// 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()
|
receiver := app.RandomAddress()
|
||||||
|
|
||||||
// setup message for sending some kava to random receiver
|
// setup message for sending some a0gi to random receiver
|
||||||
msgs := []sdk.Msg{
|
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
|
// create tx
|
||||||
tx := suite.NewEip712TxBuilder(
|
tx := suite.NewEip712TxBuilder(
|
||||||
sender,
|
sender,
|
||||||
suite.Kava,
|
suite.ZgChain,
|
||||||
1e6,
|
1e6,
|
||||||
sdk.NewCoins(ukava(1e4)),
|
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||||
msgs,
|
msgs,
|
||||||
"this is a memo",
|
"this is a memo",
|
||||||
).GetTx()
|
).GetTx()
|
||||||
|
|
||||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// broadcast tx
|
// broadcast tx
|
||||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
res, err := suite.ZgChain.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||||
TxBytes: txBytes,
|
TxBytes: txBytes,
|
||||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
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.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// check that the message was processed & the kava is transferred.
|
// check that the message was processed & the a0gi is transferred.
|
||||||
balRes, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
balRes, err := suite.ZgChain.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||||
Address: receiver.String(),
|
Address: receiver.String(),
|
||||||
Denom: "ukava",
|
Denom: chaincfg.DisplayDenom,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(sdk.NewInt(1e3), balRes.Balance.Amount)
|
suite.Equal(sdk.NewInt(1e3), balRes.Balance.Amount)
|
||||||
@ -107,74 +107,95 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
|||||||
|
|
||||||
// Note that this test works because the deployed erc20 is configured in evmutil & cdp params.
|
// Note that this test works because the deployed erc20 is configured in evmutil & cdp params.
|
||||||
// This test matches the webapp's "USDT Earn" workflow
|
// This test matches the webapp's "USDT Earn" workflow
|
||||||
func (suite *IntegrationTestSuite) TestEip712ConvertToCoinAndDepositToLend() {
|
// func (suite *IntegrationTestSuite) TestEip712ConvertToCoinAndDepositToLend() {
|
||||||
// cdp requires minimum of $11 collateral
|
// // cdp requires minimum of $11 collateral
|
||||||
amount := sdk.NewInt(11e6) // 11 USDT
|
// amount := sdk.NewInt(11e6) // 11 USDT
|
||||||
|
// principal := sdk.NewCoin("usdx", sdk.NewInt(10e6))
|
||||||
|
// sdkDenom := suite.DeployedErc20.CosmosDenom
|
||||||
|
|
||||||
sdkDenom := suite.DeployedErc20.CosmosDenom
|
// // create new funded account
|
||||||
|
// depositor := suite.ZgChain.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(a0gi(big.NewInt(1e5)))
|
||||||
|
// // give them erc20 balance to deposit
|
||||||
|
// fundRes := suite.FundZgChainErc20Balance(depositor.EvmAddress, amount.BigInt())
|
||||||
|
// suite.NoError(fundRes.Err)
|
||||||
|
|
||||||
// create new funded account
|
// // setup messages for convert to coin & deposit into earn
|
||||||
depositor := suite.Kava.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(ukava(1e5)))
|
// convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
||||||
// give them erc20 balance to deposit
|
// evmutiltypes.NewInternalEVMAddress(depositor.EvmAddress),
|
||||||
fundRes := suite.FundKavaErc20Balance(depositor.EvmAddress, amount.BigInt())
|
// depositor.SdkAddress,
|
||||||
suite.NoError(fundRes.Err)
|
// evmutiltypes.NewInternalEVMAddress(suite.DeployedErc20.Address),
|
||||||
|
// amount,
|
||||||
|
// )
|
||||||
|
// // depositMsg := cdptypes.NewMsgCreateCDP(
|
||||||
|
// // depositor.SdkAddress,
|
||||||
|
// // sdk.NewCoin(sdkDenom, amount),
|
||||||
|
// // principal,
|
||||||
|
// // suite.DeployedErc20.CdpCollateralType,
|
||||||
|
// // )
|
||||||
|
// msgs := []sdk.Msg{
|
||||||
|
// // convert to coin
|
||||||
|
// &convertMsg,
|
||||||
|
// // deposit into cdp (Mint), take out USDX
|
||||||
|
// // &depositMsg,
|
||||||
|
// }
|
||||||
|
|
||||||
// setup messages for convert to coin & deposit into earn
|
// // create tx
|
||||||
convertMsg := evmutiltypes.NewMsgConvertERC20ToCoin(
|
// tx := suite.NewEip712TxBuilder(
|
||||||
evmutiltypes.NewInternalEVMAddress(depositor.EvmAddress),
|
// depositor,
|
||||||
depositor.SdkAddress,
|
// suite.ZgChain,
|
||||||
evmutiltypes.NewInternalEVMAddress(suite.DeployedErc20.Address),
|
// 1e6,
|
||||||
amount,
|
// sdk.NewCoins(a0gi(big.NewInt(1e4)),
|
||||||
)
|
// msgs,
|
||||||
msgs := []sdk.Msg{
|
// "doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit",
|
||||||
// convert to coin
|
// ).GetTx()
|
||||||
&convertMsg,
|
|
||||||
}
|
|
||||||
|
|
||||||
// create tx
|
// txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||||
tx := suite.NewEip712TxBuilder(
|
// suite.NoError(err)
|
||||||
depositor,
|
|
||||||
suite.Kava,
|
|
||||||
1e6,
|
|
||||||
sdk.NewCoins(ukava(1e4)),
|
|
||||||
msgs,
|
|
||||||
"doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit",
|
|
||||||
).GetTx()
|
|
||||||
|
|
||||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
// // broadcast tx
|
||||||
suite.NoError(err)
|
// 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)
|
||||||
|
|
||||||
// broadcast tx
|
// _, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
// suite.Require().NoError(err)
|
||||||
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)
|
// // check that depositor no longer has erc20 balance
|
||||||
suite.Require().NoError(err)
|
// balance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||||
|
// suite.BigIntsEqual(big.NewInt(0), balance, "expected no erc20 balance")
|
||||||
|
|
||||||
// check that depositor no longer has erc20 balance
|
// // check that account has cdp
|
||||||
balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
// // cdpRes, err := suite.ZgChain.Grpc.Query.Cdp.Cdp(context.Background(), &cdptypes.QueryCdpRequest{
|
||||||
suite.BigIntsEqual(big.NewInt(0), balance, "expected no erc20 balance")
|
// // CollateralType: suite.DeployedErc20.CdpCollateralType,
|
||||||
|
// // Owner: depositor.SdkAddress.String(),
|
||||||
|
// // })
|
||||||
|
// // suite.NoError(err)
|
||||||
|
// // suite.True(cdpRes.Cdp.Collateral.Amount.Equal(amount))
|
||||||
|
// // suite.True(cdpRes.Cdp.Principal.Equal(principal))
|
||||||
|
|
||||||
// withdraw deposit & convert back to erc20 (this allows refund to recover erc20s used in test)
|
// // withdraw deposit & convert back to erc20 (this allows refund to recover erc20s used in test)
|
||||||
|
// // withdraw := cdptypes.NewMsgRepayDebt(
|
||||||
|
// // depositor.SdkAddress,
|
||||||
|
// // suite.DeployedErc20.CdpCollateralType,
|
||||||
|
// // principal,
|
||||||
|
// // )
|
||||||
|
// convertBack := evmutiltypes.NewMsgConvertCoinToERC20(
|
||||||
|
// depositor.SdkAddress.String(),
|
||||||
|
// depositor.EvmAddress.Hex(),
|
||||||
|
// sdk.NewCoin(sdkDenom, amount),
|
||||||
|
// )
|
||||||
|
// withdrawAndConvertBack := util.ZgChainMsgRequest{
|
||||||
|
// Msgs: []sdk.Msg{&withdraw, &convertBack},
|
||||||
|
// GasLimit: 1e6,
|
||||||
|
// FeeAmount: sdk.NewCoins(a0gi(big.NewInt(1000)),
|
||||||
|
// Data: "withdrawing from mint & converting back to erc20",
|
||||||
|
// }
|
||||||
|
// lastRes := depositor.SignAndBroadcastZgChainTx(withdrawAndConvertBack)
|
||||||
|
// suite.NoError(lastRes.Err)
|
||||||
|
|
||||||
convertBack := evmutiltypes.NewMsgConvertCoinToERC20(
|
// balance = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||||
depositor.SdkAddress.String(),
|
// suite.BigIntsEqual(amount.BigInt(), balance, "expected returned erc20 balance")
|
||||||
depositor.EvmAddress.Hex(),
|
// }
|
||||||
sdk.NewCoin(sdkDenom, amount),
|
|
||||||
)
|
|
||||||
withdrawAndConvertBack := util.KavaMsgRequest{
|
|
||||||
Msgs: []sdk.Msg{&convertBack},
|
|
||||||
GasLimit: 1e6,
|
|
||||||
FeeAmount: sdk.NewCoins(ukava(1000)),
|
|
||||||
Data: "withdrawing from mint & converting back to erc20",
|
|
||||||
}
|
|
||||||
lastRes := depositor.SignAndBroadcastKavaTx(withdrawAndConvertBack)
|
|
||||||
suite.NoError(lastRes.Err)
|
|
||||||
|
|
||||||
balance = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
|
||||||
suite.BigIntsEqual(amount.BigInt(), balance, "expected returned erc20 balance")
|
|
||||||
}
|
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,14 +21,14 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
|
|||||||
suite.SkipIfKvtoolDisabled()
|
suite.SkipIfKvtoolDisabled()
|
||||||
|
|
||||||
// read expected min fee from app.toml
|
// read expected min fee from app.toml
|
||||||
minGasPrices, err := getMinFeeFromAppToml(util.KavaHomePath())
|
minGasPrices, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// evm uses akava, get akava min fee
|
// evm uses neuron, get neuron min fee
|
||||||
evmMinGas := minGasPrices.AmountOf("akava").TruncateInt().BigInt()
|
evmMinGas := minGasPrices.AmountOf(chaincfg.BaseDenom).TruncateInt().BigInt()
|
||||||
|
|
||||||
// returns eth_gasPrice, units in kava
|
// returns eth_gasPrice, units in a0gi
|
||||||
gasPrice, err := suite.Kava.EvmClient.SuggestGasPrice(context.Background())
|
gasPrice, err := suite.ZgChain.EvmClient.SuggestGasPrice(context.Background())
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
suite.Equal(evmMinGas, gasPrice)
|
suite.Equal(evmMinGas, gasPrice)
|
||||||
@ -37,13 +38,13 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
|||||||
suite.SkipIfKvtoolDisabled()
|
suite.SkipIfKvtoolDisabled()
|
||||||
|
|
||||||
// setup sender & receiver
|
// 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())
|
randoReceiver := util.SdkToEvmAddress(app.RandomAddress())
|
||||||
|
|
||||||
// get min gas price for evm (from app.toml)
|
// get min gas price for evm (from app.toml)
|
||||||
minFees, err := getMinFeeFromAppToml(util.KavaHomePath())
|
minFees, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||||
suite.NoError(err)
|
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)
|
// attempt tx with less than min gas price (min fee - 1)
|
||||||
tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt()
|
tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt()
|
||||||
@ -58,12 +59,12 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
|||||||
suite.ErrorContains(res.Err, "insufficient fee")
|
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
|
// read the expected min gas price from app.toml
|
||||||
parsed := struct {
|
parsed := struct {
|
||||||
MinGasPrices string `toml:"minimum-gas-prices"`
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,17 @@ import (
|
|||||||
emtypes "github.com/evmos/ethermint/types"
|
emtypes "github.com/evmos/ethermint/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"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/e2e/testutil"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
minEvmGasPrice = big.NewInt(1e10) // akava
|
minEvmGasPrice = big.NewInt(1e10) // neuron
|
||||||
)
|
)
|
||||||
|
|
||||||
func ukava(amt int64) sdk.Coin {
|
func a0gi(amt *big.Int) sdk.Coin {
|
||||||
return sdk.NewCoin("ukava", sdkmath.NewInt(amt))
|
return sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewIntFromBigInt(amt))
|
||||||
}
|
}
|
||||||
|
|
||||||
type IntegrationTestSuite struct {
|
type IntegrationTestSuite struct {
|
||||||
@ -39,63 +40,63 @@ func TestIntegrationTestSuite(t *testing.T) {
|
|||||||
suite.Run(t, new(IntegrationTestSuite))
|
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() {
|
func (suite *IntegrationTestSuite) TestChainID() {
|
||||||
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.Kava.ChainID)
|
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.ZgChain.ChainID)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// EVM query
|
// EVM query
|
||||||
evmNetworkId, err := suite.Kava.EvmClient.NetworkID(context.Background())
|
evmNetworkId, err := suite.ZgChain.EvmClient.NetworkID(context.Background())
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(expectedEvmNetworkId, evmNetworkId)
|
suite.Equal(expectedEvmNetworkId, evmNetworkId)
|
||||||
|
|
||||||
// SDK query
|
// SDK query
|
||||||
nodeInfo, err := suite.Kava.Grpc.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
nodeInfo, err := suite.ZgChain.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||||
suite.NoError(err)
|
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
|
// example test that funds a new account & queries its balance
|
||||||
func (suite *IntegrationTestSuite) TestFundedAccount() {
|
func (suite *IntegrationTestSuite) TestFundedAccount() {
|
||||||
funds := ukava(1e3)
|
funds := a0gi(big.NewInt(1e3))
|
||||||
acc := suite.Kava.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
acc := suite.ZgChain.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
||||||
|
|
||||||
// check that the sdk & evm signers are for the same account
|
// check that the sdk & evm signers are for the same account
|
||||||
suite.Equal(acc.SdkAddress.String(), util.EvmToSdkAddress(acc.EvmAddress).String())
|
suite.Equal(acc.SdkAddress.String(), util.EvmToSdkAddress(acc.EvmAddress).String())
|
||||||
suite.Equal(acc.EvmAddress.Hex(), util.SdkToEvmAddress(acc.SdkAddress).Hex())
|
suite.Equal(acc.EvmAddress.Hex(), util.SdkToEvmAddress(acc.SdkAddress).Hex())
|
||||||
|
|
||||||
// check balance via SDK query
|
// check balance via SDK query
|
||||||
res, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
res, err := suite.ZgChain.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
||||||
acc.SdkAddress, "ukava",
|
acc.SdkAddress, chaincfg.DisplayDenom,
|
||||||
))
|
))
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(funds, *res.Balance)
|
suite.Equal(funds, *res.Balance)
|
||||||
|
|
||||||
// check balance via EVM query
|
// 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.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
|
// example test that signs & broadcasts an EVM tx
|
||||||
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||||
// fund an account that can perform the transfer
|
// fund an account that can perform the transfer
|
||||||
initialFunds := ukava(1e6) // 1 KAVA
|
initialFunds := a0gi(big.NewInt(1e6)) // 1 A0GI
|
||||||
acc := suite.Kava.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
|
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()
|
randomAddr := app.RandomAddress()
|
||||||
to := util.SdkToEvmAddress(randomAddr)
|
to := util.SdkToEvmAddress(randomAddr)
|
||||||
|
|
||||||
// example fetching of nonce (account sequence)
|
// 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.NoError(err)
|
||||||
suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs
|
suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs
|
||||||
|
|
||||||
// transfer kava over EVM
|
// transfer a0gi over EVM
|
||||||
kavaToTransfer := big.NewInt(1e17) // .1 KAVA; akava has 18 decimals.
|
a0giToTransfer := big.NewInt(1e17) // .1 A0GI; neuron has 18 decimals.
|
||||||
req := util.EvmTxRequest{
|
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",
|
Data: "any ol' data to track this through the system",
|
||||||
}
|
}
|
||||||
res := acc.SignAndBroadcastEvmTx(req)
|
res := acc.SignAndBroadcastEvmTx(req)
|
||||||
@ -103,36 +104,36 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
|||||||
suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status)
|
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.
|
// 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)).
|
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.
|
// expect (9 - gas used) A0GI remaining in account.
|
||||||
balance := suite.Kava.QuerySdkForBalances(acc.SdkAddress)
|
balance := suite.ZgChain.QuerySdkForBalances(acc.SdkAddress)
|
||||||
suite.Equal(sdkmath.NewInt(9e5).Sub(ukavaUsedForGas), balance.AmountOf("ukava"))
|
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).
|
// TestIbcTransfer transfers A0GI from the primary 0g-chain (suite.ZgChain) to the ibc chain (suite.Ibc).
|
||||||
// Note that because the IBC chain also runs kava's binary, this tests both the sending & receiving.
|
// Note that because the IBC chain also runs 0g-chain's binary, this tests both the sending & receiving.
|
||||||
func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
||||||
suite.SkipIfIbcDisabled()
|
suite.SkipIfIbcDisabled()
|
||||||
|
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
// setup kava account
|
// setup 0g-chain account
|
||||||
funds := ukava(1e5) // .1 KAVA
|
funds := a0gi(big.NewInt(1e5)) // .1 A0GI
|
||||||
kavaAcc := suite.Kava.NewFundedAccount("ibc-transfer-kava-side", sdk.NewCoins(funds))
|
zgChainAcc := suite.ZgChain.NewFundedAccount("ibc-transfer-0g-side", sdk.NewCoins(funds))
|
||||||
// setup ibc account
|
// setup ibc account
|
||||||
ibcAcc := suite.Ibc.NewFundedAccount("ibc-transfer-ibc-side", sdk.NewCoins())
|
ibcAcc := suite.Ibc.NewFundedAccount("ibc-transfer-ibc-side", sdk.NewCoins())
|
||||||
|
|
||||||
gasLimit := int64(2e5)
|
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(
|
transferMsg := ibctypes.NewMsgTransfer(
|
||||||
testutil.IbcPort,
|
testutil.IbcPort,
|
||||||
testutil.IbcChannel,
|
testutil.IbcChannel,
|
||||||
fundsToSend,
|
fundsToSend,
|
||||||
kavaAcc.SdkAddress.String(),
|
zgChainAcc.SdkAddress.String(),
|
||||||
ibcAcc.SdkAddress.String(),
|
ibcAcc.SdkAddress.String(),
|
||||||
ibcclienttypes.NewHeight(0, 0), // timeout height disabled when 0
|
ibcclienttypes.NewHeight(0, 0), // timeout height disabled when 0
|
||||||
uint64(time.Now().Add(30*time.Second).UnixNano()),
|
uint64(time.Now().Add(30*time.Second).UnixNano()),
|
||||||
@ -142,22 +143,22 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
|||||||
expectedSrcBalance := funds.Sub(fundsToSend).Sub(fee)
|
expectedSrcBalance := funds.Sub(fundsToSend).Sub(fee)
|
||||||
|
|
||||||
// ACT
|
// ACT
|
||||||
// IBC transfer from kava -> ibc
|
// IBC transfer from 0g-chain -> ibc
|
||||||
transferTo := util.KavaMsgRequest{
|
transferTo := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{transferMsg},
|
Msgs: []sdk.Msg{transferMsg},
|
||||||
GasLimit: uint64(gasLimit),
|
GasLimit: uint64(gasLimit),
|
||||||
FeeAmount: sdk.NewCoins(fee),
|
FeeAmount: sdk.NewCoins(fee),
|
||||||
Memo: "sent from Kava!",
|
Memo: "sent from ZgChain!",
|
||||||
}
|
}
|
||||||
res := kavaAcc.SignAndBroadcastKavaTx(transferTo)
|
res := zgChainAcc.SignAndBroadcastZgChainTx(transferTo)
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
suite.NoError(res.Err)
|
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 {
|
suite.Eventually(func() bool {
|
||||||
balance := suite.Kava.QuerySdkForBalances(kavaAcc.SdkAddress)
|
balance := suite.ZgChain.QuerySdkForBalances(zgChainAcc.SdkAddress)
|
||||||
return balance.AmountOf("ukava").Equal(expectedSrcBalance.Amount)
|
return balance.AmountOf(chaincfg.DisplayDenom).Equal(expectedSrcBalance.Amount)
|
||||||
}, 10*time.Second, 1*time.Second)
|
}, 10*time.Second, 1*time.Second)
|
||||||
|
|
||||||
// expect the balance to be transferred to the ibc chain!
|
// expect the balance to be transferred to the ibc chain!
|
||||||
|
@ -7,14 +7,14 @@ package e2e_test
|
|||||||
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
||||||
|
|
||||||
// // Before params
|
// // Before params
|
||||||
// kavaDistParamsBefore, err := suite.Kava.Kavadist.Params(beforeUpgradeCtx, &kavadisttypes.QueryParamsRequest{})
|
// kavaDistParamsBefore, err := suite.ZgChain.Kavadist.Params(beforeUpgradeCtx, &kavadisttypes.QueryParamsRequest{})
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// mintParamsBefore, err := suite.Kava.Mint.Params(beforeUpgradeCtx, &minttypes.QueryParamsRequest{})
|
// mintParamsBefore, err := suite.ZgChain.Mint.Params(beforeUpgradeCtx, &minttypes.QueryParamsRequest{})
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
|
|
||||||
// // Before parameters
|
// // Before parameters
|
||||||
// suite.Run("x/community and x/kavadist parameters before upgrade", func() {
|
// suite.Run("x/community and x/kavadist parameters before upgrade", func() {
|
||||||
// _, err = suite.Kava.Community.Params(beforeUpgradeCtx, &communitytypes.QueryParamsRequest{})
|
// _, err = suite.ZgChain.Community.Params(beforeUpgradeCtx, &communitytypes.QueryParamsRequest{})
|
||||||
// suite.Error(err, "x/community should not have params before upgrade")
|
// suite.Error(err, "x/community should not have params before upgrade")
|
||||||
|
|
||||||
// suite.Require().True(
|
// suite.Require().True(
|
||||||
@ -34,11 +34,11 @@ package e2e_test
|
|||||||
|
|
||||||
// // After upgrade, Before switchover - parameters
|
// // After upgrade, Before switchover - parameters
|
||||||
// suite.Run("x/kavadist, x/mint, x/community parameters after upgrade, before switchover", func() {
|
// suite.Run("x/kavadist, x/mint, x/community parameters after upgrade, before switchover", func() {
|
||||||
// kavaDistParamsAfter, err := suite.Kava.Kavadist.Params(afterUpgradeCtx, &kavadisttypes.QueryParamsRequest{})
|
// kavaDistParamsAfter, err := suite.ZgChain.Kavadist.Params(afterUpgradeCtx, &kavadisttypes.QueryParamsRequest{})
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// mintParamsAfter, err := suite.Kava.Mint.Params(afterUpgradeCtx, &minttypes.QueryParamsRequest{})
|
// mintParamsAfter, err := suite.ZgChain.Mint.Params(afterUpgradeCtx, &minttypes.QueryParamsRequest{})
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// communityParamsAfter, err := suite.Kava.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
|
// communityParamsAfter, err := suite.ZgChain.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
|
|
||||||
// suite.Equal(
|
// suite.Equal(
|
||||||
@ -74,7 +74,7 @@ package e2e_test
|
|||||||
// suite.Require().Eventually(
|
// suite.Require().Eventually(
|
||||||
// func() bool {
|
// func() bool {
|
||||||
// // Get x/community for switchover time
|
// // Get x/community for switchover time
|
||||||
// params, err := suite.Kava.Community.Params(
|
// params, err := suite.ZgChain.Community.Params(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &communitytypes.QueryParamsRequest{},
|
// &communitytypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -88,7 +88,7 @@ package e2e_test
|
|||||||
// )
|
// )
|
||||||
|
|
||||||
// // Fetch exact block when inflation stop event emitted
|
// // Fetch exact block when inflation stop event emitted
|
||||||
// _, switchoverHeight, err := suite.Kava.GetBeginBlockEventsFromQuery(
|
// _, switchoverHeight, err := suite.ZgChain.GetBeginBlockEventsFromQuery(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// fmt.Sprintf(
|
// fmt.Sprintf(
|
||||||
// "%s.%s EXISTS",
|
// "%s.%s EXISTS",
|
||||||
@ -103,17 +103,17 @@ package e2e_test
|
|||||||
// afterSwitchoverCtx := util.CtxAtHeight(switchoverHeight)
|
// afterSwitchoverCtx := util.CtxAtHeight(switchoverHeight)
|
||||||
|
|
||||||
// suite.Run("x/kavadist, x/mint, x/community parameters after upgrade, after switchover", func() {
|
// suite.Run("x/kavadist, x/mint, x/community parameters after upgrade, after switchover", func() {
|
||||||
// kavaDistParamsAfter, err := suite.Kava.Kavadist.Params(
|
// kavaDistParamsAfter, err := suite.ZgChain.Kavadist.Params(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &kavadisttypes.QueryParamsRequest{},
|
// &kavadisttypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// mintParamsAfter, err := suite.Kava.Mint.Params(
|
// mintParamsAfter, err := suite.ZgChain.Mint.Params(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &minttypes.QueryParamsRequest{},
|
// &minttypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// communityParamsAfter, err := suite.Kava.Community.Params(
|
// communityParamsAfter, err := suite.ZgChain.Community.Params(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &communitytypes.QueryParamsRequest{},
|
// &communitytypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -148,35 +148,35 @@ package e2e_test
|
|||||||
|
|
||||||
// suite.Run("x/kavadist, x/distribution, x/community balances after switchover", func() {
|
// suite.Run("x/kavadist, x/distribution, x/community balances after switchover", func() {
|
||||||
// // Before balances - community pool fund consolidation
|
// // Before balances - community pool fund consolidation
|
||||||
// kavaDistBalBefore, err := suite.Kava.Kavadist.Balance(
|
// kavaDistBalBefore, err := suite.ZgChain.Kavadist.Balance(
|
||||||
// beforeSwitchoverCtx,
|
// beforeSwitchoverCtx,
|
||||||
// &kavadisttypes.QueryBalanceRequest{},
|
// &kavadisttypes.QueryBalanceRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// distrBalBefore, err := suite.Kava.Distribution.CommunityPool(
|
// distrBalBefore, err := suite.ZgChain.Distribution.CommunityPool(
|
||||||
// beforeSwitchoverCtx,
|
// beforeSwitchoverCtx,
|
||||||
// &distrtypes.QueryCommunityPoolRequest{},
|
// &distrtypes.QueryCommunityPoolRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// distrBalCoinsBefore, distrDustBefore := distrBalBefore.Pool.TruncateDecimal()
|
// distrBalCoinsBefore, distrDustBefore := distrBalBefore.Pool.TruncateDecimal()
|
||||||
// beforeCommPoolBalance, err := suite.Kava.Community.Balance(
|
// beforeCommPoolBalance, err := suite.ZgChain.Community.Balance(
|
||||||
// beforeSwitchoverCtx,
|
// beforeSwitchoverCtx,
|
||||||
// &communitytypes.QueryBalanceRequest{},
|
// &communitytypes.QueryBalanceRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
|
|
||||||
// // After balances
|
// // After balances
|
||||||
// kavaDistBalAfter, err := suite.Kava.Kavadist.Balance(
|
// kavaDistBalAfter, err := suite.ZgChain.Kavadist.Balance(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &kavadisttypes.QueryBalanceRequest{},
|
// &kavadisttypes.QueryBalanceRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// distrBalAfter, err := suite.Kava.Distribution.CommunityPool(
|
// distrBalAfter, err := suite.ZgChain.Distribution.CommunityPool(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &distrtypes.QueryCommunityPoolRequest{},
|
// &distrtypes.QueryCommunityPoolRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// afterCommPoolBalance, err := suite.Kava.Community.Balance(
|
// afterCommPoolBalance, err := suite.ZgChain.Community.Balance(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &communitytypes.QueryBalanceRequest{},
|
// &communitytypes.QueryBalanceRequest{},
|
||||||
// )
|
// )
|
||||||
@ -200,7 +200,7 @@ package e2e_test
|
|||||||
// suite.Empty(distrCoinsAfter, "expected no coins in x/distribution community pool")
|
// suite.Empty(distrCoinsAfter, "expected no coins in x/distribution community pool")
|
||||||
|
|
||||||
// // Fetch block results for paid staking rewards in the block
|
// // Fetch block results for paid staking rewards in the block
|
||||||
// blockRes, err := suite.Kava.TmSignClient.BlockResults(
|
// blockRes, err := suite.ZgChain.TmSignClient.BlockResults(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &switchoverHeight,
|
// &switchoverHeight,
|
||||||
// )
|
// )
|
||||||
|
@ -3,6 +3,7 @@ package e2e_test
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
@ -11,14 +12,15 @@ import (
|
|||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/tests/e2e/testutil"
|
"github.com/0glabs/0g-chain/tests/e2e/testutil"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
govModuleAcc = "kava10d07y265gmmuvt4z0w9aw880jnsr700jxh8cq5"
|
govModuleAcc = "0g10d07y265gmmuvt4z0w9aw880jnsr700jxh8cq5"
|
||||||
communityModuleAcc = "kava17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5"
|
communityModuleAcc = "0g17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5"
|
||||||
kavadistModuleAcc = "kava1cj7njkw2g9fqx4e768zc75dp9sks8u9znxrf0w"
|
zgChainDistModuleAcc = "0g1cj7njkw2g9fqx4e768zc75dp9sks8u9znxrf0w"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestGovParamChanges() {
|
func (suite *IntegrationTestSuite) TestGovParamChanges() {
|
||||||
@ -28,13 +30,13 @@ func (suite *IntegrationTestSuite) TestGovParamChanges() {
|
|||||||
afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
||||||
|
|
||||||
// fetch gov parameters before upgrade
|
// fetch gov parameters before upgrade
|
||||||
govBeforeParams, err := suite.Kava.Gov.Params(beforeUpgradeCtx, &govv1.QueryParamsRequest{ParamsType: "tallying"})
|
govBeforeParams, err := suite.ZgChain.Gov.Params(beforeUpgradeCtx, &govv1.QueryParamsRequest{ParamsType: "tallying"})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// assert expected gov quorum before upgrade
|
// assert expected gov quorum before upgrade
|
||||||
suite.NotEqual(govBeforeParams.TallyParams.Quorum, "0.200000000000000000")
|
suite.NotEqual(govBeforeParams.TallyParams.Quorum, "0.200000000000000000")
|
||||||
|
|
||||||
govAfterParams, err := suite.Kava.Gov.Params(afterUpgradeCtx, &govv1.QueryParamsRequest{ParamsType: "tallying"})
|
govAfterParams, err := suite.ZgChain.Gov.Params(afterUpgradeCtx, &govv1.QueryParamsRequest{ParamsType: "tallying"})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// assert expected gov quorum after upgrade
|
// assert expected gov quorum after upgrade
|
||||||
@ -49,7 +51,7 @@ func (suite *IntegrationTestSuite) TestAuthzParamChanges() {
|
|||||||
afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
||||||
|
|
||||||
// fetch authz grants before upgrade
|
// fetch authz grants before upgrade
|
||||||
authzBeforeGrants, err := suite.Kava.Authz.Grants(beforeUpgradeCtx, &authz.QueryGrantsRequest{Granter: kavadistModuleAcc, Grantee: govModuleAcc, Pagination: &query.PageRequest{Limit: 1000, CountTotal: true}})
|
authzBeforeGrants, err := suite.ZgChain.Authz.Grants(beforeUpgradeCtx, &authz.QueryGrantsRequest{Granter: zgChainDistModuleAcc, Grantee: govModuleAcc, Pagination: &query.PageRequest{Limit: 1000, CountTotal: true}})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(authzBeforeGrants.Pagination.Total, uint64(len(authzBeforeGrants.Grants)), "expected all grants to have been requested")
|
suite.Require().Equal(authzBeforeGrants.Pagination.Total, uint64(len(authzBeforeGrants.Grants)), "expected all grants to have been requested")
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ func (suite *IntegrationTestSuite) TestAuthzParamChanges() {
|
|||||||
suite.Equal(0, len(authzBeforeGrants.Grants))
|
suite.Equal(0, len(authzBeforeGrants.Grants))
|
||||||
|
|
||||||
// fetch authz grants after upgrade
|
// fetch authz grants after upgrade
|
||||||
authzAfterGrants, err := suite.Kava.Authz.Grants(afterUpgradeCtx, &authz.QueryGrantsRequest{Granter: kavadistModuleAcc, Grantee: govModuleAcc, Pagination: &query.PageRequest{Limit: 1000, CountTotal: true}})
|
authzAfterGrants, err := suite.ZgChain.Authz.Grants(afterUpgradeCtx, &authz.QueryGrantsRequest{Granter: zgChainDistModuleAcc, Grantee: govModuleAcc, Pagination: &query.PageRequest{Limit: 1000, CountTotal: true}})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(authzAfterGrants.Pagination.Total, uint64(len(authzAfterGrants.Grants)), "expected all grants to have been requested")
|
suite.Require().Equal(authzAfterGrants.Pagination.Total, uint64(len(authzAfterGrants.Grants)), "expected all grants to have been requested")
|
||||||
|
|
||||||
@ -67,7 +69,7 @@ func (suite *IntegrationTestSuite) TestAuthzParamChanges() {
|
|||||||
grant := authzAfterGrants.Grants[0]
|
grant := authzAfterGrants.Grants[0]
|
||||||
|
|
||||||
var authorization authz.Authorization
|
var authorization authz.Authorization
|
||||||
suite.Kava.EncodingConfig.Marshaler.UnpackAny(grant.Authorization, &authorization)
|
suite.ZgChain.EncodingConfig.Marshaler.UnpackAny(grant.Authorization, &authorization)
|
||||||
|
|
||||||
genericAuthorization, ok := authorization.(*authz.GenericAuthorization)
|
genericAuthorization, ok := authorization.(*authz.GenericAuthorization)
|
||||||
suite.Require().True(ok, "expected generic authorization")
|
suite.Require().True(ok, "expected generic authorization")
|
||||||
@ -88,7 +90,7 @@ func (suite *IntegrationTestSuite) TestModuleAccountGovTransfers() {
|
|||||||
|
|
||||||
// module accounts for gov transfer test cases
|
// module accounts for gov transfer test cases
|
||||||
communityAcc := sdk.MustAccAddressFromBech32(communityModuleAcc)
|
communityAcc := sdk.MustAccAddressFromBech32(communityModuleAcc)
|
||||||
kavadistAcc := sdk.MustAccAddressFromBech32(kavadistModuleAcc)
|
zgChainDistAcc := sdk.MustAccAddressFromBech32(zgChainDistModuleAcc)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -99,14 +101,14 @@ func (suite *IntegrationTestSuite) TestModuleAccountGovTransfers() {
|
|||||||
{
|
{
|
||||||
name: "transfer from community to kavadist for incentive rewards",
|
name: "transfer from community to kavadist for incentive rewards",
|
||||||
sender: communityAcc,
|
sender: communityAcc,
|
||||||
receiver: kavadistAcc,
|
receiver: zgChainDistAcc,
|
||||||
amount: ukava(100e6),
|
amount: a0gi(big.NewInt(100)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "transfer from kavadist to community",
|
name: "transfer from kavadist to community",
|
||||||
sender: kavadistAcc,
|
sender: zgChainDistAcc,
|
||||||
receiver: communityAcc,
|
receiver: communityAcc,
|
||||||
amount: ukava(50e6),
|
amount: a0gi(big.NewInt(50)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,42 +138,42 @@ func (suite *IntegrationTestSuite) TestModuleAccountGovTransfers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) submitAndPassProposal(msgs []sdk.Msg) int64 {
|
func (suite *IntegrationTestSuite) submitAndPassProposal(msgs []sdk.Msg) int64 {
|
||||||
govParamsRes, err := suite.Kava.Gov.Params(context.Background(), &govv1.QueryParamsRequest{
|
govParamsRes, err := suite.ZgChain.Gov.Params(context.Background(), &govv1.QueryParamsRequest{
|
||||||
ParamsType: govv1.ParamDeposit,
|
ParamsType: govv1.ParamDeposit,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
kavaAcc := suite.Kava.GetAccount(testutil.FundedAccountName)
|
zgChainAcc := suite.ZgChain.GetAccount(testutil.FundedAccountName)
|
||||||
|
|
||||||
proposalMsg, err := govv1.NewMsgSubmitProposal(
|
proposalMsg, err := govv1.NewMsgSubmitProposal(
|
||||||
msgs,
|
msgs,
|
||||||
govParamsRes.DepositParams.MinDeposit,
|
govParamsRes.DepositParams.MinDeposit,
|
||||||
kavaAcc.SdkAddress.String(),
|
zgChainAcc.SdkAddress.String(),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
gasLimit := 1e6
|
gasLimit := 1e6
|
||||||
fee := ukava(1000)
|
fee := sdk.NewCoin(chaincfg.BaseDenom, sdk.NewInt(1e15))
|
||||||
|
|
||||||
req := util.KavaMsgRequest{
|
req := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{proposalMsg},
|
Msgs: []sdk.Msg{proposalMsg},
|
||||||
GasLimit: uint64(gasLimit),
|
GasLimit: uint64(gasLimit),
|
||||||
FeeAmount: sdk.NewCoins(fee),
|
FeeAmount: sdk.NewCoins(fee),
|
||||||
Memo: "this is a proposal please accept me",
|
Memo: "this is a proposal please accept me",
|
||||||
}
|
}
|
||||||
res := kavaAcc.SignAndBroadcastKavaTx(req)
|
res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||||
suite.Require().NoError(res.Err)
|
suite.Require().NoError(res.Err)
|
||||||
|
|
||||||
// Wait for proposal to be submitted
|
// Wait for proposal to be submitted
|
||||||
txRes, err := util.WaitForSdkTxCommit(suite.Kava.Tx, res.Result.TxHash, 6*time.Second)
|
txRes, err := util.WaitForSdkTxCommit(suite.ZgChain.Tx, res.Result.TxHash, 6*time.Second)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
var govRes govv1.MsgSubmitProposalResponse
|
var govRes govv1.MsgSubmitProposalResponse
|
||||||
suite.decodeTxMsgResponse(txRes, &govRes)
|
suite.decodeTxMsgResponse(txRes, &govRes)
|
||||||
|
|
||||||
// 2. Vote for proposal from whale account
|
// 2. Vote for proposal from whale account
|
||||||
whale := suite.Kava.GetAccount(testutil.FundedAccountName)
|
whale := suite.ZgChain.GetAccount(testutil.FundedAccountName)
|
||||||
voteMsg := govv1.NewMsgVote(
|
voteMsg := govv1.NewMsgVote(
|
||||||
whale.SdkAddress,
|
whale.SdkAddress,
|
||||||
govRes.ProposalId,
|
govRes.ProposalId,
|
||||||
@ -179,21 +181,21 @@ func (suite *IntegrationTestSuite) submitAndPassProposal(msgs []sdk.Msg) int64 {
|
|||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
voteReq := util.KavaMsgRequest{
|
voteReq := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{voteMsg},
|
Msgs: []sdk.Msg{voteMsg},
|
||||||
GasLimit: uint64(gasLimit),
|
GasLimit: uint64(gasLimit),
|
||||||
FeeAmount: sdk.NewCoins(fee),
|
FeeAmount: sdk.NewCoins(fee),
|
||||||
Memo: "voting",
|
Memo: "voting",
|
||||||
}
|
}
|
||||||
voteRes := whale.SignAndBroadcastKavaTx(voteReq)
|
voteRes := whale.SignAndBroadcastZgChainTx(voteReq)
|
||||||
suite.Require().NoError(voteRes.Err)
|
suite.Require().NoError(voteRes.Err)
|
||||||
|
|
||||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Tx, voteRes.Result.TxHash, 6*time.Second)
|
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Tx, voteRes.Result.TxHash, 6*time.Second)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// 3. Wait until proposal passes
|
// 3. Wait until proposal passes
|
||||||
suite.Require().Eventually(func() bool {
|
suite.Require().Eventually(func() bool {
|
||||||
proposalRes, err := suite.Kava.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
proposalRes, err := suite.ZgChain.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
||||||
ProposalId: govRes.ProposalId,
|
ProposalId: govRes.ProposalId,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
@ -215,7 +217,7 @@ func (suite *IntegrationTestSuite) submitAndPassProposal(msgs []sdk.Msg) int64 {
|
|||||||
perPage := 100
|
perPage := 100
|
||||||
|
|
||||||
// Get the block the proposal was passed in
|
// Get the block the proposal was passed in
|
||||||
passBlock, err := suite.Kava.TmSignClient.BlockSearch(
|
passBlock, err := suite.ZgChain.TmSignClient.BlockSearch(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"active_proposal.proposal_result = 'proposal_passed' AND active_proposal.proposal_id = %d",
|
"active_proposal.proposal_result = 'proposal_passed' AND active_proposal.proposal_id = %d",
|
||||||
@ -240,7 +242,7 @@ func (suite *IntegrationTestSuite) getBankTransferAmountAtBlock(
|
|||||||
receiver sdk.AccAddress,
|
receiver sdk.AccAddress,
|
||||||
) []sdk.Coin {
|
) []sdk.Coin {
|
||||||
// Fetch block results for paid staking rewards in the block
|
// Fetch block results for paid staking rewards in the block
|
||||||
blockRes, err := suite.Kava.TmSignClient.BlockResults(
|
blockRes, err := suite.ZgChain.TmSignClient.BlockResults(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&blockHeight,
|
&blockHeight,
|
||||||
)
|
)
|
||||||
|
@ -7,13 +7,13 @@ package e2e_test
|
|||||||
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
||||||
|
|
||||||
// // Before params
|
// // Before params
|
||||||
// incentiveParamsBefore, err := suite.Kava.Incentive.Params(
|
// incentiveParamsBefore, err := suite.ZgChain.Incentive.Params(
|
||||||
// beforeUpgradeCtx,
|
// beforeUpgradeCtx,
|
||||||
// &incentivetypes.QueryParamsRequest{},
|
// &incentivetypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
|
|
||||||
// incentiveParamsAfter, err := suite.Kava.Incentive.Params(
|
// incentiveParamsAfter, err := suite.ZgChain.Incentive.Params(
|
||||||
// afterUpgradeCtx,
|
// afterUpgradeCtx,
|
||||||
// &incentivetypes.QueryParamsRequest{},
|
// &incentivetypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
// afterUpgradeCtx := util.CtxAtHeight(suite.UpgradeHeight)
|
||||||
|
|
||||||
// // Get x/community for switchover time
|
// // Get x/community for switchover time
|
||||||
// params, err := suite.Kava.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
|
// params, err := suite.ZgChain.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
// // Sleep until switchover time + 6 seconds for extra block
|
// // Sleep until switchover time + 6 seconds for extra block
|
||||||
@ -18,7 +18,7 @@ import (
|
|||||||
// time.Sleep(sleepDuration)
|
// time.Sleep(sleepDuration)
|
||||||
|
|
||||||
// suite.Require().Eventually(func() bool {
|
// suite.Require().Eventually(func() bool {
|
||||||
// communityParams, err := suite.Kava.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
|
// communityParams, err := suite.ZgChain.Community.Params(afterUpgradeCtx, &communitytypes.QueryParamsRequest{})
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
// // After params are set in x/community -- non-zero switchover time
|
// // After params are set in x/community -- non-zero switchover time
|
||||||
@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
// // Fetch exact block when inflation stop event emitted
|
// // Fetch exact block when inflation stop event emitted
|
||||||
// // This is run after the switchover, so we don't need to poll
|
// // This is run after the switchover, so we don't need to poll
|
||||||
// _, switchoverHeight, err := suite.Kava.GetBeginBlockEventsFromQuery(
|
// _, switchoverHeight, err := suite.ZgChain.GetBeginBlockEventsFromQuery(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// fmt.Sprintf(
|
// fmt.Sprintf(
|
||||||
// "%s.%s EXISTS",
|
// "%s.%s EXISTS",
|
||||||
@ -43,12 +43,12 @@ import (
|
|||||||
// afterSwitchoverCtx := util.CtxAtHeight(switchoverHeight)
|
// afterSwitchoverCtx := util.CtxAtHeight(switchoverHeight)
|
||||||
|
|
||||||
// suite.Run("x/mint, x/kavadist inflation before switchover", func() {
|
// suite.Run("x/mint, x/kavadist inflation before switchover", func() {
|
||||||
// mintParams, err := suite.Kava.Mint.Params(
|
// mintParams, err := suite.ZgChain.Mint.Params(
|
||||||
// beforeSwitchoverCtx,
|
// beforeSwitchoverCtx,
|
||||||
// &minttypes.QueryParamsRequest{},
|
// &minttypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// kavaDistParams, err := suite.Kava.Kavadist.Params(
|
// kavaDistParams, err := suite.ZgChain.Kavadist.Params(
|
||||||
// beforeSwitchoverCtx,
|
// beforeSwitchoverCtx,
|
||||||
// &kavadisttypes.QueryParamsRequest{},
|
// &kavadisttypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -74,7 +74,7 @@ import (
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
// suite.Run("x/distribution community tax before switchover", func() {
|
// suite.Run("x/distribution community tax before switchover", func() {
|
||||||
// distrParams, err := suite.Kava.Distribution.Params(
|
// distrParams, err := suite.ZgChain.Distribution.Params(
|
||||||
// beforeSwitchoverCtx,
|
// beforeSwitchoverCtx,
|
||||||
// &distributiontypes.QueryParamsRequest{},
|
// &distributiontypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -88,12 +88,12 @@ import (
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
// suite.Run("x/mint, x/kavadist inflation after switchover", func() {
|
// suite.Run("x/mint, x/kavadist inflation after switchover", func() {
|
||||||
// mintParams, err := suite.Kava.Mint.Params(
|
// mintParams, err := suite.ZgChain.Mint.Params(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &minttypes.QueryParamsRequest{},
|
// &minttypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// kavaDistParams, err := suite.Kava.Kavadist.Params(
|
// kavaDistParams, err := suite.ZgChain.Kavadist.Params(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &kavadisttypes.QueryParamsRequest{},
|
// &kavadisttypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -117,7 +117,7 @@ import (
|
|||||||
// })
|
// })
|
||||||
|
|
||||||
// suite.Run("x/distribution community tax after switchover", func() {
|
// suite.Run("x/distribution community tax after switchover", func() {
|
||||||
// distrParams, err := suite.Kava.Distribution.Params(
|
// distrParams, err := suite.ZgChain.Distribution.Params(
|
||||||
// afterSwitchoverCtx,
|
// afterSwitchoverCtx,
|
||||||
// &distributiontypes.QueryParamsRequest{},
|
// &distributiontypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -135,7 +135,7 @@ import (
|
|||||||
// // 1 block before switchover
|
// // 1 block before switchover
|
||||||
// queryHeight := switchoverHeight - 1
|
// queryHeight := switchoverHeight - 1
|
||||||
|
|
||||||
// block, err := suite.Kava.TmSignClient.BlockResults(
|
// block, err := suite.ZgChain.TmSignClient.BlockResults(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &queryHeight,
|
// &queryHeight,
|
||||||
// )
|
// )
|
||||||
@ -178,10 +178,10 @@ import (
|
|||||||
// suite.Run("staking denom supply increases before switchover", func() {
|
// suite.Run("staking denom supply increases before switchover", func() {
|
||||||
// queryHeight := switchoverHeight - 2
|
// queryHeight := switchoverHeight - 2
|
||||||
|
|
||||||
// supply1, err := suite.Kava.Bank.SupplyOf(
|
// supply1, err := suite.ZgChain.Bank.SupplyOf(
|
||||||
// util.CtxAtHeight(queryHeight),
|
// util.CtxAtHeight(queryHeight),
|
||||||
// &types.QuerySupplyOfRequest{
|
// &types.QuerySupplyOfRequest{
|
||||||
// Denom: suite.Kava.StakingDenom,
|
// Denom: suite.ZgChain.StakingDenom,
|
||||||
// },
|
// },
|
||||||
// )
|
// )
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
@ -190,10 +190,10 @@ import (
|
|||||||
|
|
||||||
// // Next block
|
// // Next block
|
||||||
// queryHeight += 1
|
// queryHeight += 1
|
||||||
// supply2, err := suite.Kava.Bank.SupplyOf(
|
// supply2, err := suite.ZgChain.Bank.SupplyOf(
|
||||||
// util.CtxAtHeight(queryHeight),
|
// util.CtxAtHeight(queryHeight),
|
||||||
// &types.QuerySupplyOfRequest{
|
// &types.QuerySupplyOfRequest{
|
||||||
// Denom: suite.Kava.StakingDenom,
|
// Denom: suite.ZgChain.StakingDenom,
|
||||||
// },
|
// },
|
||||||
// )
|
// )
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
@ -210,7 +210,7 @@ import (
|
|||||||
// // Check if inflation is ACTUALLY disabled... check if any coins are being
|
// // Check if inflation is ACTUALLY disabled... check if any coins are being
|
||||||
// // minted in the blocks after switchover
|
// // minted in the blocks after switchover
|
||||||
// suite.Run("no minting after switchover", func() {
|
// suite.Run("no minting after switchover", func() {
|
||||||
// kavaSupply := sdk.NewCoin(suite.Kava.StakingDenom, sdkmath.ZeroInt())
|
// kavaSupply := sdk.NewCoin(suite.ZgChain.StakingDenom, sdkmath.ZeroInt())
|
||||||
|
|
||||||
// // Next 5 blocks after switchover, ensure there's actually no more inflation
|
// // Next 5 blocks after switchover, ensure there's actually no more inflation
|
||||||
// for i := 0; i < 5; i++ {
|
// for i := 0; i < 5; i++ {
|
||||||
@ -222,7 +222,7 @@ import (
|
|||||||
// var block *coretypes.ResultBlockResults
|
// var block *coretypes.ResultBlockResults
|
||||||
// suite.Require().Eventually(func() bool {
|
// suite.Require().Eventually(func() bool {
|
||||||
// // Check begin block events
|
// // Check begin block events
|
||||||
// block, err = suite.Kava.TmSignClient.BlockResults(
|
// block, err = suite.ZgChain.TmSignClient.BlockResults(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &queryHeight,
|
// &queryHeight,
|
||||||
// )
|
// )
|
||||||
@ -270,10 +270,10 @@ import (
|
|||||||
// suite.Run(
|
// suite.Run(
|
||||||
// fmt.Sprintf("total staking denom supply should not change @ height=%d", queryHeight),
|
// fmt.Sprintf("total staking denom supply should not change @ height=%d", queryHeight),
|
||||||
// func() {
|
// func() {
|
||||||
// supplyRes, err := suite.Kava.Bank.SupplyOf(
|
// supplyRes, err := suite.ZgChain.Bank.SupplyOf(
|
||||||
// util.CtxAtHeight(queryHeight),
|
// util.CtxAtHeight(queryHeight),
|
||||||
// &types.QuerySupplyOfRequest{
|
// &types.QuerySupplyOfRequest{
|
||||||
// Denom: suite.Kava.StakingDenom,
|
// Denom: suite.ZgChain.StakingDenom,
|
||||||
// },
|
// },
|
||||||
// )
|
// )
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
@ -297,7 +297,7 @@ import (
|
|||||||
// // 1 block before switchover
|
// // 1 block before switchover
|
||||||
// queryHeight := switchoverHeight - 1
|
// queryHeight := switchoverHeight - 1
|
||||||
|
|
||||||
// block, err := suite.Kava.TmSignClient.BlockResults(
|
// block, err := suite.ZgChain.TmSignClient.BlockResults(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &queryHeight,
|
// &queryHeight,
|
||||||
// )
|
// )
|
||||||
@ -313,7 +313,7 @@ import (
|
|||||||
// // after switchover
|
// // after switchover
|
||||||
// queryHeight := switchoverHeight + int64(i)
|
// queryHeight := switchoverHeight + int64(i)
|
||||||
|
|
||||||
// block, err := suite.Kava.TmSignClient.BlockResults(
|
// block, err := suite.ZgChain.TmSignClient.BlockResults(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &queryHeight,
|
// &queryHeight,
|
||||||
// )
|
// )
|
||||||
@ -358,7 +358,7 @@ import (
|
|||||||
// suite.SkipIfKvtoolDisabled()
|
// suite.SkipIfKvtoolDisabled()
|
||||||
|
|
||||||
// // Get the delegator of the only validator
|
// // Get the delegator of the only validator
|
||||||
// validators, err := suite.Kava.Staking.Validators(
|
// validators, err := suite.ZgChain.Staking.Validators(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &stakingtypes.QueryValidatorsRequest{},
|
// &stakingtypes.QueryValidatorsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -370,17 +370,17 @@ import (
|
|||||||
|
|
||||||
// accAddr := sdk.AccAddress(valAddr.Bytes())
|
// accAddr := sdk.AccAddress(valAddr.Bytes())
|
||||||
|
|
||||||
// balBefore, err := suite.Kava.Bank.Balance(
|
// balBefore, err := suite.ZgChain.Bank.Balance(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &types.QueryBalanceRequest{
|
// &types.QueryBalanceRequest{
|
||||||
// Address: accAddr.String(),
|
// Address: accAddr.String(),
|
||||||
// Denom: suite.Kava.StakingDenom,
|
// Denom: suite.ZgChain.StakingDenom,
|
||||||
// },
|
// },
|
||||||
// )
|
// )
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
// suite.Require().False(balBefore.Balance.IsZero(), "val staking denom balance should be non-zero")
|
// suite.Require().False(balBefore.Balance.IsZero(), "val staking denom balance should be non-zero")
|
||||||
|
|
||||||
// delegationRewards, err := suite.Kava.Distribution.DelegationRewards(
|
// delegationRewards, err := suite.ZgChain.Distribution.DelegationRewards(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &distributiontypes.QueryDelegationRewardsRequest{
|
// &distributiontypes.QueryDelegationRewardsRequest{
|
||||||
// ValidatorAddress: valAddr.String(),
|
// ValidatorAddress: valAddr.String(),
|
||||||
@ -398,16 +398,16 @@ import (
|
|||||||
// )
|
// )
|
||||||
|
|
||||||
// // Get the validator private key from kava keyring
|
// // Get the validator private key from kava keyring
|
||||||
// key, err := suite.Kava.Keyring.(unsafeExporter).ExportPrivateKeyObject(
|
// key, err := suite.ZgChain.Keyring.(unsafeExporter).ExportPrivateKeyObject(
|
||||||
// "validator",
|
// "validator",
|
||||||
// )
|
// )
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
// acc := suite.Kava.AddNewSigningAccountFromPrivKey(
|
// acc := suite.ZgChain.AddNewSigningAccountFromPrivKey(
|
||||||
// "validator",
|
// "validator",
|
||||||
// key,
|
// key,
|
||||||
// "",
|
// "",
|
||||||
// suite.Kava.ChainID,
|
// suite.ZgChain.ChainID,
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// gasLimit := int64(2e5)
|
// gasLimit := int64(2e5)
|
||||||
@ -420,14 +420,14 @@ import (
|
|||||||
// }
|
// }
|
||||||
// res := acc.SignAndBroadcastKavaTx(req)
|
// res := acc.SignAndBroadcastKavaTx(req)
|
||||||
|
|
||||||
// _, err = util.WaitForSdkTxCommit(suite.Kava.Tx, res.Result.TxHash, 6*time.Second)
|
// _, err = util.WaitForSdkTxCommit(suite.ZgChain.Tx, res.Result.TxHash, 6*time.Second)
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
// balAfter, err := suite.Kava.Bank.Balance(
|
// balAfter, err := suite.ZgChain.Bank.Balance(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &types.QueryBalanceRequest{
|
// &types.QueryBalanceRequest{
|
||||||
// Address: accAddr.String(),
|
// Address: accAddr.String(),
|
||||||
// Denom: suite.Kava.StakingDenom,
|
// Denom: suite.ZgChain.StakingDenom,
|
||||||
// },
|
// },
|
||||||
// )
|
// )
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
@ -440,11 +440,11 @@ import (
|
|||||||
// queriedRewardsCoins, _ := delegationRewards.Rewards.TruncateDecimal()
|
// queriedRewardsCoins, _ := delegationRewards.Rewards.TruncateDecimal()
|
||||||
|
|
||||||
// suite.Require().Truef(
|
// suite.Require().Truef(
|
||||||
// queriedRewardsCoins.AmountOf(suite.Kava.StakingDenom).
|
// queriedRewardsCoins.AmountOf(suite.ZgChain.StakingDenom).
|
||||||
// LTE(balIncrease.Amount),
|
// LTE(balIncrease.Amount),
|
||||||
// "claimed rewards should be >= queried delegation rewards, got claimed %s vs queried %s",
|
// "claimed rewards should be >= queried delegation rewards, got claimed %s vs queried %s",
|
||||||
// balIncrease.Amount.String(),
|
// balIncrease.Amount.String(),
|
||||||
// queriedRewardsCoins.AmountOf(suite.Kava.StakingDenom).String(),
|
// queriedRewardsCoins.AmountOf(suite.ZgChain.StakingDenom).String(),
|
||||||
// )
|
// )
|
||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
@ -19,7 +19,7 @@ func (suite *IntegrationTestSuite) TestValMinCommission() {
|
|||||||
|
|
||||||
suite.Run("before upgrade", func() {
|
suite.Run("before upgrade", func() {
|
||||||
// Before params
|
// Before params
|
||||||
beforeParams, err := suite.Kava.Staking.Params(beforeUpgradeCtx, &types.QueryParamsRequest{})
|
beforeParams, err := suite.ZgChain.Staking.Params(beforeUpgradeCtx, &types.QueryParamsRequest{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
suite.Require().Equal(
|
suite.Require().Equal(
|
||||||
@ -29,7 +29,7 @@ func (suite *IntegrationTestSuite) TestValMinCommission() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Before validators
|
// Before validators
|
||||||
beforeValidators, err := suite.Kava.Staking.Validators(beforeUpgradeCtx, &types.QueryValidatorsRequest{})
|
beforeValidators, err := suite.ZgChain.Staking.Validators(beforeUpgradeCtx, &types.QueryValidatorsRequest{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
for _, val := range beforeValidators.Validators {
|
for _, val := range beforeValidators.Validators {
|
||||||
@ -56,13 +56,13 @@ func (suite *IntegrationTestSuite) TestValMinCommission() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
suite.Run("after upgrade", func() {
|
suite.Run("after upgrade", func() {
|
||||||
block, err := suite.Kava.Tm.GetBlockByHeight(context.Background(), &tmservice.GetBlockByHeightRequest{
|
block, err := suite.ZgChain.Tm.GetBlockByHeight(context.Background(), &tmservice.GetBlockByHeightRequest{
|
||||||
Height: suite.UpgradeHeight,
|
Height: suite.UpgradeHeight,
|
||||||
})
|
})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// After params
|
// After params
|
||||||
afterParams, err := suite.Kava.Staking.Params(afterUpgradeCtx, &types.QueryParamsRequest{})
|
afterParams, err := suite.ZgChain.Staking.Params(afterUpgradeCtx, &types.QueryParamsRequest{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
expectedMinRate := sdk.MustNewDecFromStr("0.05")
|
expectedMinRate := sdk.MustNewDecFromStr("0.05")
|
||||||
@ -74,7 +74,7 @@ func (suite *IntegrationTestSuite) TestValMinCommission() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// After validators
|
// After validators
|
||||||
afterValidators, err := suite.Kava.Staking.Validators(afterUpgradeCtx, &types.QueryValidatorsRequest{})
|
afterValidators, err := suite.ZgChain.Staking.Validators(afterUpgradeCtx, &types.QueryValidatorsRequest{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
for _, val := range afterValidators.Validators {
|
for _, val := range afterValidators.Validators {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
rpchttpclient "github.com/cometbft/cometbft/rpc/client/http"
|
rpchttpclient "github.com/cometbft/cometbft/rpc/client/http"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
)
|
)
|
||||||
@ -67,20 +68,20 @@ func (c *Chains) Register(name string, chain *ChainDetails) error {
|
|||||||
// the Chain details are all hardcoded because they are currently fixed by kvtool.
|
// the Chain details are all hardcoded because they are currently fixed by kvtool.
|
||||||
// someday they may be accepted as configurable parameters.
|
// someday they may be accepted as configurable parameters.
|
||||||
var (
|
var (
|
||||||
kvtoolKavaChain = ChainDetails{
|
kvtoolZgChainChain = ChainDetails{
|
||||||
RpcUrl: "http://localhost:26657",
|
RpcUrl: "http://localhost:26657",
|
||||||
GrpcUrl: "http://localhost:9090",
|
GrpcUrl: "http://localhost:9090",
|
||||||
EvmRpcUrl: "http://localhost:8545",
|
EvmRpcUrl: "http://localhost:8545",
|
||||||
|
|
||||||
ChainId: "kavalocalnet_8888-1",
|
ChainId: "0gchainlocalnet_8888-1",
|
||||||
StakingDenom: "ukava",
|
StakingDenom: chaincfg.DisplayDenom,
|
||||||
}
|
}
|
||||||
kvtoolIbcChain = ChainDetails{
|
kvtoolIbcChain = ChainDetails{
|
||||||
RpcUrl: "http://localhost:26658",
|
RpcUrl: "http://localhost:26658",
|
||||||
GrpcUrl: "http://localhost:9092",
|
GrpcUrl: "http://localhost:9092",
|
||||||
EvmRpcUrl: "http://localhost:8547",
|
EvmRpcUrl: "http://localhost:8547",
|
||||||
|
|
||||||
ChainId: "kavalocalnet_8889-2",
|
ChainId: "0gchainlocalnet_8889-2",
|
||||||
StakingDenom: "uatom",
|
StakingDenom: "uatom",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -8,24 +8,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type KvtoolRunnerConfig struct {
|
type KvtoolRunnerConfig struct {
|
||||||
KavaConfigTemplate string
|
ZgChainConfigTemplate string
|
||||||
|
|
||||||
ImageTag string
|
ImageTag string
|
||||||
IncludeIBC bool
|
IncludeIBC bool
|
||||||
|
|
||||||
EnableAutomatedUpgrade bool
|
EnableAutomatedUpgrade bool
|
||||||
KavaUpgradeName string
|
ZgChainUpgradeName string
|
||||||
KavaUpgradeHeight int64
|
ZgChainUpgradeHeight int64
|
||||||
KavaUpgradeBaseImageTag string
|
ZgChainUpgradeBaseImageTag string
|
||||||
|
|
||||||
SkipShutdown bool
|
SkipShutdown bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// KvtoolRunner implements a NodeRunner that spins up local chains with kvtool.
|
// KvtoolRunner implements a NodeRunner that spins up local chains with kvtool.
|
||||||
// It has support for the following:
|
// It has support for the following:
|
||||||
// - running a Kava node
|
// - running a ZgChain node
|
||||||
// - optionally, running an IBC node with a channel opened to the Kava node
|
// - optionally, running an IBC node with a channel opened to the ZgChain node
|
||||||
// - optionally, start the Kava node on one version and upgrade to another
|
// - optionally, start the ZgChain node on one version and upgrade to another
|
||||||
type KvtoolRunner struct {
|
type KvtoolRunner struct {
|
||||||
config KvtoolRunnerConfig
|
config KvtoolRunnerConfig
|
||||||
}
|
}
|
||||||
@ -51,8 +51,8 @@ func (k *KvtoolRunner) StartChains() Chains {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start local test network with kvtool
|
// start local test network with kvtool
|
||||||
log.Println("starting kava node")
|
log.Println("starting 0gchain node")
|
||||||
kvtoolArgs := []string{"testnet", "bootstrap", "--kava.configTemplate", k.config.KavaConfigTemplate}
|
kvtoolArgs := []string{"testnet", "bootstrap", "--0gchain.configTemplate", k.config.ZgChainConfigTemplate}
|
||||||
// include an ibc chain if desired
|
// include an ibc chain if desired
|
||||||
if k.config.IncludeIBC {
|
if k.config.IncludeIBC {
|
||||||
kvtoolArgs = append(kvtoolArgs, "--ibc")
|
kvtoolArgs = append(kvtoolArgs, "--ibc")
|
||||||
@ -60,32 +60,32 @@ func (k *KvtoolRunner) StartChains() Chains {
|
|||||||
// handle automated upgrade functionality, if defined
|
// handle automated upgrade functionality, if defined
|
||||||
if k.config.EnableAutomatedUpgrade {
|
if k.config.EnableAutomatedUpgrade {
|
||||||
kvtoolArgs = append(kvtoolArgs,
|
kvtoolArgs = append(kvtoolArgs,
|
||||||
"--upgrade-name", k.config.KavaUpgradeName,
|
"--upgrade-name", k.config.ZgChainUpgradeName,
|
||||||
"--upgrade-height", fmt.Sprint(k.config.KavaUpgradeHeight),
|
"--upgrade-height", fmt.Sprint(k.config.ZgChainUpgradeHeight),
|
||||||
"--upgrade-base-image-tag", k.config.KavaUpgradeBaseImageTag,
|
"--upgrade-base-image-tag", k.config.ZgChainUpgradeBaseImageTag,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// start the chain
|
// start the chain
|
||||||
startKavaCmd := exec.Command("kvtool", kvtoolArgs...)
|
startZgChainCmd := exec.Command("kvtool", kvtoolArgs...)
|
||||||
startKavaCmd.Env = os.Environ()
|
startZgChainCmd.Env = os.Environ()
|
||||||
startKavaCmd.Env = append(startKavaCmd.Env, fmt.Sprintf("KAVA_TAG=%s", k.config.ImageTag))
|
startZgChainCmd.Env = append(startZgChainCmd.Env, fmt.Sprintf("0GCHAIN_TAG=%s", k.config.ImageTag))
|
||||||
startKavaCmd.Stdout = os.Stdout
|
startZgChainCmd.Stdout = os.Stdout
|
||||||
startKavaCmd.Stderr = os.Stderr
|
startZgChainCmd.Stderr = os.Stderr
|
||||||
log.Println(startKavaCmd.String())
|
log.Println(startZgChainCmd.String())
|
||||||
if err := startKavaCmd.Run(); err != nil {
|
if err := startZgChainCmd.Run(); err != nil {
|
||||||
panic(fmt.Sprintf("failed to start kava: %s", err.Error()))
|
panic(fmt.Sprintf("failed to start 0gchain: %s", err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for chain to be live.
|
// wait for chain to be live.
|
||||||
// if an upgrade is defined, this waits for the upgrade to be completed.
|
// 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()
|
k.Shutdown()
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Println("kava is started!")
|
log.Println("0gchain is started!")
|
||||||
|
|
||||||
chains := NewChains()
|
chains := NewChains()
|
||||||
chains.Register("kava", &kvtoolKavaChain)
|
chains.Register("0gchain", &kvtoolZgChainChain)
|
||||||
if k.config.IncludeIBC {
|
if k.config.IncludeIBC {
|
||||||
chains.Register("ibc", &kvtoolIbcChain)
|
chains.Register("ibc", &kvtoolIbcChain)
|
||||||
}
|
}
|
||||||
@ -101,11 +101,11 @@ func (k *KvtoolRunner) Shutdown() {
|
|||||||
log.Printf("would shut down but SkipShutdown is true")
|
log.Printf("would shut down but SkipShutdown is true")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("shutting down kava node")
|
log.Println("shutting down 0gchain node")
|
||||||
shutdownKavaCmd := exec.Command("kvtool", "testnet", "down")
|
shutdownZgChainCmd := exec.Command("kvtool", "testnet", "down")
|
||||||
shutdownKavaCmd.Stdout = os.Stdout
|
shutdownZgChainCmd.Stdout = os.Stdout
|
||||||
shutdownKavaCmd.Stderr = os.Stderr
|
shutdownZgChainCmd.Stderr = os.Stderr
|
||||||
if err := shutdownKavaCmd.Run(); err != nil {
|
if err := shutdownZgChainCmd.Run(); err != nil {
|
||||||
panic(fmt.Sprintf("failed to shutdown kvtool: %s", err.Error()))
|
panic(fmt.Sprintf("failed to shutdown kvtool: %s", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,15 @@ import (
|
|||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
|
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
|
||||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
|
"github.com/influxdata/influxdb/client"
|
||||||
"github.com/kava-labs/kava/client/grpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LiveNodeRunnerConfig implements NodeRunner.
|
// LiveNodeRunnerConfig implements NodeRunner.
|
||||||
// It connects to a running network via the RPC, GRPC, and EVM urls.
|
// It connects to a running network via the RPC, GRPC, and EVM urls.
|
||||||
type LiveNodeRunnerConfig struct {
|
type LiveNodeRunnerConfig struct {
|
||||||
KavaRpcUrl string
|
ZgChainRpcUrl string
|
||||||
KavaGrpcUrl string
|
ZgChainGrpcUrl string
|
||||||
KavaEvmRpcUrl string
|
ZgChainEvmRpcUrl string
|
||||||
|
|
||||||
UpgradeHeight int64
|
UpgradeHeight int64
|
||||||
}
|
}
|
||||||
@ -37,41 +36,41 @@ func NewLiveNodeRunner(config LiveNodeRunnerConfig) *LiveNodeRunner {
|
|||||||
// It initializes connections to the chain based on parameters.
|
// It initializes connections to the chain based on parameters.
|
||||||
// It attempts to ping the necessary endpoints and panics if they cannot be reached.
|
// It attempts to ping the necessary endpoints and panics if they cannot be reached.
|
||||||
func (r LiveNodeRunner) StartChains() Chains {
|
func (r LiveNodeRunner) StartChains() Chains {
|
||||||
fmt.Println("establishing connection to live kava network")
|
fmt.Println("establishing connection to live 0g-chain network")
|
||||||
chains := NewChains()
|
chains := NewChains()
|
||||||
|
|
||||||
kavaChain := ChainDetails{
|
zgChain := ChainDetails{
|
||||||
RpcUrl: r.config.KavaRpcUrl,
|
RpcUrl: r.config.ZgChainRpcUrl,
|
||||||
GrpcUrl: r.config.KavaGrpcUrl,
|
GrpcUrl: r.config.ZgChainGrpcUrl,
|
||||||
EvmRpcUrl: r.config.KavaEvmRpcUrl,
|
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))
|
panic(fmt.Sprintf("failed to ping chain: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine chain id
|
// determine chain id
|
||||||
client, err := grpc.NewClient(kavaChain.GrpcUrl)
|
grpc, err := zgChain.GrpcConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to create kava grpc client: %s", err))
|
panic(fmt.Sprintf("failed to establish grpc conn to %s: %s", r.config.ZgChainGrpcUrl, err))
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to fetch kava node info: %s", err))
|
panic(fmt.Sprintf("failed to fetch 0-chain node info: %s", err))
|
||||||
}
|
}
|
||||||
kavaChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
zgChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
||||||
|
|
||||||
// determine staking denom
|
// determine staking denom
|
||||||
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
|
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to fetch kava staking params: %s", err))
|
panic(fmt.Sprintf("failed to fetch 0gchain 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
|
return chains
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ func waitForChainStart(chainDetails ChainDetails) error {
|
|||||||
b := backoff.NewExponentialBackOff()
|
b := backoff.NewExponentialBackOff()
|
||||||
b.MaxInterval = 5 * time.Second
|
b.MaxInterval = 5 * time.Second
|
||||||
b.MaxElapsedTime = 30 * 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)
|
return fmt.Errorf("failed connect to chain: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,9 +34,9 @@ func waitForChainStart(chainDetails ChainDetails) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func pingKava(rpcUrl string) error {
|
func pingZgChain(rpcUrl string) error {
|
||||||
statusUrl := fmt.Sprintf("%s/status", rpcUrl)
|
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)
|
res, err := http.Get(statusUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -45,7 +45,7 @@ func pingKava(rpcUrl string) error {
|
|||||||
if res.StatusCode >= 400 {
|
if res.StatusCode >= 400 {
|
||||||
return fmt.Errorf("ping to status failed: %d", res.StatusCode)
|
return fmt.Errorf("ping to status failed: %d", res.StatusCode)
|
||||||
}
|
}
|
||||||
log.Println("successfully started Kava!")
|
log.Println("successfully started ZgChain!")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
emtests "github.com/evmos/ethermint/tests"
|
emtests "github.com/evmos/ethermint/tests"
|
||||||
emtypes "github.com/evmos/ethermint/types"
|
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"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,9 +43,9 @@ type SigningAccount struct {
|
|||||||
evmReqChan chan<- util.EvmTxRequest
|
evmReqChan chan<- util.EvmTxRequest
|
||||||
evmResChan <-chan util.EvmTxResponse
|
evmResChan <-chan util.EvmTxResponse
|
||||||
|
|
||||||
kavaSigner *util.KavaSigner
|
zgChainSigner *util.ZgChainSigner
|
||||||
sdkReqChan chan<- util.KavaMsgRequest
|
sdkReqChan chan<- util.ZgChainMsgRequest
|
||||||
sdkResChan <-chan util.KavaMsgResponse
|
sdkResChan <-chan util.ZgChainMsgResponse
|
||||||
|
|
||||||
EvmAuth *bind.TransactOpts
|
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)
|
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())
|
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)
|
require.NoErrorf(chain.t, err, "failed to derive private key from mnemonic for %s: %s", name, err)
|
||||||
privKey := ðsecp256k1.PrivKey{Key: privKeyBytes}
|
privKey := ðsecp256k1.PrivKey{Key: privKeyBytes}
|
||||||
@ -97,8 +97,8 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
|||||||
chain.t.Fatalf("account with name %s already exists", name)
|
chain.t.Fatalf("account with name %s already exists", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kava signing account for SDK side
|
// 0gChain signing account for SDK side
|
||||||
kavaSigner := util.NewKavaSigner(
|
zgChainSigner := util.NewZgChainSigner(
|
||||||
chainId,
|
chainId,
|
||||||
chain.EncodingConfig,
|
chain.EncodingConfig,
|
||||||
chain.Grpc.Query.Auth,
|
chain.Grpc.Query.Auth,
|
||||||
@ -107,11 +107,11 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
|||||||
100,
|
100,
|
||||||
)
|
)
|
||||||
|
|
||||||
sdkReqChan := make(chan util.KavaMsgRequest)
|
sdkReqChan := make(chan util.ZgChainMsgRequest)
|
||||||
sdkResChan, err := kavaSigner.Run(sdkReqChan)
|
sdkResChan, err := zgChainSigner.Run(sdkReqChan)
|
||||||
require.NoErrorf(chain.t, err, "failed to start signer for account %s: %s", name, err)
|
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)
|
evmChainId, err := emtypes.ParseChainID(chainId)
|
||||||
require.NoErrorf(chain.t, err, "unable to parse ethermint-compatible chain id from %s", chainId)
|
require.NoErrorf(chain.t, err, "unable to parse ethermint-compatible chain id from %s", chainId)
|
||||||
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes()))
|
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes()))
|
||||||
@ -141,21 +141,21 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
|||||||
evmReqChan: evmReqChan,
|
evmReqChan: evmReqChan,
|
||||||
evmResChan: evmResChan,
|
evmResChan: evmResChan,
|
||||||
|
|
||||||
kavaSigner: kavaSigner,
|
zgChainSigner: zgChainSigner,
|
||||||
sdkReqChan: sdkReqChan,
|
sdkReqChan: sdkReqChan,
|
||||||
sdkResChan: sdkResChan,
|
sdkResChan: sdkResChan,
|
||||||
|
|
||||||
EvmAuth: evmSigner.Auth,
|
EvmAuth: evmSigner.Auth,
|
||||||
|
|
||||||
EvmAddress: evmSigner.Address(),
|
EvmAddress: evmSigner.Address(),
|
||||||
SdkAddress: kavaSigner.Address(),
|
SdkAddress: zgChainSigner.Address(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return chain.accounts[name]
|
return chain.accounts[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignAndBroadcastKavaTx sends a request to the signer and awaits its response.
|
// SignAndBroadcastZgChainTx sends a request to the signer and awaits its response.
|
||||||
func (a *SigningAccount) SignAndBroadcastKavaTx(req util.KavaMsgRequest) util.KavaMsgResponse {
|
func (a *SigningAccount) SignAndBroadcastZgChainTx(req util.ZgChainMsgRequest) util.ZgChainMsgResponse {
|
||||||
a.l.Printf("broadcasting sdk tx. has data = %+v\n", req.Data)
|
a.l.Printf("broadcasting sdk tx. has data = %+v\n", req.Data)
|
||||||
// send the request to signer
|
// send the request to signer
|
||||||
a.sdkReqChan <- req
|
a.sdkReqChan <- req
|
||||||
@ -222,7 +222,7 @@ func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccou
|
|||||||
|
|
||||||
acc := chain.AddNewSigningAccount(
|
acc := chain.AddNewSigningAccount(
|
||||||
name,
|
name,
|
||||||
hd.CreateHDPath(app.Bip44CoinType, 0, 0),
|
hd.CreateHDPath(chaincfg.Bip44CoinType, 0, 0),
|
||||||
chain.ChainID,
|
chain.ChainID,
|
||||||
mnemonic,
|
mnemonic,
|
||||||
)
|
)
|
||||||
@ -257,12 +257,12 @@ func (a *SigningAccount) NextNonce() (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BankSend is a helper method for sending funds via x/bank's MsgSend
|
// 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 {
|
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.ZgChainMsgResponse {
|
||||||
return a.SignAndBroadcastKavaTx(
|
return a.SignAndBroadcastZgChainTx(
|
||||||
util.KavaMsgRequest{
|
util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)},
|
Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)},
|
||||||
GasLimit: 2e5, // 200,000 gas
|
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),
|
Data: fmt.Sprintf("sending %s to %s", amount, to),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"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/tests/e2e/runner"
|
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
committeetypes "github.com/0glabs/0g-chain/x/committee/types"
|
committeetypes "github.com/0glabs/0g-chain/x/committee/types"
|
||||||
@ -45,7 +45,7 @@ type Chain struct {
|
|||||||
ContractAddrs map[string]common.Address
|
ContractAddrs map[string]common.Address
|
||||||
erc20s map[common.Address]struct{}
|
erc20s map[common.Address]struct{}
|
||||||
|
|
||||||
EncodingConfig kavaparams.EncodingConfig
|
EncodingConfig chainparams.EncodingConfig
|
||||||
|
|
||||||
Auth authtypes.QueryClient
|
Auth authtypes.QueryClient
|
||||||
Authz authz.QueryClient
|
Authz authz.QueryClient
|
||||||
@ -83,7 +83,7 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
|||||||
kr, err := keyring.New(
|
kr, err := keyring.New(
|
||||||
sdk.KeyringServiceName(),
|
sdk.KeyringServiceName(),
|
||||||
keyring.BackendTest,
|
keyring.BackendTest,
|
||||||
util.KavaHomePath(),
|
util.ZgChainHomePath(),
|
||||||
nil,
|
nil,
|
||||||
chain.EncodingConfig.Marshaler,
|
chain.EncodingConfig.Marshaler,
|
||||||
evmhd.EthSecp256k1Option(),
|
evmhd.EthSecp256k1Option(),
|
||||||
|
@ -36,26 +36,26 @@ type SuiteConfig struct {
|
|||||||
// KvtoolConfig wraps configuration options for running the end-to-end test suite against
|
// 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.
|
// a locally running chain. This config must be defined if E2E_RUN_KVTOOL_NETWORKS is true.
|
||||||
type KvtoolConfig struct {
|
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.
|
// 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.
|
// Whether or not to run a chain upgrade & run post-upgrade tests. Use `suite.SkipIfUpgradeDisabled()` in post-upgrade tests.
|
||||||
IncludeAutomatedUpgrade bool
|
IncludeAutomatedUpgrade bool
|
||||||
// Name of the upgrade, if upgrade is enabled.
|
// 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.
|
// Height upgrade will be applied to the test chain, if upgrade is enabled.
|
||||||
KavaUpgradeHeight int64
|
ZgChainUpgradeHeight int64
|
||||||
// Tag of kava docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
|
// Tag of 0gchain docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
|
||||||
KavaUpgradeBaseImageTag string
|
ZgChainUpgradeBaseImageTag string
|
||||||
}
|
}
|
||||||
|
|
||||||
// LiveNetworkConfig wraps configuration options for running the end-to-end test suite
|
// 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.
|
// against a live network. It must be defined if E2E_RUN_KVTOOL_NETWORKS is false.
|
||||||
type LiveNetworkConfig struct {
|
type LiveNetworkConfig struct {
|
||||||
KavaRpcUrl string
|
ZgChainRpcUrl string
|
||||||
KavaGrpcUrl string
|
ZgChainGrpcUrl string
|
||||||
KavaEvmRpcUrl string
|
ZgChainEvmRpcUrl string
|
||||||
|
|
||||||
UpgradeHeight int64
|
UpgradeHeight int64
|
||||||
}
|
}
|
||||||
@ -65,8 +65,8 @@ func ParseSuiteConfig() SuiteConfig {
|
|||||||
config := SuiteConfig{
|
config := SuiteConfig{
|
||||||
// this mnemonic is expected to be a funded account that can seed the funds for all
|
// 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"]
|
// new accounts created during tests. it will be available under Accounts["whale"]
|
||||||
FundedAccountMnemonic: nonemptyStringEnv("E2E_KAVA_FUNDED_ACCOUNT_MNEMONIC"),
|
FundedAccountMnemonic: nonemptyStringEnv("E2E_0GCHAIN_FUNDED_ACCOUNT_MNEMONIC"),
|
||||||
ZgChainErc20Address: nonemptyStringEnv("E2E_KAVA_ERC20_ADDRESS"),
|
ZgChainErc20Address: nonemptyStringEnv("E2E_0GCHAIN_ERC20_ADDRESS"),
|
||||||
IncludeIbcTests: mustParseBool("E2E_INCLUDE_IBC_TESTS"),
|
IncludeIbcTests: mustParseBool("E2E_INCLUDE_IBC_TESTS"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,18 +90,18 @@ func ParseSuiteConfig() SuiteConfig {
|
|||||||
// ParseKvtoolConfig builds a KvtoolConfig from environment variables.
|
// ParseKvtoolConfig builds a KvtoolConfig from environment variables.
|
||||||
func ParseKvtoolConfig() KvtoolConfig {
|
func ParseKvtoolConfig() KvtoolConfig {
|
||||||
config := KvtoolConfig{
|
config := KvtoolConfig{
|
||||||
KavaConfigTemplate: nonemptyStringEnv("E2E_KVTOOL_KAVA_CONFIG_TEMPLATE"),
|
ZgChainConfigTemplate: nonemptyStringEnv("E2E_KVTOOL_0GCHAIN_CONFIG_TEMPLATE"),
|
||||||
IncludeAutomatedUpgrade: mustParseBool("E2E_INCLUDE_AUTOMATED_UPGRADE"),
|
IncludeAutomatedUpgrade: mustParseBool("E2E_INCLUDE_AUTOMATED_UPGRADE"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.IncludeAutomatedUpgrade {
|
if config.IncludeAutomatedUpgrade {
|
||||||
config.KavaUpgradeName = nonemptyStringEnv("E2E_KAVA_UPGRADE_NAME")
|
config.ZgChainUpgradeName = nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_NAME")
|
||||||
config.KavaUpgradeBaseImageTag = nonemptyStringEnv("E2E_KAVA_UPGRADE_BASE_IMAGE_TAG")
|
config.ZgChainUpgradeBaseImageTag = nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_BASE_IMAGE_TAG")
|
||||||
upgradeHeight, err := strconv.ParseInt(nonemptyStringEnv("E2E_KAVA_UPGRADE_HEIGHT"), 10, 64)
|
upgradeHeight, err := strconv.ParseInt(nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_HEIGHT"), 10, 64)
|
||||||
if err != nil {
|
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
|
return config
|
||||||
@ -110,16 +110,16 @@ func ParseKvtoolConfig() KvtoolConfig {
|
|||||||
// ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.
|
// ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.
|
||||||
func ParseLiveNetworkConfig() LiveNetworkConfig {
|
func ParseLiveNetworkConfig() LiveNetworkConfig {
|
||||||
config := LiveNetworkConfig{
|
config := LiveNetworkConfig{
|
||||||
KavaRpcUrl: nonemptyStringEnv("E2E_KAVA_RPC_URL"),
|
ZgChainRpcUrl: nonemptyStringEnv("E2E_0GCHAIN_RPC_URL"),
|
||||||
KavaGrpcUrl: nonemptyStringEnv("E2E_KAVA_GRPC_URL"),
|
ZgChainGrpcUrl: nonemptyStringEnv("E2E_0GCHAIN_GRPC_URL"),
|
||||||
KavaEvmRpcUrl: nonemptyStringEnv("E2E_KAVA_EVM_RPC_URL"),
|
ZgChainEvmRpcUrl: nonemptyStringEnv("E2E_0GCHAIN_EVM_RPC_URL"),
|
||||||
}
|
}
|
||||||
|
|
||||||
upgradeHeight := os.Getenv("E2E_KAVA_UPGRADE_HEIGHT")
|
upgradeHeight := os.Getenv("E2E_0GCHAIN_UPGRADE_HEIGHT")
|
||||||
if upgradeHeight != "" {
|
if upgradeHeight != "" {
|
||||||
parsedHeight, err := strconv.ParseInt(upgradeHeight, 10, 64)
|
parsedHeight, err := strconv.ParseInt(upgradeHeight, 10, 64)
|
||||||
if err != nil {
|
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
|
config.UpgradeHeight = parsedHeight
|
||||||
|
@ -11,13 +11,13 @@ import (
|
|||||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
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.
|
// It is used to initialize some EVM state, such as deploying contracts.
|
||||||
func (suite *E2eTestSuite) InitKavaEvmData() {
|
func (suite *E2eTestSuite) InitZgChainEvmData() {
|
||||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||||
|
|
||||||
// ensure funded account has nonzero erc20 balance
|
// 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 {
|
if balance.Cmp(big.NewInt(0)) != 1 {
|
||||||
panic(fmt.Sprintf(
|
panic(fmt.Sprintf(
|
||||||
"expected funded account (%s) to have erc20 balance of token %s",
|
"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
|
// 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.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to fetch evmutil params during init: %s", err))
|
panic(fmt.Sprintf("failed to fetch evmutil params during init: %s", err))
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
|||||||
if !found {
|
if !found {
|
||||||
panic(fmt.Sprintf("erc20 %s must be enabled for conversion to cosmos coin", erc20Addr))
|
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)
|
||||||
|
|
||||||
// deploy an example contract
|
// deploy an example contract
|
||||||
greeterAddr, _, _, err := greeter.DeployGreeter(
|
greeterAddr, _, _, err := greeter.DeployGreeter(
|
||||||
@ -51,13 +51,13 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
|||||||
"what's up!",
|
"what's up!",
|
||||||
)
|
)
|
||||||
suite.NoError(err, "failed to deploy a contract to the EVM")
|
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`.
|
// FundZgChainErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.
|
||||||
func (suite *E2eTestSuite) FundKavaErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
|
func (suite *E2eTestSuite) FundZgChainErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
|
||||||
// funded account should have erc20 balance
|
// 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)
|
res, err := whale.TransferErc20(suite.DeployedErc20.Address, toAddress, amount)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
return res
|
return res
|
||||||
|
@ -10,14 +10,14 @@ import (
|
|||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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/e2e/runner"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FundedAccountName = "whale"
|
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
|
// these accounts use the ethsecp256k1 signing algorithm that allows the signing client
|
||||||
// to manage both sdk & evm txs.
|
// to manage both sdk & evm txs.
|
||||||
Bip44CoinType = 60
|
Bip44CoinType = 60
|
||||||
@ -33,7 +33,7 @@ const (
|
|||||||
// - the funded account has a nonzero balance of the erc20
|
// - the funded account has a nonzero balance of the erc20
|
||||||
// - the erc20 is enabled for conversion to sdk.Coin
|
// - the erc20 is enabled for conversion to sdk.Coin
|
||||||
// - the corresponding sdk.Coin is enabled as a cdp collateral type
|
// - 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 {
|
type DeployedErc20 struct {
|
||||||
Address common.Address
|
Address common.Address
|
||||||
CosmosDenom string
|
CosmosDenom string
|
||||||
@ -41,14 +41,14 @@ type DeployedErc20 struct {
|
|||||||
CdpCollateralType string
|
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 {
|
type E2eTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
config SuiteConfig
|
config SuiteConfig
|
||||||
runner runner.NodeRunner
|
runner runner.NodeRunner
|
||||||
|
|
||||||
Kava *Chain
|
ZgChain *Chain
|
||||||
Ibc *Chain
|
Ibc *Chain
|
||||||
|
|
||||||
UpgradeHeight int64
|
UpgradeHeight int64
|
||||||
@ -85,13 +85,13 @@ func (s costSummary) String() string {
|
|||||||
func (suite *E2eTestSuite) SetupSuite() {
|
func (suite *E2eTestSuite) SetupSuite() {
|
||||||
var err error
|
var err error
|
||||||
fmt.Println("setting up test suite.")
|
fmt.Println("setting up test suite.")
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
|
|
||||||
suiteConfig := ParseSuiteConfig()
|
suiteConfig := ParseSuiteConfig()
|
||||||
suite.config = suiteConfig
|
suite.config = suiteConfig
|
||||||
suite.DeployedErc20 = DeployedErc20{
|
suite.DeployedErc20 = DeployedErc20{
|
||||||
Address: common.HexToAddress(suiteConfig.ZgChainErc20Address),
|
Address: common.HexToAddress(suiteConfig.ZgChainErc20Address),
|
||||||
// Denom & CdpCollateralType are fetched in InitKavaEvmData()
|
// Denom & CdpCollateralType are fetched in InitZgChainEvmData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the correct NodeRunner for the given config
|
// setup the correct NodeRunner for the given config
|
||||||
@ -104,11 +104,11 @@ func (suite *E2eTestSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chains := suite.runner.StartChains()
|
chains := suite.runner.StartChains()
|
||||||
kavachain := chains.MustGetChain("kava")
|
zgchain := chains.MustGetChain("0gchain")
|
||||||
suite.Kava, err = NewChain(suite.T(), kavachain, suiteConfig.FundedAccountMnemonic)
|
suite.ZgChain, err = NewChain(suite.T(), zgchain, suiteConfig.FundedAccountMnemonic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.runner.Shutdown()
|
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 {
|
if suiteConfig.IncludeIbcTests {
|
||||||
@ -120,14 +120,14 @@ func (suite *E2eTestSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.InitKavaEvmData()
|
suite.InitZgChainEvmData()
|
||||||
|
|
||||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||||
suite.cost = costSummary{
|
suite.cost = costSummary{
|
||||||
sdkAddress: whale.SdkAddress.String(),
|
sdkAddress: whale.SdkAddress.String(),
|
||||||
evmAddress: whale.EvmAddress.Hex(),
|
evmAddress: whale.EvmAddress.Hex(),
|
||||||
sdkBalanceBefore: suite.Kava.QuerySdkForBalances(whale.SdkAddress),
|
sdkBalanceBefore: suite.ZgChain.QuerySdkForBalances(whale.SdkAddress),
|
||||||
erc20BalanceBefore: suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress),
|
erc20BalanceBefore: suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,27 +136,27 @@ func (suite *E2eTestSuite) SetupSuite() {
|
|||||||
func (suite *E2eTestSuite) TearDownSuite() {
|
func (suite *E2eTestSuite) TearDownSuite() {
|
||||||
fmt.Println("tearing down test suite.")
|
fmt.Println("tearing down test suite.")
|
||||||
|
|
||||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||||
|
|
||||||
if suite.enableRefunds {
|
if suite.enableRefunds {
|
||||||
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
|
suite.cost.sdkBalanceAfter = suite.ZgChain.QuerySdkForBalances(whale.SdkAddress)
|
||||||
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
suite.cost.erc20BalanceAfter = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||||
fmt.Println("==BEFORE REFUNDS==")
|
fmt.Println("==BEFORE REFUNDS==")
|
||||||
fmt.Println(suite.cost)
|
fmt.Println(suite.cost)
|
||||||
|
|
||||||
fmt.Println("attempting to return all unused funds")
|
fmt.Println("attempting to return all unused funds")
|
||||||
suite.Kava.ReturnAllFunds()
|
suite.ZgChain.ReturnAllFunds()
|
||||||
|
|
||||||
fmt.Println("==AFTER REFUNDS==")
|
fmt.Println("==AFTER REFUNDS==")
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate & output cost summary for funded account
|
// calculate & output cost summary for funded account
|
||||||
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
|
suite.cost.sdkBalanceAfter = suite.ZgChain.QuerySdkForBalances(whale.SdkAddress)
|
||||||
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
suite.cost.erc20BalanceAfter = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||||
fmt.Println(suite.cost)
|
fmt.Println(suite.cost)
|
||||||
|
|
||||||
// close all account request channels
|
// close all account request channels
|
||||||
suite.Kava.Shutdown()
|
suite.ZgChain.Shutdown()
|
||||||
if suite.Ibc != nil {
|
if suite.Ibc != nil {
|
||||||
suite.Ibc.Shutdown()
|
suite.Ibc.Shutdown()
|
||||||
}
|
}
|
||||||
@ -167,19 +167,19 @@ func (suite *E2eTestSuite) TearDownSuite() {
|
|||||||
// SetupKvtoolNodeRunner is a helper method for building a KvtoolRunnerConfig from the suite config.
|
// SetupKvtoolNodeRunner is a helper method for building a KvtoolRunnerConfig from the suite config.
|
||||||
func (suite *E2eTestSuite) SetupKvtoolNodeRunner() *runner.KvtoolRunner {
|
func (suite *E2eTestSuite) SetupKvtoolNodeRunner() *runner.KvtoolRunner {
|
||||||
// upgrade tests are only supported on kvtool networks
|
// upgrade tests are only supported on kvtool networks
|
||||||
suite.UpgradeHeight = suite.config.Kvtool.KavaUpgradeHeight
|
suite.UpgradeHeight = suite.config.Kvtool.ZgChainUpgradeHeight
|
||||||
suite.enableRefunds = false
|
suite.enableRefunds = false
|
||||||
|
|
||||||
runnerConfig := runner.KvtoolRunnerConfig{
|
runnerConfig := runner.KvtoolRunnerConfig{
|
||||||
KavaConfigTemplate: suite.config.Kvtool.KavaConfigTemplate,
|
ZgChainConfigTemplate: suite.config.Kvtool.ZgChainConfigTemplate,
|
||||||
|
|
||||||
IncludeIBC: suite.config.IncludeIbcTests,
|
IncludeIBC: suite.config.IncludeIbcTests,
|
||||||
ImageTag: "local",
|
ImageTag: "local",
|
||||||
|
|
||||||
EnableAutomatedUpgrade: suite.config.Kvtool.IncludeAutomatedUpgrade,
|
EnableAutomatedUpgrade: suite.config.Kvtool.IncludeAutomatedUpgrade,
|
||||||
KavaUpgradeName: suite.config.Kvtool.KavaUpgradeName,
|
ZgChainUpgradeName: suite.config.Kvtool.ZgChainUpgradeName,
|
||||||
KavaUpgradeHeight: suite.config.Kvtool.KavaUpgradeHeight,
|
ZgChainUpgradeHeight: suite.config.Kvtool.ZgChainUpgradeHeight,
|
||||||
KavaUpgradeBaseImageTag: suite.config.Kvtool.KavaUpgradeBaseImageTag,
|
ZgChainUpgradeBaseImageTag: suite.config.Kvtool.ZgChainUpgradeBaseImageTag,
|
||||||
|
|
||||||
SkipShutdown: suite.config.SkipShutdown,
|
SkipShutdown: suite.config.SkipShutdown,
|
||||||
}
|
}
|
||||||
@ -199,9 +199,9 @@ func (suite *E2eTestSuite) SetupLiveNetworkNodeRunner() *runner.LiveNodeRunner {
|
|||||||
suite.enableRefunds = true
|
suite.enableRefunds = true
|
||||||
|
|
||||||
runnerConfig := runner.LiveNodeRunnerConfig{
|
runnerConfig := runner.LiveNodeRunnerConfig{
|
||||||
KavaRpcUrl: suite.config.LiveNetwork.KavaRpcUrl,
|
ZgChainRpcUrl: suite.config.LiveNetwork.ZgChainRpcUrl,
|
||||||
KavaGrpcUrl: suite.config.LiveNetwork.KavaGrpcUrl,
|
ZgChainGrpcUrl: suite.config.LiveNetwork.ZgChainGrpcUrl,
|
||||||
KavaEvmRpcUrl: suite.config.LiveNetwork.KavaEvmRpcUrl,
|
ZgChainEvmRpcUrl: suite.config.LiveNetwork.ZgChainEvmRpcUrl,
|
||||||
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,13 +8,13 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddressConversion(t *testing.T) {
|
func TestAddressConversion(t *testing.T) {
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
bech32Addr := sdk.MustAccAddressFromBech32("kava17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5")
|
bech32Addr := sdk.MustAccAddressFromBech32("0g17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5")
|
||||||
hexAddr := common.HexToAddress("0xf354ee99e2bc863cE19d80b843353476394EbC35")
|
hexAddr := common.HexToAddress("0xf354ee99e2bc863cE19d80b843353476394EbC35")
|
||||||
require.Equal(t, bech32Addr, util.EvmToSdkAddress(hexAddr))
|
require.Equal(t, bech32Addr, util.EvmToSdkAddress(hexAddr))
|
||||||
require.Equal(t, hexAddr, util.SdkToEvmAddress(bech32Addr))
|
require.Equal(t, hexAddr, util.SdkToEvmAddress(bech32Addr))
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"path/filepath"
|
"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
|
// Assumes network is running with kvtool installed from the sub-repository in tests/e2e/kvtool
|
||||||
func KavaHomePath() string {
|
func ZgChainHomePath() string {
|
||||||
return filepath.Join("kvtool", "full_configs", "generated", "kava", "initstate", ".kava")
|
return filepath.Join("kvtool", "full_configs", "generated", "0gchaind", "initstate", ".0gchain")
|
||||||
}
|
}
|
||||||
|
@ -27,18 +27,18 @@ var (
|
|||||||
ErrUnsuccessfulTx = errors.New("tx committed but returned nonzero code")
|
ErrUnsuccessfulTx = errors.New("tx committed but returned nonzero code")
|
||||||
)
|
)
|
||||||
|
|
||||||
type KavaMsgRequest struct {
|
type ZgChainMsgRequest struct {
|
||||||
Msgs []sdk.Msg
|
Msgs []sdk.Msg
|
||||||
GasLimit uint64
|
GasLimit uint64
|
||||||
FeeAmount sdk.Coins
|
FeeAmount sdk.Coins
|
||||||
Memo string
|
Memo string
|
||||||
// Arbitrary data to be referenced in the corresponding KavaMsgResponse, unused
|
// Arbitrary data to be referenced in the corresponding ZgChainMsgResponse, unused
|
||||||
// in signing. This is mostly useful to match KavaMsgResponses with KavaMsgRequests.
|
// in signing. This is mostly useful to match ZgChainMsgResponses with ZgChainMsgRequests.
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type KavaMsgResponse struct {
|
type ZgChainMsgResponse struct {
|
||||||
Request KavaMsgRequest
|
Request ZgChainMsgRequest
|
||||||
Tx authsigning.Tx
|
Tx authsigning.Tx
|
||||||
TxBytes []byte
|
TxBytes []byte
|
||||||
Result sdk.TxResponse
|
Result sdk.TxResponse
|
||||||
@ -55,8 +55,8 @@ const (
|
|||||||
txResetSequence
|
txResetSequence
|
||||||
)
|
)
|
||||||
|
|
||||||
// KavaSigner broadcasts msgs to a single kava node
|
// ZgChainSigner broadcasts msgs to a single 0g-chain node
|
||||||
type KavaSigner struct {
|
type ZgChainSigner struct {
|
||||||
chainID string
|
chainID string
|
||||||
encodingConfig params.EncodingConfig
|
encodingConfig params.EncodingConfig
|
||||||
authClient authtypes.QueryClient
|
authClient authtypes.QueryClient
|
||||||
@ -65,15 +65,15 @@ type KavaSigner struct {
|
|||||||
inflightTxLimit uint64
|
inflightTxLimit uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKavaSigner(
|
func NewZgChainSigner(
|
||||||
chainID string,
|
chainID string,
|
||||||
encodingConfig params.EncodingConfig,
|
encodingConfig params.EncodingConfig,
|
||||||
authClient authtypes.QueryClient,
|
authClient authtypes.QueryClient,
|
||||||
txClient txtypes.ServiceClient,
|
txClient txtypes.ServiceClient,
|
||||||
privKey cryptotypes.PrivKey,
|
privKey cryptotypes.PrivKey,
|
||||||
inflightTxLimit uint64) *KavaSigner {
|
inflightTxLimit uint64) *ZgChainSigner {
|
||||||
|
|
||||||
return &KavaSigner{
|
return &ZgChainSigner{
|
||||||
chainID: chainID,
|
chainID: chainID,
|
||||||
encodingConfig: encodingConfig,
|
encodingConfig: encodingConfig,
|
||||||
authClient: authClient,
|
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)
|
accountState := make(chan authtypes.AccountI)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -109,7 +109,7 @@ func (s *KavaSigner) pollAccountState() <-chan authtypes.AccountI {
|
|||||||
return accountState
|
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
|
// poll account state in it's own goroutine
|
||||||
// and send status updates to the signing 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
|
// websocket events with a fallback to polling
|
||||||
accountState := s.pollAccountState()
|
accountState := s.pollAccountState()
|
||||||
|
|
||||||
responses := make(chan KavaMsgResponse)
|
responses := make(chan ZgChainMsgResponse)
|
||||||
go func() {
|
go func() {
|
||||||
// wait until account is loaded to start signing
|
// wait until account is loaded to start signing
|
||||||
account := <-accountState
|
account := <-accountState
|
||||||
// store current request waiting to be broadcasted
|
// store current request waiting to be broadcasted
|
||||||
var currentRequest *KavaMsgRequest
|
var currentRequest *ZgChainMsgRequest
|
||||||
// keep track of all successfully broadcasted txs
|
// keep track of all successfully broadcasted txs
|
||||||
// index is sequence % inflightTxLimit
|
// index is sequence % inflightTxLimit
|
||||||
inflight := make([]*KavaMsgResponse, s.inflightTxLimit)
|
inflight := make([]*ZgChainMsgResponse, s.inflightTxLimit)
|
||||||
// used for confirming sent txs only
|
// used for confirming sent txs only
|
||||||
prevDeliverTxSeq := account.GetSequence()
|
prevDeliverTxSeq := account.GetSequence()
|
||||||
// tx sequence of already signed messages
|
// 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)
|
tx, txBytes, err := Sign(s.encodingConfig.TxConfig, s.privKey, txBuilder, signerData)
|
||||||
|
|
||||||
response = &KavaMsgResponse{
|
response = &ZgChainMsgResponse{
|
||||||
Request: *currentRequest,
|
Request: *currentRequest,
|
||||||
Tx: tx,
|
Tx: tx,
|
||||||
TxBytes: txBytes,
|
TxBytes: txBytes,
|
||||||
@ -376,7 +376,7 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Address returns the address of the Signer
|
// Address returns the address of the Signer
|
||||||
func (s *KavaSigner) Address() sdk.AccAddress {
|
func (s *ZgChainSigner) Address() sdk.AccAddress {
|
||||||
return GetAccAddress(s.privKey)
|
return GetAccAddress(s.privKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func GetCmdCreateAtomicSwap() *cobra.Command {
|
|||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "create [to] [recipient-other-chain] [sender-other-chain] [timestamp] [coins] [height-span]",
|
Use: "create [to] [recipient-other-chain] [sender-other-chain] [timestamp] [coins] [height-span]",
|
||||||
Short: "create a new atomic swap",
|
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),
|
version.AppName, types.ModuleName),
|
||||||
Args: cobra.ExactArgs(6),
|
Args: cobra.ExactArgs(6),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
@ -58,7 +58,7 @@ func GetCmdCreateAtomicSwap() *cobra.Command {
|
|||||||
return err
|
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])
|
to, err := sdk.AccAddressFromBech32(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -16,8 +16,8 @@ import (
|
|||||||
const (
|
const (
|
||||||
TestSenderOtherChain = "bnb1uky3me9ggqypmrsvxk7ur6hqkzq7zmv4ed4ng7"
|
TestSenderOtherChain = "bnb1uky3me9ggqypmrsvxk7ur6hqkzq7zmv4ed4ng7"
|
||||||
TestRecipientOtherChain = "bnb1urfermcg92dwq36572cx4xg84wpk3lfpksr5g7"
|
TestRecipientOtherChain = "bnb1urfermcg92dwq36572cx4xg84wpk3lfpksr5g7"
|
||||||
TestDeputy = "kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj"
|
TestDeputy = "0g1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj"
|
||||||
TestUser = "kava1vry5lhegzlulehuutcr7nmdlmktw88awp0a39p"
|
TestUser = "0g1vry5lhegzlulehuutcr7nmdlmktw88awp0a39p"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -18,13 +18,13 @@ import (
|
|||||||
const (
|
const (
|
||||||
TestSenderOtherChain = "bnb1uky3me9ggqypmrsvxk7ur6hqkzq7zmv4ed4ng7"
|
TestSenderOtherChain = "bnb1uky3me9ggqypmrsvxk7ur6hqkzq7zmv4ed4ng7"
|
||||||
TestRecipientOtherChain = "bnb1urfermcg92dwq36572cx4xg84wpk3lfpksr5g7"
|
TestRecipientOtherChain = "bnb1urfermcg92dwq36572cx4xg84wpk3lfpksr5g7"
|
||||||
TestDeputy = "kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj"
|
TestDeputy = "0g1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
DenomMap = map[int]string{0: "btc", 1: "eth", 2: "bnb", 3: "xrp", 4: "dai"}
|
DenomMap = map[int]string{0: "btc", 1: "eth", 2: "bnb", 3: "xrp", 4: "dai"}
|
||||||
TestUser1 = sdk.AccAddress(crypto.AddressHash([]byte("KavaTestUser1")))
|
TestUser1 = sdk.AccAddress(crypto.AddressHash([]byte("0gTestUser1")))
|
||||||
TestUser2 = sdk.AccAddress(crypto.AddressHash([]byte("KavaTestUser2")))
|
TestUser2 = sdk.AccAddress(crypto.AddressHash([]byte("0gTestUser2")))
|
||||||
)
|
)
|
||||||
|
|
||||||
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
|
func c(denom string, amount int64) sdk.Coin { return sdk.NewInt64Coin(denom, amount) }
|
||||||
|
@ -35,7 +35,7 @@ func (suite *MsgServerTestSuite) SetupTest() {
|
|||||||
|
|
||||||
// Set up genesis state and initialize
|
// Set up genesis state and initialize
|
||||||
_, addrs := app.GeneratePrivKeyAddressPairs(3)
|
_, 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)
|
authGS := app.NewFundedGenStateWithSameCoins(tApp.AppCodec(), coins, addrs)
|
||||||
tApp.InitializeFromGenesisStates(authGS, NewBep3GenStateMulti(cdc, addrs[0]))
|
tApp.InitializeFromGenesisStates(authGS, NewBep3GenStateMulti(cdc, addrs[0]))
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func resetSwapForZeroHeight(swap types.AtomicSwap) types.AtomicSwap {
|
|||||||
case types.SWAP_DIRECTION_OUTGOING:
|
case types.SWAP_DIRECTION_OUTGOING:
|
||||||
// Open outgoing swaps should be extended to allow enough time to claim after the chain launches.
|
// 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.
|
// 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:
|
case types.SWAP_DIRECTION_UNSPECIFIED:
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unknown bep3 swap direction '%s'", dir))
|
panic(fmt.Sprintf("unknown bep3 swap direction '%s'", dir))
|
||||||
|
@ -31,8 +31,8 @@ func atomicSwap(index int) types.AtomicSwap {
|
|||||||
randomNumber, _ := types.GenerateSecureRandomNumber()
|
randomNumber, _ := types.GenerateSecureRandomNumber()
|
||||||
randomNumberHash := types.CalculateRandomHash(randomNumber[:], timestamp)
|
randomNumberHash := types.CalculateRandomHash(randomNumber[:], timestamp)
|
||||||
|
|
||||||
swap := types.NewAtomicSwap(cs(c("bnb", 50000)), randomNumberHash, expireOffset, timestamp, kavaAddrs[0],
|
swap := types.NewAtomicSwap(cs(c("bnb", 50000)), randomNumberHash, expireOffset, timestamp, zgAddrs[0],
|
||||||
kavaAddrs[1], binanceAddrs[0].String(), binanceAddrs[1].String(), 1, types.SWAP_STATUS_OPEN, true, types.SWAP_DIRECTION_INCOMING)
|
zgAddrs[1], binanceAddrs[0].String(), binanceAddrs[1].String(), 1, types.SWAP_STATUS_OPEN, true, types.SWAP_DIRECTION_INCOMING)
|
||||||
|
|
||||||
return swap
|
return swap
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ type GenesisTestSuite struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *GenesisTestSuite) SetupTest() {
|
func (suite *GenesisTestSuite) SetupTest() {
|
||||||
coin := sdk.NewCoin("kava", sdk.OneInt())
|
coin := sdk.NewCoin("a0gi", sdk.OneInt())
|
||||||
suite.swaps = atomicSwaps(10)
|
suite.swaps = atomicSwaps(10)
|
||||||
|
|
||||||
supply := types.NewAssetSupply(coin, coin, coin, coin, time.Duration(0))
|
supply := types.NewAssetSupply(coin, coin, coin, coin, time.Duration(0))
|
||||||
|
@ -33,7 +33,7 @@ var (
|
|||||||
_ sdk.Msg = &MsgCreateAtomicSwap{}
|
_ sdk.Msg = &MsgCreateAtomicSwap{}
|
||||||
_ sdk.Msg = &MsgClaimAtomicSwap{}
|
_ sdk.Msg = &MsgClaimAtomicSwap{}
|
||||||
_ sdk.Msg = &MsgRefundAtomicSwap{}
|
_ sdk.Msg = &MsgRefundAtomicSwap{}
|
||||||
AtomicSwapCoinsAccAddr = sdk.AccAddress(crypto.AddressHash([]byte("KavaAtomicSwapCoins")))
|
AtomicSwapCoinsAccAddr = sdk.AccAddress(crypto.AddressHash([]byte("0gChainAtomicSwapCoins")))
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMsgCreateAtomicSwap initializes a new MsgCreateAtomicSwap
|
// NewMsgCreateAtomicSwap initializes a new MsgCreateAtomicSwap
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
coinsSingle = sdk.NewCoins(sdk.NewInt64Coin("bnb", 50000))
|
coinsSingle = sdk.NewCoins(sdk.NewInt64Coin("bnb", 50000))
|
||||||
binanceAddrs = []sdk.AccAddress{}
|
binanceAddrs = []sdk.AccAddress{}
|
||||||
kavaAddrs = []sdk.AccAddress{}
|
zgAddrs = []sdk.AccAddress{}
|
||||||
randomNumberBytes = []byte{15}
|
randomNumberBytes = []byte{15}
|
||||||
timestampInt64 = int64(100)
|
timestampInt64 = int64(100)
|
||||||
randomNumberHash = tmbytes.HexBytes(types.CalculateRandomHash(randomNumberBytes, timestampInt64))
|
randomNumberHash = tmbytes.HexBytes(types.CalculateRandomHash(randomNumberBytes, timestampInt64))
|
||||||
@ -24,14 +24,14 @@ var (
|
|||||||
func init() {
|
func init() {
|
||||||
app.SetSDKConfig()
|
app.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{
|
binanceAddrs = []sdk.AccAddress{
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("BinanceTest1"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("BinanceTest1"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("BinanceTest2"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("BinanceTest2"))),
|
||||||
}
|
}
|
||||||
kavaAddrs = []sdk.AccAddress{
|
zgAddrs = []sdk.AccAddress{
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gTest1"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gTest2"))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,12 +57,12 @@ func (suite *MsgTestSuite) TestMsgCreateAtomicSwap() {
|
|||||||
heightSpan uint64
|
heightSpan uint64
|
||||||
expectPass bool
|
expectPass bool
|
||||||
}{
|
}{
|
||||||
{"normal cross-chain", binanceAddrs[0], kavaAddrs[0], kavaAddrs[0].String(), binanceAddrs[0].String(), randomNumberHash.String(), timestampInt64, coinsSingle, 500, true},
|
{"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], kavaAddrs[0], "", "", randomNumberHash.String(), timestampInt64, coinsSingle, 500, false},
|
{"without other chain fields", binanceAddrs[0], zgAddrs[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 amount", binanceAddrs[0], zgAddrs[0], zgAddrs[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 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{}, kavaAddrs[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], kavaAddrs[0], kavaAddrs[0].String(), binanceAddrs[0].String(), "ff", 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 {
|
for i, tc := range tests {
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
bech32MainPrefix = "kava"
|
bech32MainPrefix = "0g"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parameter keys
|
// Parameter keys
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestAssetSupplyValidate(t *testing.T) {
|
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)}
|
invalidCoin := sdk.Coin{Denom: "Invalid Denom", Amount: sdkmath.NewInt(-1)}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
msg string
|
msg string
|
||||||
|
@ -35,15 +35,15 @@ const PARAMS_CHANGE_PROPOSAL_EXAMPLE = `
|
|||||||
|
|
||||||
const COMMITTEE_CHANGE_PROPOSAL_EXAMPLE = `
|
const COMMITTEE_CHANGE_PROPOSAL_EXAMPLE = `
|
||||||
{
|
{
|
||||||
"@type": "/kava.committee.v1beta1.CommitteeChangeProposal",
|
"@type": "/0g-chain.committee.v1beta1.CommitteeChangeProposal",
|
||||||
"title": "A Title",
|
"title": "A Title",
|
||||||
"description": "A proposal description.",
|
"description": "A proposal description.",
|
||||||
"new_committee": {
|
"new_committee": {
|
||||||
"@type": "/kava.committee.v1beta1.MemberCommittee",
|
"@type": "/0g-chain.committee.v1beta1.MemberCommittee",
|
||||||
"base_committee": {
|
"base_committee": {
|
||||||
"id": "34",
|
"id": "34",
|
||||||
"description": "member committee",
|
"description": "member committee",
|
||||||
"members": ["kava1ze7y9qwdddejmy7jlw4cymqqlt2wh05yhwmrv2"],
|
"members": ["0g1ze7y9qwdddejmy7jlw4cymqqlt2wh05yhwmrv2"],
|
||||||
"permissions": [],
|
"permissions": [],
|
||||||
"vote_threshold": "1.000000000000000000",
|
"vote_threshold": "1.000000000000000000",
|
||||||
"proposal_duration": "86400s",
|
"proposal_duration": "86400s",
|
||||||
@ -55,7 +55,7 @@ const COMMITTEE_CHANGE_PROPOSAL_EXAMPLE = `
|
|||||||
|
|
||||||
const COMMITTEE_DELETE_PROPOSAL_EXAMPLE = `
|
const COMMITTEE_DELETE_PROPOSAL_EXAMPLE = `
|
||||||
{
|
{
|
||||||
"@type": "/kava.committee.v1beta1.CommitteeDeleteProposal",
|
"@type": "/0g-chain.committee.v1beta1.CommitteeDeleteProposal",
|
||||||
"title": "A Title",
|
"title": "A Title",
|
||||||
"description": "A proposal description.",
|
"description": "A proposal description.",
|
||||||
"committee_id": "1"
|
"committee_id": "1"
|
||||||
|
@ -29,239 +29,239 @@ func (suite *PermissionTestSuite) SetupTest() {
|
|||||||
suite.cdc = app.AppCodec()
|
suite.cdc = app.AppCodec()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PermissionTestSuite) TestSubParamChangePermission_Allows() {
|
// func (suite *PermissionTestSuite) TestSubParamChangePermission_Allows() {
|
||||||
// cdp CollateralParams
|
// // cdp CollateralParams
|
||||||
testCPs := cdptypes.CollateralParams{
|
// testCPs := cdptypes.CollateralParams{
|
||||||
{
|
// {
|
||||||
Denom: "bnb",
|
// Denom: "bnb",
|
||||||
Type: "bnb-a",
|
// Type: "bnb-a",
|
||||||
LiquidationRatio: d("2.0"),
|
// LiquidationRatio: d("2.0"),
|
||||||
DebtLimit: c("usdx", 1000000000000),
|
// DebtLimit: c("usdx", 1000000000000),
|
||||||
StabilityFee: d("1.000000001547125958"),
|
// StabilityFee: d("1.000000001547125958"),
|
||||||
LiquidationPenalty: d("0.05"),
|
// LiquidationPenalty: d("0.05"),
|
||||||
AuctionSize: i(100),
|
// AuctionSize: i(100),
|
||||||
Prefix: 0x20,
|
// Prefix: 0x20,
|
||||||
ConversionFactor: i(6),
|
// ConversionFactor: i(6),
|
||||||
SpotMarketID: "bnb:usd",
|
// SpotMarketID: "bnb:usd",
|
||||||
LiquidationMarketID: "bnb:usd",
|
// LiquidationMarketID: "bnb:usd",
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
Denom: "btc",
|
// Denom: "btc",
|
||||||
Type: "btc-a",
|
// Type: "btc-a",
|
||||||
LiquidationRatio: d("1.5"),
|
// LiquidationRatio: d("1.5"),
|
||||||
DebtLimit: c("usdx", 1000000000),
|
// DebtLimit: c("usdx", 1000000000),
|
||||||
StabilityFee: d("1.000000001547125958"),
|
// StabilityFee: d("1.000000001547125958"),
|
||||||
LiquidationPenalty: d("0.10"),
|
// LiquidationPenalty: d("0.10"),
|
||||||
AuctionSize: i(1000),
|
// AuctionSize: i(1000),
|
||||||
Prefix: 0x30,
|
// Prefix: 0x30,
|
||||||
ConversionFactor: i(8),
|
// ConversionFactor: i(8),
|
||||||
SpotMarketID: "btc:usd",
|
// SpotMarketID: "btc:usd",
|
||||||
LiquidationMarketID: "btc:usd",
|
// LiquidationMarketID: "btc:usd",
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
testCPUpdatedDebtLimit := make(cdptypes.CollateralParams, len(testCPs))
|
// testCPUpdatedDebtLimit := make(cdptypes.CollateralParams, len(testCPs))
|
||||||
copy(testCPUpdatedDebtLimit, testCPs)
|
// copy(testCPUpdatedDebtLimit, testCPs)
|
||||||
testCPUpdatedDebtLimit[0].DebtLimit = c("usdx", 5000000)
|
// testCPUpdatedDebtLimit[0].DebtLimit = c("usdx", 5000000)
|
||||||
|
|
||||||
// cdp DebtParam
|
// // cdp DebtParam
|
||||||
testDP := cdptypes.DebtParam{
|
// testDP := cdptypes.DebtParam{
|
||||||
Denom: "usdx",
|
// Denom: "usdx",
|
||||||
ReferenceAsset: "usd",
|
// ReferenceAsset: "usd",
|
||||||
ConversionFactor: i(6),
|
// ConversionFactor: i(6),
|
||||||
DebtFloor: i(10000000),
|
// DebtFloor: i(10000000),
|
||||||
}
|
// }
|
||||||
testDPUpdatedDebtFloor := testDP
|
// testDPUpdatedDebtFloor := testDP
|
||||||
testDPUpdatedDebtFloor.DebtFloor = i(1000)
|
// testDPUpdatedDebtFloor.DebtFloor = i(1000)
|
||||||
|
|
||||||
// cdp Genesis
|
// // cdp Genesis
|
||||||
testCDPParams := cdptypes.DefaultParams()
|
// testCDPParams := cdptypes.DefaultParams()
|
||||||
testCDPParams.CollateralParams = testCPs
|
// testCDPParams.CollateralParams = testCPs
|
||||||
testCDPParams.DebtParam = testDP
|
// testCDPParams.DebtParam = testDP
|
||||||
testCDPParams.GlobalDebtLimit = testCPs[0].DebtLimit.Add(testCPs[0].DebtLimit) // correct global debt limit to pass genesis validation
|
// testCDPParams.GlobalDebtLimit = testCPs[0].DebtLimit.Add(testCPs[0].DebtLimit) // correct global debt limit to pass genesis validation
|
||||||
|
|
||||||
testDeputy, err := sdk.AccAddressFromBech32("kava1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj")
|
// testDeputy, err := sdk.AccAddressFromBech32("0g1xy7hrjy9r0algz9w3gzm8u6mrpq97kwta747gj")
|
||||||
suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
// bep3 Asset Params
|
// // bep3 Asset Params
|
||||||
testAPs := bep3types.AssetParams{
|
// testAPs := bep3types.AssetParams{
|
||||||
bep3types.AssetParam{
|
// bep3types.AssetParam{
|
||||||
Denom: "bnb",
|
// Denom: "bnb",
|
||||||
CoinID: 714,
|
// CoinID: 714,
|
||||||
SupplyLimit: bep3types.SupplyLimit{
|
// SupplyLimit: bep3types.SupplyLimit{
|
||||||
Limit: sdkmath.NewInt(350000000000000),
|
// Limit: sdkmath.NewInt(350000000000000),
|
||||||
TimeLimited: false,
|
// TimeLimited: false,
|
||||||
TimeBasedLimit: sdk.ZeroInt(),
|
// TimeBasedLimit: sdk.ZeroInt(),
|
||||||
TimePeriod: time.Hour,
|
// TimePeriod: time.Hour,
|
||||||
},
|
// },
|
||||||
Active: true,
|
// Active: true,
|
||||||
DeputyAddress: testDeputy,
|
// DeputyAddress: testDeputy,
|
||||||
FixedFee: sdkmath.NewInt(1000),
|
// FixedFee: sdkmath.NewInt(1000),
|
||||||
MinSwapAmount: sdk.OneInt(),
|
// MinSwapAmount: sdk.OneInt(),
|
||||||
MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
// MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
||||||
MinBlockLock: bep3types.DefaultMinBlockLock,
|
// MinBlockLock: bep3types.DefaultMinBlockLock,
|
||||||
MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
// MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
||||||
},
|
// },
|
||||||
bep3types.AssetParam{
|
// bep3types.AssetParam{
|
||||||
Denom: "inc",
|
// Denom: "inc",
|
||||||
CoinID: 9999,
|
// CoinID: 9999,
|
||||||
SupplyLimit: bep3types.SupplyLimit{
|
// SupplyLimit: bep3types.SupplyLimit{
|
||||||
Limit: sdkmath.NewInt(100000000000000),
|
// Limit: sdkmath.NewInt(100000000000000),
|
||||||
TimeLimited: true,
|
// TimeLimited: true,
|
||||||
TimeBasedLimit: sdkmath.NewInt(50000000000),
|
// TimeBasedLimit: sdkmath.NewInt(50000000000),
|
||||||
TimePeriod: time.Hour,
|
// TimePeriod: time.Hour,
|
||||||
},
|
// },
|
||||||
Active: false,
|
// Active: false,
|
||||||
DeputyAddress: testDeputy,
|
// DeputyAddress: testDeputy,
|
||||||
FixedFee: sdkmath.NewInt(1000),
|
// FixedFee: sdkmath.NewInt(1000),
|
||||||
MinSwapAmount: sdk.OneInt(),
|
// MinSwapAmount: sdk.OneInt(),
|
||||||
MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
// MaxSwapAmount: sdkmath.NewInt(1000000000000),
|
||||||
MinBlockLock: bep3types.DefaultMinBlockLock,
|
// MinBlockLock: bep3types.DefaultMinBlockLock,
|
||||||
MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
// MaxBlockLock: bep3types.DefaultMaxBlockLock,
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
testAPsUpdatedActive := make(bep3types.AssetParams, len(testAPs))
|
// testAPsUpdatedActive := make(bep3types.AssetParams, len(testAPs))
|
||||||
copy(testAPsUpdatedActive, testAPs)
|
// copy(testAPsUpdatedActive, testAPs)
|
||||||
testAPsUpdatedActive[1].Active = true
|
// testAPsUpdatedActive[1].Active = true
|
||||||
|
|
||||||
// bep3 Genesis
|
// // bep3 Genesis
|
||||||
testBep3Params := bep3types.DefaultParams()
|
// testBep3Params := bep3types.DefaultParams()
|
||||||
testBep3Params.AssetParams = testAPs
|
// testBep3Params.AssetParams = testAPs
|
||||||
|
|
||||||
// pricefeed Markets
|
// // pricefeed Markets
|
||||||
testMs := pricefeedtypes.Markets{
|
// testMs := pricefeedtypes.Markets{
|
||||||
{
|
// {
|
||||||
MarketID: "bnb:usd",
|
// MarketID: "bnb:usd",
|
||||||
BaseAsset: "bnb",
|
// BaseAsset: "bnb",
|
||||||
QuoteAsset: "usd",
|
// QuoteAsset: "usd",
|
||||||
Oracles: []sdk.AccAddress{},
|
// Oracles: []sdk.AccAddress{},
|
||||||
Active: true,
|
// Active: true,
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
MarketID: "btc:usd",
|
// MarketID: "btc:usd",
|
||||||
BaseAsset: "btc",
|
// BaseAsset: "btc",
|
||||||
QuoteAsset: "usd",
|
// QuoteAsset: "usd",
|
||||||
Oracles: []sdk.AccAddress{},
|
// Oracles: []sdk.AccAddress{},
|
||||||
Active: true,
|
// Active: true,
|
||||||
},
|
// },
|
||||||
}
|
// }
|
||||||
testMsUpdatedActive := make(pricefeedtypes.Markets, len(testMs))
|
// testMsUpdatedActive := make(pricefeedtypes.Markets, len(testMs))
|
||||||
copy(testMsUpdatedActive, testMs)
|
// copy(testMsUpdatedActive, testMs)
|
||||||
testMsUpdatedActive[1].Active = true
|
// testMsUpdatedActive[1].Active = true
|
||||||
|
|
||||||
testcases := []struct {
|
// testcases := []struct {
|
||||||
name string
|
// name string
|
||||||
genState []app.GenesisState
|
// genState []app.GenesisState
|
||||||
permission types.SubParamChangePermission
|
// permission types.SubParamChangePermission
|
||||||
pubProposal types.PubProposal
|
// pubProposal types.PubProposal
|
||||||
expectAllowed bool
|
// expectAllowed bool
|
||||||
}{
|
// }{
|
||||||
{
|
// {
|
||||||
name: "normal",
|
// name: "normal",
|
||||||
genState: []app.GenesisState{
|
// genState: []app.GenesisState{
|
||||||
newPricefeedGenState([]string{"bnb", "btc"}, []sdk.Dec{d("15.01"), d("9500")}),
|
// newPricefeedGenState([]string{"bnb", "btc"}, []sdk.Dec{d("15.01"), d("9500")}),
|
||||||
newCDPGenesisState(testCDPParams),
|
// newCDPGenesisState(testCDPParams),
|
||||||
newBep3GenesisState(testBep3Params),
|
// newBep3GenesisState(testBep3Params),
|
||||||
},
|
// },
|
||||||
permission: types.SubParamChangePermission{
|
// permission: types.SubParamChangePermission{
|
||||||
AllowedParams: types.AllowedParams{
|
// AllowedParams: types.AllowedParams{
|
||||||
{Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtThreshold)},
|
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtThreshold)},
|
||||||
{Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyCollateralParams)},
|
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyCollateralParams)},
|
||||||
{Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtParam)},
|
// {Subspace: cdptypes.ModuleName, Key: string(cdptypes.KeyDebtParam)},
|
||||||
{Subspace: bep3types.ModuleName, Key: string(bep3types.KeyAssetParams)},
|
// {Subspace: bep3types.ModuleName, Key: string(bep3types.KeyAssetParams)},
|
||||||
{Subspace: pricefeedtypes.ModuleName, Key: string(pricefeedtypes.KeyMarkets)},
|
// {Subspace: pricefeedtypes.ModuleName, Key: string(pricefeedtypes.KeyMarkets)},
|
||||||
},
|
// },
|
||||||
AllowedCollateralParams: types.AllowedCollateralParams{
|
// AllowedCollateralParams: types.AllowedCollateralParams{
|
||||||
{
|
// {
|
||||||
Type: "bnb-a",
|
// Type: "bnb-a",
|
||||||
DebtLimit: true,
|
// DebtLimit: true,
|
||||||
StabilityFee: true,
|
// StabilityFee: true,
|
||||||
},
|
// },
|
||||||
{ // TODO currently even if a perm doesn't allow a change in one element it must still be present in list
|
// { // TODO currently even if a perm doesn't allow a change in one element it must still be present in list
|
||||||
Type: "btc-a",
|
// Type: "btc-a",
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
AllowedDebtParam: types.AllowedDebtParam{
|
// AllowedDebtParam: types.AllowedDebtParam{
|
||||||
DebtFloor: true,
|
// DebtFloor: true,
|
||||||
},
|
// },
|
||||||
AllowedAssetParams: types.AllowedAssetParams{
|
// AllowedAssetParams: types.AllowedAssetParams{
|
||||||
{
|
// {
|
||||||
Denom: "bnb",
|
// Denom: "bnb",
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
Denom: "inc",
|
// Denom: "inc",
|
||||||
Active: true,
|
// Active: true,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
AllowedMarkets: types.AllowedMarkets{
|
// AllowedMarkets: types.AllowedMarkets{
|
||||||
{
|
// {
|
||||||
MarketID: "bnb:usd",
|
// MarketID: "bnb:usd",
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
MarketID: "btc:usd",
|
// MarketID: "btc:usd",
|
||||||
Active: true,
|
// Active: true,
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
pubProposal: paramstypes.NewParameterChangeProposal(
|
// pubProposal: paramstypes.NewParameterChangeProposal(
|
||||||
"A Title",
|
// "A Title",
|
||||||
"A description for this proposal.",
|
// "A description for this proposal.",
|
||||||
[]paramstypes.ParamChange{
|
// []paramstypes.ParamChange{
|
||||||
{
|
// {
|
||||||
Subspace: cdptypes.ModuleName,
|
// Subspace: cdptypes.ModuleName,
|
||||||
Key: string(cdptypes.KeyDebtThreshold),
|
// Key: string(cdptypes.KeyDebtThreshold),
|
||||||
Value: string(suite.cdc.MustMarshalJSON(i(1234))),
|
// Value: string(suite.cdc.MustMarshalJSON(i(1234))),
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
Subspace: cdptypes.ModuleName,
|
// Subspace: cdptypes.ModuleName,
|
||||||
Key: string(cdptypes.KeyCollateralParams),
|
// Key: string(cdptypes.KeyCollateralParams),
|
||||||
Value: string(suite.cdc.MustMarshalJSON(testCPUpdatedDebtLimit)),
|
// Value: string(suite.cdc.MustMarshalJSON(testCPUpdatedDebtLimit)),
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
Subspace: cdptypes.ModuleName,
|
// Subspace: cdptypes.ModuleName,
|
||||||
Key: string(cdptypes.KeyDebtParam),
|
// Key: string(cdptypes.KeyDebtParam),
|
||||||
Value: string(suite.cdc.MustMarshalJSON(testDPUpdatedDebtFloor)),
|
// Value: string(suite.cdc.MustMarshalJSON(testDPUpdatedDebtFloor)),
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
Subspace: bep3types.ModuleName,
|
// Subspace: bep3types.ModuleName,
|
||||||
Key: string(bep3types.KeyAssetParams),
|
// Key: string(bep3types.KeyAssetParams),
|
||||||
Value: string(suite.cdc.MustMarshalJSON(testAPsUpdatedActive)),
|
// Value: string(suite.cdc.MustMarshalJSON(testAPsUpdatedActive)),
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
Subspace: pricefeedtypes.ModuleName,
|
// Subspace: pricefeedtypes.ModuleName,
|
||||||
Key: string(pricefeedtypes.KeyMarkets),
|
// Key: string(pricefeedtypes.KeyMarkets),
|
||||||
Value: string(suite.cdc.MustMarshalJSON(testMsUpdatedActive)),
|
// Value: string(suite.cdc.MustMarshalJSON(testMsUpdatedActive)),
|
||||||
},
|
// },
|
||||||
},
|
// },
|
||||||
),
|
// ),
|
||||||
expectAllowed: true,
|
// expectAllowed: true,
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
name: "not allowed (wrong pubproposal type)",
|
// name: "not allowed (wrong pubproposal type)",
|
||||||
permission: types.SubParamChangePermission{},
|
// permission: types.SubParamChangePermission{},
|
||||||
pubProposal: govtypes.NewTextProposal("A Title", "A description for this proposal."),
|
// pubProposal: govtypes.NewTextProposal("A Title", "A description for this proposal."),
|
||||||
expectAllowed: false,
|
// expectAllowed: false,
|
||||||
},
|
// },
|
||||||
{
|
// {
|
||||||
name: "not allowed (nil pubproposal)",
|
// name: "not allowed (nil pubproposal)",
|
||||||
permission: types.SubParamChangePermission{},
|
// permission: types.SubParamChangePermission{},
|
||||||
pubProposal: nil,
|
// pubProposal: nil,
|
||||||
expectAllowed: false,
|
// expectAllowed: false,
|
||||||
},
|
// },
|
||||||
// TODO more cases
|
// // TODO more cases
|
||||||
}
|
// }
|
||||||
|
|
||||||
for _, tc := range testcases {
|
// for _, tc := range testcases {
|
||||||
suite.Run(tc.name, func() {
|
// suite.Run(tc.name, func() {
|
||||||
tApp := app.NewTestApp()
|
// tApp := app.NewTestApp()
|
||||||
ctx := tApp.NewContext(true, abci.Header{})
|
// ctx := tApp.NewContext(true, abci.Header{})
|
||||||
tApp.InitializeFromGenesisStates(tc.genState...)
|
// tApp.InitializeFromGenesisStates(tc.genState...)
|
||||||
|
|
||||||
suite.Equal(
|
// suite.Equal(
|
||||||
tc.expectAllowed,
|
// tc.expectAllowed,
|
||||||
tc.permission.Allows(ctx, tApp.Codec(), tApp.GetParamsKeeper(), tc.pubProposal),
|
// tc.permission.Allows(ctx, tApp.Codec(), tApp.GetParamsKeeper(), tc.pubProposal),
|
||||||
)
|
// )
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func TestPermissionTestSuite(t *testing.T) {
|
func TestPermissionTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(PermissionTestSuite))
|
suite.Run(t, new(PermissionTestSuite))
|
||||||
|
@ -61,7 +61,7 @@ func (suite *MsgServerTestSuite) SetupTest() {
|
|||||||
[]types.Proposal{},
|
[]types.Proposal{},
|
||||||
[]types.Vote{},
|
[]types.Vote{},
|
||||||
)
|
)
|
||||||
suite.communityPoolAmt = sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1000)))
|
suite.communityPoolAmt = sdk.NewCoins(sdk.NewCoin("neuron", sdkmath.NewInt(1000000000000000)))
|
||||||
suite.app.InitializeFromGenesisStates(
|
suite.app.InitializeFromGenesisStates(
|
||||||
app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(testGenesis)},
|
app.GenesisState{types.ModuleName: cdc.MustMarshalJSON(testGenesis)},
|
||||||
// TODO: not used?
|
// TODO: not used?
|
||||||
|
@ -53,28 +53,28 @@ func init() {
|
|||||||
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
|
||||||
// Proposals
|
// Proposals
|
||||||
cdc.RegisterInterface((*PubProposal)(nil), nil)
|
cdc.RegisterInterface((*PubProposal)(nil), nil)
|
||||||
cdc.RegisterConcrete(CommitteeChangeProposal{}, "kava/CommitteeChangeProposal", nil)
|
cdc.RegisterConcrete(CommitteeChangeProposal{}, "0gchain/CommitteeChangeProposal", nil)
|
||||||
cdc.RegisterConcrete(CommitteeDeleteProposal{}, "kava/CommitteeDeleteProposal", nil)
|
cdc.RegisterConcrete(CommitteeDeleteProposal{}, "0gchain/CommitteeDeleteProposal", nil)
|
||||||
|
|
||||||
// Committees
|
// Committees
|
||||||
cdc.RegisterInterface((*Committee)(nil), nil)
|
cdc.RegisterInterface((*Committee)(nil), nil)
|
||||||
cdc.RegisterConcrete(BaseCommittee{}, "kava/BaseCommittee", nil)
|
cdc.RegisterConcrete(BaseCommittee{}, "0gchain/BaseCommittee", nil)
|
||||||
cdc.RegisterConcrete(MemberCommittee{}, "kava/MemberCommittee", nil)
|
cdc.RegisterConcrete(MemberCommittee{}, "0gchain/MemberCommittee", nil)
|
||||||
cdc.RegisterConcrete(TokenCommittee{}, "kava/TokenCommittee", nil)
|
cdc.RegisterConcrete(TokenCommittee{}, "0gchain/TokenCommittee", nil)
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
cdc.RegisterInterface((*Permission)(nil), nil)
|
cdc.RegisterInterface((*Permission)(nil), nil)
|
||||||
cdc.RegisterConcrete(GodPermission{}, "kava/GodPermission", nil)
|
cdc.RegisterConcrete(GodPermission{}, "0gchain/GodPermission", nil)
|
||||||
cdc.RegisterConcrete(TextPermission{}, "kava/TextPermission", nil)
|
cdc.RegisterConcrete(TextPermission{}, "0gchain/TextPermission", nil)
|
||||||
cdc.RegisterConcrete(SoftwareUpgradePermission{}, "kava/SoftwareUpgradePermission", nil)
|
cdc.RegisterConcrete(SoftwareUpgradePermission{}, "0gchain/SoftwareUpgradePermission", nil)
|
||||||
cdc.RegisterConcrete(ParamsChangePermission{}, "kava/ParamsChangePermission", nil)
|
cdc.RegisterConcrete(ParamsChangePermission{}, "0gchain/ParamsChangePermission", nil)
|
||||||
cdc.RegisterConcrete(CommunityCDPRepayDebtPermission{}, "kava/CommunityCDPRepayDebtPermission", nil)
|
cdc.RegisterConcrete(CommunityCDPRepayDebtPermission{}, "0gchain/CommunityCDPRepayDebtPermission", nil)
|
||||||
cdc.RegisterConcrete(CommunityCDPWithdrawCollateralPermission{}, "kava/CommunityCDPWithdrawCollateralPermission", nil)
|
cdc.RegisterConcrete(CommunityCDPWithdrawCollateralPermission{}, "0gchain/CommunityCDPWithdrawCollateralPermission", nil)
|
||||||
cdc.RegisterConcrete(CommunityPoolLendWithdrawPermission{}, "kava/CommunityPoolLendWithdrawPermission", nil)
|
cdc.RegisterConcrete(CommunityPoolLendWithdrawPermission{}, "0gchain/CommunityPoolLendWithdrawPermission", nil)
|
||||||
|
|
||||||
// Msgs
|
// Msgs
|
||||||
legacy.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "kava/MsgSubmitProposal")
|
legacy.RegisterAminoMsg(cdc, &MsgSubmitProposal{}, "0gchain/MsgSubmitProposal")
|
||||||
legacy.RegisterAminoMsg(cdc, &MsgVote{}, "kava/MsgVote")
|
legacy.RegisterAminoMsg(cdc, &MsgVote{}, "0gchain/MsgVote")
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterProposalTypeCodec allows external modules to register their own pubproposal types on the
|
// RegisterProposalTypeCodec allows external modules to register their own pubproposal types on the
|
||||||
@ -92,7 +92,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
|||||||
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
|
||||||
|
|
||||||
registry.RegisterInterface(
|
registry.RegisterInterface(
|
||||||
"kava.committee.v1beta1.Committee",
|
"0gchain.committee.v1beta1.Committee",
|
||||||
(*Committee)(nil),
|
(*Committee)(nil),
|
||||||
&BaseCommittee{},
|
&BaseCommittee{},
|
||||||
&TokenCommittee{},
|
&TokenCommittee{},
|
||||||
@ -100,7 +100,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
registry.RegisterInterface(
|
registry.RegisterInterface(
|
||||||
"kava.committee.v1beta1.Permission",
|
"0gchain.committee.v1beta1.Permission",
|
||||||
(*Permission)(nil),
|
(*Permission)(nil),
|
||||||
&GodPermission{},
|
&GodPermission{},
|
||||||
&TextPermission{},
|
&TextPermission{},
|
||||||
@ -114,7 +114,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.
|
// 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.
|
// Note that all proposals supported by x/committee needed to be registered here, including the proposals from x/gov.
|
||||||
registry.RegisterInterface(
|
registry.RegisterInterface(
|
||||||
"kava.committee.v1beta1.PubProposal",
|
"0gchain.committee.v1beta1.PubProposal",
|
||||||
(*PubProposal)(nil),
|
(*PubProposal)(nil),
|
||||||
&Proposal{},
|
&Proposal{},
|
||||||
&distrtypes.CommunityPoolSpendProposal{},
|
&distrtypes.CommunityPoolSpendProposal{},
|
||||||
|
@ -15,10 +15,10 @@ import (
|
|||||||
const MaxCommitteeDescriptionLength int = 512
|
const MaxCommitteeDescriptionLength int = 512
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BaseCommitteeType = "kava/BaseCommittee"
|
BaseCommitteeType = "0g-chain/BaseCommittee"
|
||||||
MemberCommitteeType = "kava/MemberCommittee" // Committee is composed of member addresses that vote to enact proposals within their permissions
|
MemberCommitteeType = "0g-chain/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
|
TokenCommitteeType = "0g-chain/TokenCommittee" // Committee is composed of token holders with voting power determined by total token balance
|
||||||
BondDenom = "ukava"
|
BondDenom = "neuron"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Marshal needed for protobuf compatibility.
|
// Marshal needed for protobuf compatibility.
|
||||||
|
@ -17,9 +17,9 @@ import (
|
|||||||
|
|
||||||
func TestBaseCommittee(t *testing.T) {
|
func TestBaseCommittee(t *testing.T) {
|
||||||
addresses := []sdk.AccAddress{
|
addresses := []sdk.AccAddress{
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest2"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest3"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest3"))),
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -205,9 +205,9 @@ func TestBaseCommittee(t *testing.T) {
|
|||||||
|
|
||||||
func TestMemberCommittee(t *testing.T) {
|
func TestMemberCommittee(t *testing.T) {
|
||||||
addresses := []sdk.AccAddress{
|
addresses := []sdk.AccAddress{
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest2"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest3"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest3"))),
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -251,9 +251,9 @@ func TestMemberCommittee(t *testing.T) {
|
|||||||
// TestTokenCommittee tests unique TokenCommittee functionality
|
// TestTokenCommittee tests unique TokenCommittee functionality
|
||||||
func TestTokenCommittee(t *testing.T) {
|
func TestTokenCommittee(t *testing.T) {
|
||||||
addresses := []sdk.AccAddress{
|
addresses := []sdk.AccAddress{
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest2"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest3"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest3"))),
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
|
@ -17,11 +17,11 @@ import (
|
|||||||
func TestGenesisState_Validate(t *testing.T) {
|
func TestGenesisState_Validate(t *testing.T) {
|
||||||
testTime := time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)
|
testTime := time.Date(1998, time.January, 1, 0, 0, 0, 0, time.UTC)
|
||||||
addresses := []sdk.AccAddress{
|
addresses := []sdk.AccAddress{
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest2"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest2"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest3"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest3"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest4"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest4"))),
|
||||||
sdk.AccAddress(crypto.AddressHash([]byte("KavaTest5"))),
|
sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest5"))),
|
||||||
}
|
}
|
||||||
|
|
||||||
testGenesis := types.NewGenesisState(
|
testGenesis := types.NewGenesisState(
|
||||||
|
@ -20,7 +20,7 @@ func MustNewMsgSubmitProposal(pubProposal PubProposal, proposer sdk.AccAddress,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMsgSubmitProposal_ValidateBasic(t *testing.T) {
|
func TestMsgSubmitProposal_ValidateBasic(t *testing.T) {
|
||||||
addr := sdk.AccAddress(crypto.AddressHash([]byte("KavaTest1")))
|
addr := sdk.AccAddress(crypto.AddressHash([]byte("0gChainTest1")))
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
msg *MsgSubmitProposal
|
msg *MsgSubmitProposal
|
||||||
@ -57,7 +57,7 @@ func TestMsgSubmitProposal_ValidateBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMsgVote_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 {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
msg MsgVote
|
msg MsgVote
|
||||||
|
@ -46,12 +46,12 @@ func ParseOrQueryConversionPairAddress(
|
|||||||
|
|
||||||
if err := sdk.ValidateDenom(addrOrDenom); err != nil {
|
if err := sdk.ValidateDenom(addrOrDenom); err != nil {
|
||||||
return common.Address{}, fmt.Errorf(
|
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,
|
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(
|
paramsRes, err := queryClient.Params(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&types.QueryParamsRequest{},
|
&types.QueryParamsRequest{},
|
||||||
@ -67,7 +67,7 @@ func ParseOrQueryConversionPairAddress(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return common.Address{}, fmt.Errorf(
|
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,
|
addrOrDenom,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func GetTxCmd() *cobra.Command {
|
|||||||
|
|
||||||
func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
||||||
return &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",
|
Short: "EVM-native asset: converts a coin on Cosmos co-chain to an ERC20 on EVM co-chain",
|
||||||
Example: fmt.Sprintf(
|
Example: fmt.Sprintf(
|
||||||
`%s tx %s convert-evm-erc20-from-coin 0x7Bbf300890857b8c241b219C6a489431669b3aFA 500000000erc20/usdc --from <key> --gas 2000000`,
|
`%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 {
|
func getCmdConvertEvmERC20ToCoin() *cobra.Command {
|
||||||
return &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",
|
Short: "EVM-native asset: converts an ERC20 on EVM co-chain to a coin on Cosmos co-chain",
|
||||||
Example: fmt.Sprintf(`
|
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,
|
`, version.AppName, types.ModuleName,
|
||||||
),
|
),
|
||||||
Args: cobra.ExactArgs(3),
|
Args: cobra.ExactArgs(3),
|
||||||
@ -163,11 +163,11 @@ func getCmdMsgConvertCosmosCoinToERC20() *cobra.Command {
|
|||||||
|
|
||||||
func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
||||||
return &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",
|
Short: "Cosmos-native asset: converts an ERC20 on EVM co-chain back to a coin on Cosmos co-chain",
|
||||||
Example: fmt.Sprintf(
|
Example: fmt.Sprintf(
|
||||||
`Convert ERC20 representation of 500 ATOM back to a Cosmos coin, sending to kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a:
|
`Convert ERC20 representation of 500 ATOM back to a Cosmos coin, sending to 0g1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a:
|
||||||
%s tx %s convert-cosmos-coin-from-erc20 kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a 500000000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 --from <key> --gas 2000000`,
|
%s tx %s convert-cosmos-coin-from-erc20 0g1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a 500000000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 --from <key> --gas 2000000`,
|
||||||
version.AppName, types.ModuleName,
|
version.AppName, types.ModuleName,
|
||||||
),
|
),
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
@ -179,7 +179,7 @@ func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
|||||||
|
|
||||||
receiver, err := sdk.AccAddressFromBech32(args[0])
|
receiver, err := sdk.AccAddressFromBech32(args[0])
|
||||||
if err != nil {
|
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])
|
amount, err := sdk.ParseCoinNormalized(args[1])
|
||||||
|
@ -98,7 +98,7 @@ func (s *genesisTestSuite) TestExportGenesis() {
|
|||||||
params.AllowedCosmosDenoms = []types.AllowedCosmosCoinERC20Token{
|
params.AllowedCosmosDenoms = []types.AllowedCosmosCoinERC20Token{
|
||||||
{
|
{
|
||||||
CosmosDenom: "hard",
|
CosmosDenom: "hard",
|
||||||
Name: "Kava EVM HARD",
|
Name: "0G EVM HARD",
|
||||||
Symbol: "HARD",
|
Symbol: "HARD",
|
||||||
Decimals: 6,
|
Decimals: 6,
|
||||||
},
|
},
|
||||||
|
@ -9,56 +9,49 @@ import (
|
|||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// ConversionMultiplier is the conversion multiplier between neuron and a0gi
|
||||||
// EvmDenom is the gas denom used by the evm
|
var ConversionMultiplier = sdkmath.NewInt(chaincfg.ConversionMultiplier)
|
||||||
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)
|
|
||||||
|
|
||||||
var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
||||||
|
|
||||||
// EvmBankKeeper is a BankKeeper wrapper for the x/evm module to allow the use
|
// EvmBankKeeper is a BankKeeper wrapper for the x/evm module to allow the use
|
||||||
// of the 18 decimal akava coin on the evm.
|
// of the 18 decimal neuron coin on the evm.
|
||||||
// x/evm consumes gas and send coins by minting and burning akava coins in its module
|
// 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.
|
// 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.
|
// extra percision needed by the evm.
|
||||||
type EvmBankKeeper struct {
|
type EvmBankKeeper struct {
|
||||||
akavaKeeper Keeper
|
baseKeeper Keeper
|
||||||
bk types.BankKeeper
|
bk types.BankKeeper
|
||||||
ak types.AccountKeeper
|
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{
|
return EvmBankKeeper{
|
||||||
akavaKeeper: akavaKeeper,
|
baseKeeper: baseKeeper,
|
||||||
bk: bk,
|
bk: bk,
|
||||||
ak: ak,
|
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 {
|
func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
||||||
if denom != EvmDenom {
|
if denom != chaincfg.BaseDenom {
|
||||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", EvmDenom))
|
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.BaseDenom))
|
||||||
}
|
}
|
||||||
|
|
||||||
spendableCoins := k.bk.SpendableCoins(ctx, addr)
|
spendableCoins := k.bk.SpendableCoins(ctx, addr)
|
||||||
ukava := spendableCoins.AmountOf(CosmosDenom)
|
a0gi := spendableCoins.AmountOf(chaincfg.DisplayDenom)
|
||||||
akava := k.akavaKeeper.GetBalance(ctx, addr)
|
neuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||||
total := ukava.Mul(ConversionMultiplier).Add(akava)
|
total := a0gi.Mul(ConversionMultiplier).Add(neuron)
|
||||||
return sdk.NewCoin(EvmDenom, total)
|
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 {
|
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
|
// 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
|
// evmtypes.BankKeeper interface. This must be updated if the evm module
|
||||||
@ -66,158 +59,148 @@ func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, rec
|
|||||||
panic("not implemented")
|
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
|
// 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.
|
// 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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ukava.Amount.IsPositive() {
|
if a0gi.Amount.IsPositive() {
|
||||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
senderAddr := k.GetModuleAddress(senderModule)
|
senderAddr := k.GetModuleAddress(senderModule)
|
||||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, senderAddr, akava); err != nil {
|
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil {
|
||||||
return err
|
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 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.
|
// 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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, senderAddr, akavaNeeded); err != nil {
|
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
recipientAddr := k.GetModuleAddress(recipientModule)
|
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 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.
|
// 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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recipientAddr := k.GetModuleAddress(moduleName)
|
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 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.
|
// 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 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleAddr := k.GetModuleAddress(moduleName)
|
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 err
|
||||||
}
|
}
|
||||||
|
|
||||||
return k.akavaKeeper.RemoveBalance(ctx, moduleAddr, akava)
|
return k.baseKeeper.RemoveBalance(ctx, moduleAddr, neuron)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSendEnabledCoins checks the coins provided and returns an ErrSendDisabled
|
// ConvertOneA0giToNeuronIfNeeded converts 1 a0gi to neuron for an address if
|
||||||
// if any of the coins are not configured for sending. Returns nil if sending is
|
// its neuron balance is smaller than the neuronNeeded amount.
|
||||||
// enabled for all provided coins.
|
func (k EvmBankKeeper) ConvertOneA0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error {
|
||||||
func (k EvmBankKeeper) IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error {
|
neuronBal := k.baseKeeper.GetBalance(ctx, addr)
|
||||||
// IsSendEnabledCoins method is not used by the evm module, but is required by the
|
if neuronBal.GTE(neuronNeeded) {
|
||||||
// evmtypes.BankKeeper interface. This must be updated if the evm module
|
|
||||||
// is updated to use IsSendEnabledCoins.
|
|
||||||
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) {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ukavaToStore := sdk.NewCoins(sdk.NewCoin(CosmosDenom, sdk.OneInt()))
|
a0giToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdk.OneInt()))
|
||||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, ukavaToStore); err != nil {
|
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, a0giToStore); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// add 1ukava equivalent of akava to addr
|
// add 1a0gi equivalent of neuron to addr
|
||||||
akavaToReceive := ConversionMultiplier
|
neuronToReceive := ConversionMultiplier
|
||||||
if err := k.akavaKeeper.AddBalance(ctx, addr, akavaToReceive); err != nil {
|
if err := k.baseKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertAkavaToUkava converts all available akava to ukava for a given AccAddress.
|
// ConvertNeuronToA0gi converts all available neuron to a0gi for a given AccAddress.
|
||||||
func (k EvmBankKeeper) ConvertAkavaToUkava(ctx sdk.Context, addr sdk.AccAddress) error {
|
func (k EvmBankKeeper) ConvertNeuronToA0gi(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||||
totalAkava := k.akavaKeeper.GetBalance(ctx, addr)
|
totalNeuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||||
ukava, _, err := SplitAkavaCoins(sdk.NewCoins(sdk.NewCoin(EvmDenom, totalAkava)))
|
a0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, totalNeuron)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// do nothing if account does not have enough akava for a single ukava
|
// do nothing if account does not have enough neuron for a single a0gi
|
||||||
ukavaToReceive := ukava.Amount
|
a0giToReceive := a0gi.Amount
|
||||||
if !ukavaToReceive.IsPositive() {
|
if !a0giToReceive.IsPositive() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove akava used for converting to ukava
|
// remove neuron used for converting to a0gi
|
||||||
akavaToBurn := ukavaToReceive.Mul(ConversionMultiplier)
|
neuronToBurn := a0giToReceive.Mul(ConversionMultiplier)
|
||||||
finalBal := totalAkava.Sub(akavaToBurn)
|
finalBal := totalNeuron.Sub(neuronToBurn)
|
||||||
if err := k.akavaKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
if err := k.baseKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fromAddr := k.GetModuleAddress(types.ModuleName)
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,35 +215,35 @@ func (k EvmBankKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
|
|||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
// SplitAkavaCoins splits akava coins to the equivalent ukava coins and any remaining akava balance.
|
// 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 akava denom.
|
// An error will be returned if the coins are not valid or if the coins are not the neuron denom.
|
||||||
func SplitAkavaCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||||
akava := sdk.ZeroInt()
|
neuron := sdk.ZeroInt()
|
||||||
ukava := sdk.NewCoin(CosmosDenom, sdk.ZeroInt())
|
a0gi := sdk.NewCoin(chaincfg.DisplayDenom, sdk.ZeroInt())
|
||||||
|
|
||||||
if len(coins) == 0 {
|
if len(coins) == 0 {
|
||||||
return ukava, akava, nil
|
return a0gi, neuron, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ValidateEvmCoins(coins); err != 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.
|
// note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate.
|
||||||
coin := coins[0]
|
coin := coins[0]
|
||||||
remainingBalance := coin.Amount.Mod(ConversionMultiplier)
|
remainingBalance := coin.Amount.Mod(ConversionMultiplier)
|
||||||
if remainingBalance.IsPositive() {
|
if remainingBalance.IsPositive() {
|
||||||
akava = remainingBalance
|
neuron = remainingBalance
|
||||||
}
|
}
|
||||||
ukavaAmount := coin.Amount.Quo(ConversionMultiplier)
|
a0giAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||||
if ukavaAmount.IsPositive() {
|
if a0giAmount.IsPositive() {
|
||||||
ukava = sdk.NewCoin(CosmosDenom, ukavaAmount)
|
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 {
|
func ValidateEvmCoins(coins sdk.Coins) error {
|
||||||
if len(coins) == 0 {
|
if len(coins) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@ -271,9 +254,9 @@ func ValidateEvmCoins(coins sdk.Coins) error {
|
|||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
|
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate that coin denom is akava
|
// validate that coin denom is neuron
|
||||||
if len(coins) != 1 || coins[0].Denom != EvmDenom {
|
if len(coins) != 1 || coins[0].Denom != chaincfg.BaseDenom {
|
||||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", EvmDenom)
|
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.BaseDenom)
|
||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/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/keeper"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
@ -27,8 +28,8 @@ func (suite *evmBankKeeperTestSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
||||||
startingCoins := sdk.NewCoins(sdk.NewInt64Coin("ukava", 10))
|
startingCoins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10))
|
||||||
startingAkava := sdkmath.NewInt(100)
|
startingNeuron := sdkmath.NewInt(100)
|
||||||
|
|
||||||
now := tmtime.Now()
|
now := tmtime.Now()
|
||||||
endTime := now.Add(24 * time.Hour)
|
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)
|
err := suite.App.FundAccount(suite.Ctx, suite.Addrs[0], startingCoins)
|
||||||
suite.Require().NoError(err)
|
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)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "akava")
|
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||||
suite.Require().Equal(startingAkava, coin.Amount)
|
suite.Require().Equal(startingNeuron, coin.Amount)
|
||||||
|
|
||||||
ctx := suite.Ctx.WithBlockTime(now.Add(12 * time.Hour))
|
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)
|
suite.Require().Equal(sdkmath.NewIntFromUint64(5_000_000_000_100), coin.Amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_NotEvmDenom() {
|
func (suite *evmBankKeeperTestSuite) TestGetBalance_NotEvmDenom() {
|
||||||
suite.Require().Panics(func() {
|
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.Require().Panics(func() {
|
||||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "busd")
|
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "busd")
|
||||||
@ -65,39 +66,39 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
|||||||
expAmount sdkmath.Int
|
expAmount sdkmath.Int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"ukava with akava",
|
"a0gi with neuron",
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 100),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||||
sdk.NewInt64Coin("ukava", 10),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 10),
|
||||||
),
|
),
|
||||||
sdkmath.NewInt(10_000_000_000_100),
|
sdkmath.NewInt(10_000_000_000_100),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"just akava",
|
"just neuron",
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 100),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||||
sdk.NewInt64Coin("busd", 100),
|
sdk.NewInt64Coin("busd", 100),
|
||||||
),
|
),
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"just ukava",
|
"just a0gi",
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("ukava", 10),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 10),
|
||||||
sdk.NewInt64Coin("busd", 100),
|
sdk.NewInt64Coin("busd", 100),
|
||||||
),
|
),
|
||||||
sdkmath.NewInt(10_000_000_000_000),
|
sdkmath.NewInt(10_000_000_000_000),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"no ukava or akava",
|
"no a0gi or neuron",
|
||||||
sdk.NewCoins(),
|
sdk.NewCoins(),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"with avaka that is more than 1 ukava",
|
"with avaka that is more than 1 a0gi",
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 20_000_000_000_220),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 20_000_000_000_220),
|
||||||
sdk.NewInt64Coin("ukava", 11),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 11),
|
||||||
),
|
),
|
||||||
sdkmath.NewInt(31_000_000_000_220),
|
sdkmath.NewInt(31_000_000_000_220),
|
||||||
},
|
},
|
||||||
@ -107,8 +108,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
|||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
|
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingAmount)
|
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAmount)
|
||||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "akava")
|
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||||
suite.Require().Equal(tt.expAmount, coin.Amount)
|
suite.Require().Equal(tt.expAmount, coin.Amount)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -116,8 +117,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
|||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||||
startingModuleCoins := sdk.NewCoins(
|
startingModuleCoins := sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 200),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||||
sdk.NewInt64Coin("ukava", 100),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||||
)
|
)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -127,102 +128,102 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
|||||||
hasErr bool
|
hasErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"send more than 1 ukava",
|
"send more than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_010)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 10),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 10),
|
||||||
sdk.NewInt64Coin("ukava", 12),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 12),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send less than 1 ukava",
|
"send less than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 122),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 122),
|
||||||
sdk.NewInt64Coin("ukava", 0),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 0),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send an exact amount of ukava",
|
"send an exact amount of a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 0o0),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 0o0),
|
||||||
sdk.NewInt64Coin("ukava", 98),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 98),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send no akava",
|
"send no neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 0),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 0),
|
||||||
sdk.NewInt64Coin("ukava", 0),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 0),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if sending other coins",
|
"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{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough total akava to cover",
|
"errors if not enough total neuron to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_001_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough ukava to cover",
|
"errors if not enough a0gi to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts receiver's akava to ukava if there's enough akava after the transfer",
|
"converts receiver's neuron to a0gi if there's enough neuron after the transfer",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_000_000_000_200)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_000_200)),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 999_999_999_900),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 999_999_999_900),
|
||||||
sdk.NewInt64Coin("ukava", 1),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||||
),
|
),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 100),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||||
sdk.NewInt64Coin("ukava", 101),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 101),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts all of receiver's akava to ukava even if somehow receiver has more than 1ukava of akava",
|
"converts all of receiver's neuron to a0gi even if somehow receiver has more than 1a0gi of neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_100)),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 5_999_999_999_990),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 5_999_999_999_990),
|
||||||
sdk.NewInt64Coin("ukava", 1),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||||
),
|
),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 90),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 90),
|
||||||
sdk.NewInt64Coin("ukava", 19),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 19),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"swap 1 ukava for akava if module account doesn't have enough akava",
|
"swap 1 a0gi for neuron if module account doesn't have enough neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_000_000_001_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_001_000)),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 200),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||||
sdk.NewInt64Coin("ukava", 1),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||||
),
|
),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 1200),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 1200),
|
||||||
sdk.NewInt64Coin("ukava", 100),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
@ -232,11 +233,11 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
|||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
|
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingAccBal)
|
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAccBal)
|
||||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingModuleCoins)
|
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||||
|
|
||||||
// fund our module with some ukava to account for converting extra akava back to ukava
|
// fund our module with some a0gi to account for converting extra neuron back to a0gi
|
||||||
suite.FundModuleAccountWithKava(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||||
|
|
||||||
err := suite.EvmBankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, evmtypes.ModuleName, suite.Addrs[0], tt.sendCoins)
|
err := suite.EvmBankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, evmtypes.ModuleName, suite.Addrs[0], tt.sendCoins)
|
||||||
if tt.hasErr {
|
if tt.hasErr {
|
||||||
@ -246,24 +247,24 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
|||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check ukava
|
// check a0gi
|
||||||
ukavaSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expAccBal.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||||
|
|
||||||
// check akava
|
// check neuron
|
||||||
actualAkava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().Equal(tt.expAccBal.AmountOf("akava").Int64(), actualAkava.Int64())
|
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||||
startingAccCoins := sdk.NewCoins(
|
startingAccCoins := sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 200),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||||
sdk.NewInt64Coin("ukava", 100),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||||
)
|
)
|
||||||
startingModuleCoins := sdk.NewCoins(
|
startingModuleCoins := sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 100_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000),
|
||||||
)
|
)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -273,36 +274,36 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
|||||||
hasErr bool
|
hasErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"send more than 1 ukava",
|
"send more than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_010)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 190), sdk.NewInt64Coin("ukava", 88)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 190), sdk.NewInt64Coin(chaincfg.DisplayDenom, 88)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_010), sdk.NewInt64Coin("ukava", 12)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_010), sdk.NewInt64Coin(chaincfg.DisplayDenom, 12)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send less than 1 ukava",
|
"send less than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 78), sdk.NewInt64Coin("ukava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 78), sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_122), sdk.NewInt64Coin("ukava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_122), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send an exact amount of ukava",
|
"send an exact amount of a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 2)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 2)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 98)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 98)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send no akava",
|
"send no neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if sending other coins",
|
"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{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
@ -310,39 +311,39 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
|||||||
{
|
{
|
||||||
"errors if have dup coins",
|
"errors if have dup coins",
|
||||||
sdk.Coins{
|
sdk.Coins{
|
||||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||||
},
|
},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough total akava to cover",
|
"errors if not enough total neuron to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_001_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough ukava to cover",
|
"errors if not enough a0gi to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts 1 ukava to akava if not enough akava to cover",
|
"converts 1 a0gi to neuron if not enough neuron to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_001_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_001_000_000_000)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 999_000_000_200), sdk.NewInt64Coin("ukava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 999_000_000_200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 101_000_000_000), sdk.NewInt64Coin("ukava", 99)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 101_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 99)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts receiver's akava to ukava if there's enough akava after the transfer",
|
"converts receiver's neuron to a0gi if there's enough neuron after the transfer",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 5_900_000_000_200)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_900_000_000_200)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 94)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 94)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 6)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 6)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -350,8 +351,8 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], startingAccCoins)
|
suite.FundAccountWithZgChain(suite.Addrs[0], startingAccCoins)
|
||||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingModuleCoins)
|
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||||
|
|
||||||
err := suite.EvmBankKeeper.SendCoinsFromAccountToModule(suite.Ctx, suite.Addrs[0], evmtypes.ModuleName, tt.sendCoins)
|
err := suite.EvmBankKeeper.SendCoinsFromAccountToModule(suite.Ctx, suite.Addrs[0], evmtypes.ModuleName, tt.sendCoins)
|
||||||
if tt.hasErr {
|
if tt.hasErr {
|
||||||
@ -362,67 +363,67 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check sender balance
|
// check sender balance
|
||||||
ukavaSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expSenderCoins.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||||
actualAkava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().Equal(tt.expSenderCoins.AmountOf("akava").Int64(), actualAkava.Int64())
|
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||||
|
|
||||||
// check module balance
|
// check module balance
|
||||||
moduleAddr := suite.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
|
moduleAddr := suite.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
|
||||||
ukavaSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, "ukava")
|
a0giSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expModuleCoins.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||||
actualAkava = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
actualNeuron = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
||||||
suite.Require().Equal(tt.expModuleCoins.AmountOf("akava").Int64(), actualAkava.Int64())
|
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||||
startingUkava := sdkmath.NewInt(100)
|
startingA0gi := sdkmath.NewInt(100)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
burnCoins sdk.Coins
|
burnCoins sdk.Coins
|
||||||
expUkava sdkmath.Int
|
expA0gi sdkmath.Int
|
||||||
expAkava sdkmath.Int
|
expNeuron sdkmath.Int
|
||||||
hasErr bool
|
hasErr bool
|
||||||
akavaStart sdkmath.Int
|
neuronStart sdkmath.Int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"burn more than 1 ukava",
|
"burn more than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||||
sdkmath.NewInt(88),
|
sdkmath.NewInt(88),
|
||||||
sdkmath.NewInt(100_000_000_000),
|
sdkmath.NewInt(100_000_000_000),
|
||||||
false,
|
false,
|
||||||
sdkmath.NewInt(121_000_000_002),
|
sdkmath.NewInt(121_000_000_002),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"burn less than 1 ukava",
|
"burn less than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
sdkmath.NewInt(878),
|
sdkmath.NewInt(878),
|
||||||
false,
|
false,
|
||||||
sdkmath.NewInt(1000),
|
sdkmath.NewInt(1000),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"burn an exact amount of ukava",
|
"burn an exact amount of a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||||
sdkmath.NewInt(2),
|
sdkmath.NewInt(2),
|
||||||
sdkmath.NewInt(10),
|
sdkmath.NewInt(10),
|
||||||
false,
|
false,
|
||||||
sdkmath.NewInt(10),
|
sdkmath.NewInt(10),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"burn no akava",
|
"burn no neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||||
startingUkava,
|
startingA0gi,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
false,
|
false,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if burning other coins",
|
"errors if burning other coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||||
startingUkava,
|
startingA0gi,
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
true,
|
true,
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
@ -430,41 +431,41 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
|||||||
{
|
{
|
||||||
"errors if have dup coins",
|
"errors if have dup coins",
|
||||||
sdk.Coins{
|
sdk.Coins{
|
||||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||||
},
|
},
|
||||||
startingUkava,
|
startingA0gi,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
true,
|
true,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if burn amount is negative",
|
"errors if burn amount is negative",
|
||||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-100)}},
|
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||||
startingUkava,
|
startingA0gi,
|
||||||
sdkmath.NewInt(50),
|
sdkmath.NewInt(50),
|
||||||
true,
|
true,
|
||||||
sdkmath.NewInt(50),
|
sdkmath.NewInt(50),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough akava to cover burn",
|
"errors if not enough neuron to cover burn",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_999_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_999_000_000_000)),
|
||||||
sdkmath.NewInt(0),
|
sdkmath.NewInt(0),
|
||||||
sdkmath.NewInt(99_000_000_000),
|
sdkmath.NewInt(99_000_000_000),
|
||||||
true,
|
true,
|
||||||
sdkmath.NewInt(99_000_000_000),
|
sdkmath.NewInt(99_000_000_000),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough ukava to cover burn",
|
"errors if not enough a0gi to cover burn",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
true,
|
true,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts 1 ukava to akava if not enough akava to cover",
|
"converts 1 a0gi to neuron if not enough neuron to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||||
sdkmath.NewInt(87),
|
sdkmath.NewInt(87),
|
||||||
sdkmath.NewInt(980_000_000_000),
|
sdkmath.NewInt(980_000_000_000),
|
||||||
false,
|
false,
|
||||||
@ -476,10 +477,10 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
|||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
startingCoins := sdk.NewCoins(
|
startingCoins := sdk.NewCoins(
|
||||||
sdk.NewCoin("ukava", startingUkava),
|
sdk.NewCoin(chaincfg.DisplayDenom, startingA0gi),
|
||||||
sdk.NewCoin("akava", tt.akavaStart),
|
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)
|
err := suite.EvmBankKeeper.BurnCoins(suite.Ctx, evmtypes.ModuleName, tt.burnCoins)
|
||||||
if tt.hasErr {
|
if tt.hasErr {
|
||||||
@ -489,13 +490,13 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
|||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check ukava
|
// check a0gi
|
||||||
ukavaActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ukava")
|
a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expUkava, ukavaActual.Amount)
|
suite.Require().Equal(tt.expA0gi, a0giActual.Amount)
|
||||||
|
|
||||||
// check akava
|
// check neuron
|
||||||
akavaActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||||
suite.Require().Equal(tt.expAkava, akavaActual)
|
suite.Require().Equal(tt.expNeuron, neuronActual)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -504,38 +505,38 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
mintCoins sdk.Coins
|
mintCoins sdk.Coins
|
||||||
ukava sdkmath.Int
|
a0gi sdkmath.Int
|
||||||
akava sdkmath.Int
|
neuron sdkmath.Int
|
||||||
hasErr bool
|
hasErr bool
|
||||||
akavaStart sdkmath.Int
|
neuronStart sdkmath.Int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"mint more than 1 ukava",
|
"mint more than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||||
sdkmath.NewInt(12),
|
sdkmath.NewInt(12),
|
||||||
sdkmath.NewInt(21_000_000_002),
|
sdkmath.NewInt(21_000_000_002),
|
||||||
false,
|
false,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mint less than 1 ukava",
|
"mint less than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 901_000_000_001)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 901_000_000_001)),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
sdkmath.NewInt(901_000_000_001),
|
sdkmath.NewInt(901_000_000_001),
|
||||||
false,
|
false,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mint an exact amount of ukava",
|
"mint an exact amount of a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 123_000_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 123_000_000_000_000_000)),
|
||||||
sdkmath.NewInt(123_000),
|
sdkmath.NewInt(123_000),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
false,
|
false,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mint no akava",
|
"mint no neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
false,
|
false,
|
||||||
@ -543,7 +544,7 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if minting other coins",
|
"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(),
|
sdk.ZeroInt(),
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
true,
|
true,
|
||||||
@ -552,8 +553,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
{
|
{
|
||||||
"errors if have dup coins",
|
"errors if have dup coins",
|
||||||
sdk.Coins{
|
sdk.Coins{
|
||||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||||
},
|
},
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
@ -562,23 +563,23 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if mint amount is negative",
|
"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(),
|
sdk.ZeroInt(),
|
||||||
sdkmath.NewInt(50),
|
sdkmath.NewInt(50),
|
||||||
true,
|
true,
|
||||||
sdkmath.NewInt(50),
|
sdkmath.NewInt(50),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"adds to existing akava balance",
|
"adds to existing neuron balance",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||||
sdkmath.NewInt(12),
|
sdkmath.NewInt(12),
|
||||||
sdkmath.NewInt(21_000_000_102),
|
sdkmath.NewInt(21_000_000_102),
|
||||||
false,
|
false,
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"convert akava balance to ukava if it exceeds 1 ukava",
|
"convert neuron balance to a0gi if it exceeds 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_999_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_999_000_000_000)),
|
||||||
sdkmath.NewInt(12),
|
sdkmath.NewInt(12),
|
||||||
sdkmath.NewInt(1_200_000_001),
|
sdkmath.NewInt(1_200_000_001),
|
||||||
false,
|
false,
|
||||||
@ -589,8 +590,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
suite.FundModuleAccountWithKava(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin("akava", tt.akavaStart)))
|
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, tt.neuronStart)))
|
||||||
|
|
||||||
err := suite.EvmBankKeeper.MintCoins(suite.Ctx, evmtypes.ModuleName, tt.mintCoins)
|
err := suite.EvmBankKeeper.MintCoins(suite.Ctx, evmtypes.ModuleName, tt.mintCoins)
|
||||||
if tt.hasErr {
|
if tt.hasErr {
|
||||||
@ -600,13 +601,13 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check ukava
|
// check a0gi
|
||||||
ukavaActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ukava")
|
a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.ukava, ukavaActual.Amount)
|
suite.Require().Equal(tt.a0gi, a0giActual.Amount)
|
||||||
|
|
||||||
// check akava
|
// check neuron
|
||||||
akavaActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||||
suite.Require().Equal(tt.akava, akavaActual)
|
suite.Require().Equal(tt.neuron, neuronActual)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -619,22 +620,22 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"valid coins",
|
"valid coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dup coins",
|
"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,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"not evm coins",
|
"not evm coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 500)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 500)),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"negative coins",
|
"negative coins",
|
||||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-500)}},
|
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-500)}},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -650,8 +651,8 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
func (suite *evmBankKeeperTestSuite) TestConvertOneA0giToNeuronIfNeeded() {
|
||||||
akavaNeeded := sdkmath.NewInt(200)
|
neuronNeeded := sdkmath.NewInt(200)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
startingCoins sdk.Coins
|
startingCoins sdk.Coins
|
||||||
@ -659,21 +660,21 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
|||||||
success bool
|
success bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"not enough ukava for conversion",
|
"not enough a0gi for conversion",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts 1 ukava to akava",
|
"converts 1 a0gi to neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 9), sdk.NewInt64Coin("akava", 1_000_000_000_100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 9), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_100)),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"conversion not needed",
|
"conversion not needed",
|
||||||
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("ukava", 10), sdk.NewInt64Coin("akava", 200)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -681,67 +682,67 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
|||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
|
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingCoins)
|
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||||
err := suite.EvmBankKeeper.ConvertOneUkavaToAkavaIfNeeded(suite.Ctx, suite.Addrs[0], akavaNeeded)
|
err := suite.EvmBankKeeper.ConvertOneA0giToNeuronIfNeeded(suite.Ctx, suite.Addrs[0], neuronNeeded)
|
||||||
moduleKava := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), "ukava")
|
moduleZgChain := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), chaincfg.DisplayDenom)
|
||||||
if tt.success {
|
if tt.success {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
if tt.startingCoins.AmountOf("akava").LT(akavaNeeded) {
|
if tt.startingCoins.AmountOf(chaincfg.BaseDenom).LT(neuronNeeded) {
|
||||||
suite.Require().Equal(sdk.OneInt(), moduleKava.Amount)
|
suite.Require().Equal(sdk.OneInt(), moduleZgChain.Amount)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
suite.Require().Error(err)
|
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])
|
neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||||
ukava := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
a0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestConvertAkavaToUkava() {
|
func (suite *evmBankKeeperTestSuite) TestConvertNeuronToA0gi() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
startingCoins sdk.Coins
|
startingCoins sdk.Coins
|
||||||
expectedCoins sdk.Coins
|
expectedCoins sdk.Coins
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"not enough ukava",
|
"not enough a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100), sdk.NewInt64Coin("ukava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts akava for 1 ukava",
|
"converts neuron for 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 1_000_000_000_003)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_003)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 11), sdk.NewInt64Coin("akava", 3)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 11), sdk.NewInt64Coin(chaincfg.BaseDenom, 3)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts more than 1 ukava of akava",
|
"converts more than 1 a0gi of neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 8_000_000_000_123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 18), sdk.NewInt64Coin("akava", 123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 18), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
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.Require().NoError(err)
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingCoins)
|
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||||
err = suite.EvmBankKeeper.ConvertAkavaToUkava(suite.Ctx, suite.Addrs[0])
|
err = suite.EvmBankKeeper.ConvertNeuronToA0gi(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
akava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||||
ukava := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
a0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
func (suite *evmBankKeeperTestSuite) TestSplitNeuronCoins() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
coins sdk.Coins
|
coins sdk.Coins
|
||||||
@ -750,7 +751,7 @@ func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"invalid coins",
|
"invalid coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 500)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 500)),
|
||||||
nil,
|
nil,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
@ -761,33 +762,33 @@ func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
|||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ukava & akava coins",
|
"a0gi & neuron coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 8_000_000_000_123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 8), sdk.NewInt64Coin("akava", 123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 8), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"only akava",
|
"only neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"only ukava",
|
"only a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 5_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_000_000_000_000)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 5)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 5)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
ukava, akava, err := keeper.SplitAkavaCoins(tt.coins)
|
a0gi, neuron, err := keeper.SplitNeuronCoins(tt.coins)
|
||||||
if tt.shouldErr {
|
if tt.shouldErr {
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (suite *convertCosmosCoinToERC20Suite) TestConvertCosmosCoinToERC20() {
|
|||||||
caller, key := testutil.RandomEvmAccount()
|
caller, key := testutil.RandomEvmAccount()
|
||||||
query := func(method string, args ...interface{}) ([]interface{}, error) {
|
query := func(method string, args ...interface{}) ([]interface{}, error) {
|
||||||
return suite.QueryContract(
|
return suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
key,
|
key,
|
||||||
contractAddress,
|
contractAddress,
|
||||||
@ -90,7 +90,7 @@ func (suite *convertCosmosCoinToERC20Suite) TestConvertCosmosCoinToERC20() {
|
|||||||
// make the denom allowed for conversion
|
// make the denom allowed for conversion
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
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)
|
suite.Keeper.SetParams(suite.Ctx, params)
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ func (suite *convertCosmosCoinFromERC20Suite) SetupTest() {
|
|||||||
caller, key := testutil.RandomEvmAccount()
|
caller, key := testutil.RandomEvmAccount()
|
||||||
suite.query = func(method string, args ...interface{}) ([]interface{}, error) {
|
suite.query = func(method string, args ...interface{}) ([]interface{}, error) {
|
||||||
return suite.QueryContract(
|
return suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
key,
|
key,
|
||||||
suite.contractAddress,
|
suite.contractAddress,
|
||||||
|
@ -68,10 +68,10 @@ func (k Keeper) DeployTestMintableERC20Contract(
|
|||||||
return types.NewInternalEVMAddress(contractAddr), nil
|
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.
|
// contract with the token metadata.
|
||||||
// This method does NOT check if a token for the provided SdkDenom has already been deployed.
|
// 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,
|
ctx sdk.Context,
|
||||||
token types.AllowedCosmosCoinERC20Token,
|
token types.AllowedCosmosCoinERC20Token,
|
||||||
) (types.InternalEVMAddress, error) {
|
) (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)
|
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
|
"", // Empty string for contract constructor
|
||||||
token.Name,
|
token.Name,
|
||||||
token.Symbol,
|
token.Symbol,
|
||||||
@ -89,13 +89,13 @@ func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
|||||||
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to pack token with details %+v", token)
|
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(
|
copy(
|
||||||
data[:len(types.ERC20KavaWrappedCosmosCoinContract.Bin)],
|
data[:len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin)],
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.Bin,
|
types.ERC20ZgChainWrappedCosmosCoinContract.Bin,
|
||||||
)
|
)
|
||||||
copy(
|
copy(
|
||||||
data[len(types.ERC20KavaWrappedCosmosCoinContract.Bin):],
|
data[len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin):],
|
||||||
packedAbi,
|
packedAbi,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ func (k *Keeper) GetOrDeployCosmosCoinERC20Contract(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deploy a new contract
|
// deploy a new contract
|
||||||
contractAddress, err := k.DeployKavaWrappedCosmosCoinERC20Contract(ctx, tokenInfo)
|
contractAddress, err := k.DeployZgChainWrappedCosmosCoinERC20Contract(ctx, tokenInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return contractAddress, err
|
return contractAddress, err
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ func (k Keeper) BurnERC20(
|
|||||||
) error {
|
) error {
|
||||||
_, err := k.CallEVM(
|
_, err := k.CallEVM(
|
||||||
ctx,
|
ctx,
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
types.ModuleEVMAddress,
|
types.ModuleEVMAddress,
|
||||||
contractAddr,
|
contractAddr,
|
||||||
erc20BurnMethod,
|
erc20BurnMethod,
|
||||||
@ -213,7 +213,7 @@ func (k Keeper) QueryERC20TotalSupply(
|
|||||||
) (*big.Int, error) {
|
) (*big.Int, error) {
|
||||||
res, err := k.CallEVM(
|
res, err := k.CallEVM(
|
||||||
ctx,
|
ctx,
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
types.ModuleEVMAddress,
|
types.ModuleEVMAddress,
|
||||||
contractAddr,
|
contractAddr,
|
||||||
erc20TotalSupplyMethod,
|
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() {
|
suite.Run("fails to deploy invalid contract", func() {
|
||||||
// empty other fields means this token is invalid.
|
// empty other fields means this token is invalid.
|
||||||
invalidToken := types.AllowedCosmosCoinERC20Token{CosmosDenom: "nope"}
|
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")
|
suite.ErrorContains(err, "token's name cannot be empty")
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -119,13 +119,13 @@ func (suite *ERC20TestSuite) TestDeployKavaWrappedCosmosCoinERC20Contract() {
|
|||||||
caller, privKey := testutil.RandomEvmAccount()
|
caller, privKey := testutil.RandomEvmAccount()
|
||||||
|
|
||||||
token := types.NewAllowedCosmosCoinERC20Token("hard", "EVM HARD", "HARD", 6)
|
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.NoError(err)
|
||||||
suite.NotNil(addr)
|
suite.NotNil(addr)
|
||||||
|
|
||||||
callContract := func(method string, args ...interface{}) ([]interface{}, error) {
|
callContract := func(method string, args ...interface{}) ([]interface{}, error) {
|
||||||
return suite.QueryContract(
|
return suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
privKey,
|
privKey,
|
||||||
addr,
|
addr,
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"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)
|
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)
|
broken = totalMinorBalances.GT(bankBalance)
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"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/keeper"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
@ -46,10 +47,10 @@ func (suite *invariantTestSuite) SetupValidState() {
|
|||||||
keeper.ConversionMultiplier.QuoRaw(2),
|
keeper.ConversionMultiplier.QuoRaw(2),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
suite.FundModuleAccountWithKava(
|
suite.FundModuleAccountWithZgChain(
|
||||||
types.ModuleName,
|
types.ModuleName,
|
||||||
sdk.NewCoins(
|
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
|
// increase minor balance at least above conversion multiplier
|
||||||
suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], keeper.ConversionMultiplier)
|
suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], keeper.ConversionMultiplier)
|
||||||
// add same number of ukava to avoid breaking other invariants
|
// add same number of a0gi to avoid breaking other invariants
|
||||||
amt := sdk.NewCoins(sdk.NewInt64Coin(keeper.CosmosDenom, 1))
|
amt := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1))
|
||||||
suite.Require().NoError(
|
suite.Require().NoError(
|
||||||
suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, amt),
|
suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, amt),
|
||||||
)
|
)
|
||||||
@ -190,7 +191,7 @@ func (suite *invariantTestSuite) TestSendToModuleAccountNotAllowed() {
|
|||||||
ToAddress: maccAddress.String(),
|
ToAddress: maccAddress.String(),
|
||||||
Amount: coins,
|
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() {
|
func (suite *invariantTestSuite) TestCosmosCoinsFullyBackedInvariant() {
|
||||||
|
@ -115,7 +115,7 @@ func (k Keeper) SetAccount(ctx sdk.Context, account types.Account) error {
|
|||||||
return nil
|
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 {
|
func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
||||||
account := k.GetAccount(ctx, addr)
|
account := k.GetAccount(ctx, addr)
|
||||||
if account == nil {
|
if account == nil {
|
||||||
@ -124,7 +124,7 @@ func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
|||||||
return account.Balance
|
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 {
|
func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int) error {
|
||||||
account := k.GetAccount(ctx, addr)
|
account := k.GetAccount(ctx, addr)
|
||||||
if account == nil {
|
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)
|
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 {
|
func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdkmath.Int) error {
|
||||||
if amt.IsNegative() {
|
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() {
|
if amt.IsZero() {
|
||||||
@ -162,13 +162,13 @@ func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipien
|
|||||||
return k.SetBalance(ctx, recipientAddr, receiverBal)
|
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 {
|
func (k Keeper) AddBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
||||||
bal := k.GetBalance(ctx, addr)
|
bal := k.GetBalance(ctx, addr)
|
||||||
return k.SetBalance(ctx, addr, amt.Add(bal))
|
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 {
|
func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
||||||
if amt.IsNegative() {
|
if amt.IsNegative() {
|
||||||
return fmt.Errorf("cannot remove a negative amount from balance: %d", amt)
|
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)
|
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 {
|
func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string, contractAddress types.InternalEVMAddress) error {
|
||||||
if err := sdk.ValidateDenom(cosmosDenom); err != nil {
|
if err := sdk.ValidateDenom(cosmosDenom); err != nil {
|
||||||
return errorsmod.Wrap(types.ErrInvalidCosmosDenom, cosmosDenom)
|
return errorsmod.Wrap(types.ErrInvalidCosmosDenom, cosmosDenom)
|
||||||
@ -203,7 +203,7 @@ func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom stri
|
|||||||
return nil
|
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
|
// 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) {
|
func (k *Keeper) GetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string) (types.InternalEVMAddress, bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
@ -26,7 +26,7 @@ var _ types.MsgServer = msgServer{}
|
|||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
// ConvertCoinToERC20 handles a MsgConvertCoinToERC20 message to convert
|
// ConvertCoinToERC20 handles a MsgConvertCoinToERC20 message to convert
|
||||||
// sdk.Coin to Kava EVM tokens.
|
// sdk.Coin to 0gChain EVM tokens.
|
||||||
func (s msgServer) ConvertCoinToERC20(
|
func (s msgServer) ConvertCoinToERC20(
|
||||||
goCtx context.Context,
|
goCtx context.Context,
|
||||||
msg *types.MsgConvertCoinToERC20,
|
msg *types.MsgConvertCoinToERC20,
|
||||||
@ -64,7 +64,7 @@ func (s msgServer) ConvertCoinToERC20(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConvertERC20ToCoin handles a MsgConvertERC20ToCoin message to convert
|
// ConvertERC20ToCoin handles a MsgConvertERC20ToCoin message to convert
|
||||||
// sdk.Coin to Kava EVM tokens.
|
// sdk.Coin to 0gChain EVM tokens.
|
||||||
func (s msgServer) ConvertERC20ToCoin(
|
func (s msgServer) ConvertERC20ToCoin(
|
||||||
goCtx context.Context,
|
goCtx context.Context,
|
||||||
msg *types.MsgConvertERC20ToCoin,
|
msg *types.MsgConvertERC20ToCoin,
|
||||||
|
@ -34,7 +34,7 @@ func TestMsgServerSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *MsgServerSuite) TestConvertCoinToERC20() {
|
func (suite *MsgServerSuite) TestConvertCoinToERC20() {
|
||||||
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
invoker, err := sdk.AccAddressFromBech32("0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
err = suite.App.FundAccount(suite.Ctx, invoker, sdk.NewCoins(sdk.NewCoin("erc20/usdc", sdkmath.NewInt(10000))))
|
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
|
// make the denom allowed for conversion
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
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)
|
suite.Keeper.SetParams(suite.Ctx, params)
|
||||||
|
|
||||||
@ -331,7 +331,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
|||||||
{
|
{
|
||||||
name: "invalid - bad initiator",
|
name: "invalid - bad initiator",
|
||||||
msg: types.NewMsgConvertCosmosCoinToERC20(
|
msg: types.NewMsgConvertCosmosCoinToERC20(
|
||||||
"invalid-kava-address",
|
"invalid-0g-address",
|
||||||
testutil.RandomEvmAddress().Hex(),
|
testutil.RandomEvmAddress().Hex(),
|
||||||
sdk.NewInt64Coin(allowedDenom, 1e4),
|
sdk.NewInt64Coin(allowedDenom, 1e4),
|
||||||
),
|
),
|
||||||
@ -452,7 +452,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_AlreadyDeployedContrac
|
|||||||
// make the denom allowed for conversion
|
// make the denom allowed for conversion
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
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)
|
suite.Keeper.SetParams(suite.Ctx, params)
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_AlreadyDeployedContrac
|
|||||||
// check total supply
|
// check total supply
|
||||||
caller, key := testutil.RandomEvmAccount()
|
caller, key := testutil.RandomEvmAccount()
|
||||||
totalSupply, err := suite.QueryContract(
|
totalSupply, err := suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
key,
|
key,
|
||||||
contractAddress,
|
contractAddress,
|
||||||
@ -639,7 +639,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinFromERC20() {
|
|||||||
// expect erc20 total supply to reflect new value
|
// expect erc20 total supply to reflect new value
|
||||||
caller, key := testutil.RandomEvmAccount()
|
caller, key := testutil.RandomEvmAccount()
|
||||||
totalSupply, err := suite.QueryContract(
|
totalSupply, err := suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
key,
|
key,
|
||||||
contractAddress,
|
contractAddress,
|
||||||
|
@ -66,9 +66,9 @@ func (suite *keeperTestSuite) TestGetAllowedTokenMetadata() {
|
|||||||
|
|
||||||
atom := types.NewAllowedCosmosCoinERC20Token(
|
atom := types.NewAllowedCosmosCoinERC20Token(
|
||||||
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
|
"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
|
// init state with some allowed tokens
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
|
@ -37,6 +37,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"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/keeper"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
)
|
)
|
||||||
@ -81,14 +82,14 @@ func (suite *Suite) SetupTest() {
|
|||||||
suite.Addrs = addrs
|
suite.Addrs = addrs
|
||||||
|
|
||||||
evmGenesis := evmtypes.DefaultGenesisState()
|
evmGenesis := evmtypes.DefaultGenesisState()
|
||||||
evmGenesis.Params.EvmDenom = "akava"
|
evmGenesis.Params.EvmDenom = chaincfg.BaseDenom
|
||||||
|
|
||||||
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
||||||
feemarketGenesis.Params.EnableHeight = 1
|
feemarketGenesis.Params.EnableHeight = 1
|
||||||
feemarketGenesis.Params.NoBaseFee = false
|
feemarketGenesis.Params.NoBaseFee = false
|
||||||
|
|
||||||
cdc := suite.App.AppCodec()
|
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{
|
authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{
|
||||||
sdk.AccAddress(suite.Key1.PubKey().Address()),
|
sdk.AccAddress(suite.Key1.PubKey().Address()),
|
||||||
sdk.AccAddress(suite.Key2.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)
|
return suite.App.GetModuleAccountBalance(suite.Ctx, types.ModuleName, denom)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *Suite) FundAccountWithKava(addr sdk.AccAddress, coins sdk.Coins) {
|
func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) {
|
||||||
ukava := coins.AmountOf("ukava")
|
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin("ukava", ukava)))
|
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
akava := coins.AmountOf("akava")
|
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||||
if akava.IsPositive() {
|
if neuron.IsPositive() {
|
||||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, akava)
|
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *Suite) FundModuleAccountWithKava(moduleName string, coins sdk.Coins) {
|
func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) {
|
||||||
ukava := coins.AmountOf("ukava")
|
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin("ukava", ukava)))
|
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
akava := coins.AmountOf("akava")
|
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||||
if akava.IsPositive() {
|
if neuron.IsPositive() {
|
||||||
addr := suite.AccountKeeper.GetModuleAddress(moduleName)
|
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)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +218,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress {
|
|||||||
suite.App.FundModuleAccount(
|
suite.App.FundModuleAccount(
|
||||||
suite.Ctx,
|
suite.Ctx,
|
||||||
types.ModuleName,
|
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))
|
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
|
// Mint the max gas to the FeeCollector to ensure balance in case of refund
|
||||||
suite.MintFeeCollector(sdk.NewCoins(
|
suite.MintFeeCollector(sdk.NewCoins(
|
||||||
sdk.NewCoin(
|
sdk.NewCoin(
|
||||||
"ukava",
|
chaincfg.DisplayDenom,
|
||||||
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
|
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
|
// InternalEVMAddress is a type alias of common.Address to represent an address
|
||||||
// on the Kava EVM.
|
// on the 0gChain EVM.
|
||||||
type InternalEVMAddress struct {
|
type InternalEVMAddress struct {
|
||||||
common.Address
|
common.Address
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,11 @@ var (
|
|||||||
// ERC20MintableBurnableAddress is the erc20 module address
|
// ERC20MintableBurnableAddress is the erc20 module address
|
||||||
ERC20MintableBurnableAddress common.Address
|
ERC20MintableBurnableAddress common.Address
|
||||||
|
|
||||||
//go:embed ethermint_json/ERC20KavaWrappedCosmosCoin.json
|
//go:embed ethermint_json/ERC20ZgChainWrappedCosmosCoin.json
|
||||||
ERC20KavaWrappedCosmosCoinJSON []byte
|
ERC20ZgChainWrappedCosmosCoinJSON []byte
|
||||||
|
|
||||||
// ERC20KavaWrappedCosmosCoinContract is the compiled erc20 contract
|
// ERC20ZgChainWrappedCosmosCoinContract is the compiled erc20 contract
|
||||||
ERC20KavaWrappedCosmosCoinContract evmtypes.CompiledContract
|
ERC20ZgChainWrappedCosmosCoinContract evmtypes.CompiledContract
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -53,12 +53,12 @@ func init() {
|
|||||||
panic("loading ERC20MintableBurnable contract failed")
|
panic("loading ERC20MintableBurnable contract failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(ERC20KavaWrappedCosmosCoinJSON, &ERC20KavaWrappedCosmosCoinContract)
|
err = json.Unmarshal(ERC20ZgChainWrappedCosmosCoinJSON, &ERC20ZgChainWrappedCosmosCoinContract)
|
||||||
if err != nil {
|
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 {
|
if len(ERC20ZgChainWrappedCosmosCoinContract.Bin) == 0 {
|
||||||
panic("loading ERC20KavaWrappedCosmosCoin contract failed")
|
panic("loading ERC20ZgChainWrappedCosmosCoin contract failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func NewConversionPair(address InternalEVMAddress, denom string) ConversionPair
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAddress returns the InternalEVMAddress of the Kava ERC20 address.
|
// GetAddress returns the InternalEVMAddress of the 0gChain ERC20 address.
|
||||||
func (pair ConversionPair) GetAddress() InternalEVMAddress {
|
func (pair ConversionPair) GetAddress() InternalEVMAddress {
|
||||||
return NewInternalEVMAddress(common.BytesToAddress(pair.ZgChainERC20Address))
|
return NewInternalEVMAddress(common.BytesToAddress(pair.ZgChainERC20Address))
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
|||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||||
"kava",
|
"a0gi",
|
||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
@ -162,7 +162,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
|||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
||||||
"kava",
|
"a0gi",
|
||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
@ -183,16 +183,16 @@ func TestConversionPairs_Validate(t *testing.T) {
|
|||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||||
"kava",
|
"a0gi",
|
||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
"kava",
|
"a0gi",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
errArgs{
|
errArgs{
|
||||||
expectPass: false,
|
expectPass: false,
|
||||||
contains: "found duplicate enabled conversion pair denom kava",
|
contains: "found duplicate enabled conversion pair denom a0gi",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -208,7 +208,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
|||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
"kava",
|
"a0gi",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -240,12 +240,12 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "valid token",
|
name: "valid token",
|
||||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 6),
|
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 6),
|
||||||
expErr: "",
|
expErr: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid - highest allowed decimals",
|
name: "valid - highest allowed decimals",
|
||||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 255),
|
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 255),
|
||||||
expErr: "",
|
expErr: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -280,7 +280,7 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - decimals higher than uint8",
|
name: "invalid - decimals higher than uint8",
|
||||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 256),
|
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0g-wrapped ATOM", "kATOM", 256),
|
||||||
expErr: "decimals must be less than 256",
|
expErr: "decimals must be less than 256",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
// AccountStoreKeyPrefix is the prefix for keys that store accounts
|
// AccountStoreKeyPrefix is the prefix for keys that store accounts
|
||||||
AccountStoreKeyPrefix = []byte{0x00}
|
AccountStoreKeyPrefix = []byte{0x00}
|
||||||
// DeployedCosmosCoinContractKeyPrefix is the key for storing deployed KavaWrappedCosmosCoinERC20s contract addresses
|
// DeployedCosmosCoinContractKeyPrefix is the key for storing deployed ZgChainWrappedCosmosCoinERC20s contract addresses
|
||||||
DeployedCosmosCoinContractKeyPrefix = []byte{0x01}
|
DeployedCosmosCoinContractKeyPrefix = []byte{0x01}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"valid",
|
"valid",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -38,7 +38,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - odd length hex address",
|
"invalid - odd length hex address",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
||||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -48,7 +48,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - zero amount",
|
"invalid - zero amount",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(0)),
|
sdk.NewCoin("erc20/weth", sdkmath.NewInt(0)),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -58,7 +58,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - negative amount",
|
"invalid - negative amount",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
// Create manually so there is no validation
|
// Create manually so there is no validation
|
||||||
sdk.Coin{Denom: "erc20/weth", Amount: sdkmath.NewInt(-1234)},
|
sdk.Coin{Denom: "erc20/weth", Amount: sdkmath.NewInt(-1234)},
|
||||||
@ -69,7 +69,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - empty denom",
|
"invalid - empty denom",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.Coin{Denom: "", Amount: sdkmath.NewInt(-1234)},
|
sdk.Coin{Denom: "", Amount: sdkmath.NewInt(-1234)},
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -79,7 +79,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - invalid denom",
|
"invalid - invalid denom",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.Coin{Denom: "h", Amount: sdkmath.NewInt(-1234)},
|
sdk.Coin{Denom: "h", Amount: sdkmath.NewInt(-1234)},
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -126,7 +126,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"valid",
|
"valid",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
sdkmath.NewInt(1234),
|
sdkmath.NewInt(1234),
|
||||||
@ -136,7 +136,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - odd length hex address",
|
"invalid - odd length hex address",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
sdkmath.NewInt(1234),
|
sdkmath.NewInt(1234),
|
||||||
@ -147,7 +147,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - zero amount",
|
"invalid - zero amount",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
sdkmath.NewInt(0),
|
sdkmath.NewInt(0),
|
||||||
@ -158,7 +158,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - negative amount",
|
"invalid - negative amount",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
sdkmath.NewInt(-1234),
|
sdkmath.NewInt(-1234),
|
||||||
@ -169,7 +169,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - invalid contract address",
|
"invalid - invalid contract address",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369",
|
||||||
sdkmath.NewInt(1234),
|
sdkmath.NewInt(1234),
|
||||||
@ -201,7 +201,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
||||||
validKavaAddr := app.RandomAddress()
|
valid0gAddr := app.RandomAddress()
|
||||||
validHexAddr, _ := testutil.RandomEvmAccount()
|
validHexAddr, _ := testutil.RandomEvmAccount()
|
||||||
invalidAddr := "not-an-address"
|
invalidAddr := "not-an-address"
|
||||||
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
||||||
@ -215,14 +215,14 @@ func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: valid0gAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: validAmount,
|
amount: validAmount,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - sending to kava addr",
|
name: "invalid - sending to 0g addr",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: valid0gAddr.String(),
|
||||||
receiver: app.RandomAddress().String(),
|
receiver: app.RandomAddress().String(),
|
||||||
amount: validAmount,
|
amount: validAmount,
|
||||||
expectedErr: "receiver is not a valid hex address",
|
expectedErr: "receiver is not a valid hex address",
|
||||||
@ -236,35 +236,35 @@ func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid receiver",
|
name: "invalid - invalid receiver",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: valid0gAddr.String(),
|
||||||
receiver: invalidAddr,
|
receiver: invalidAddr,
|
||||||
amount: validAmount,
|
amount: validAmount,
|
||||||
expectedErr: "receiver is not a valid hex address",
|
expectedErr: "receiver is not a valid hex address",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - nil",
|
name: "invalid - invalid amount - nil",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: valid0gAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: sdk.Coin{},
|
amount: sdk.Coin{},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - zero",
|
name: "invalid - invalid amount - zero",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: valid0gAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: sdk.NewInt64Coin("magic", 0),
|
amount: sdk.NewInt64Coin("magic", 0),
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - negative",
|
name: "invalid - invalid amount - negative",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: valid0gAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - invalid denom",
|
name: "invalid - invalid amount - invalid denom",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: valid0gAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
@ -313,7 +313,7 @@ func TestConvertCosmosCoinToERC20_GetSigners(t *testing.T) {
|
|||||||
|
|
||||||
func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
||||||
validHexAddr := testutil.RandomEvmAddress()
|
validHexAddr := testutil.RandomEvmAddress()
|
||||||
validKavaAddr := app.RandomAddress()
|
valid0gAddr := app.RandomAddress()
|
||||||
invalidAddr := "not-an-address"
|
invalidAddr := "not-an-address"
|
||||||
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: valid0gAddr.String(),
|
||||||
amount: validAmount,
|
amount: validAmount,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
},
|
},
|
||||||
@ -355,28 +355,28 @@ func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid - invalid amount - nil",
|
name: "invalid - invalid amount - nil",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: valid0gAddr.String(),
|
||||||
amount: sdk.Coin{},
|
amount: sdk.Coin{},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - zero",
|
name: "invalid - invalid amount - zero",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: valid0gAddr.String(),
|
||||||
amount: sdk.NewInt64Coin("magic", 0),
|
amount: sdk.NewInt64Coin("magic", 0),
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - negative",
|
name: "invalid - invalid amount - negative",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: valid0gAddr.String(),
|
||||||
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - invalid denom",
|
name: "invalid - invalid amount - invalid denom",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: valid0gAddr.String(),
|
||||||
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
|
@ -107,11 +107,11 @@ func (suite *ParamsTestSuite) TestParams_Validate() {
|
|||||||
invalidConversionPairs := types.NewConversionPairs(
|
invalidConversionPairs := types.NewConversionPairs(
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||||
"kava",
|
"a0gi",
|
||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
"kava", // duplicate denom!
|
"a0gi", // duplicate denom!
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
validAllowedCosmosDenoms := types.NewAllowedCosmosCoinERC20Tokens(
|
validAllowedCosmosDenoms := types.NewAllowedCosmosCoinERC20Tokens(
|
||||||
|
@ -38,7 +38,7 @@ func (suite *ABCITestSuite) SetupTest() {
|
|||||||
tApp.InitializeFromGenesisStates()
|
tApp.InitializeFromGenesisStates()
|
||||||
_, addrs := app.GeneratePrivKeyAddressPairs(5)
|
_, addrs := app.GeneratePrivKeyAddressPairs(5)
|
||||||
keeper := tApp.GetIssuanceKeeper()
|
keeper := tApp.GetIssuanceKeeper()
|
||||||
modAccount, err := sdk.AccAddressFromBech32("kava1cj7njkw2g9fqx4e768zc75dp9sks8u9znxrf0w")
|
modAccount, err := sdk.AccAddressFromBech32("0g1cj7njkw2g9fqx4e768zc75dp9sks8u9znxrf0w")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.app = tApp
|
suite.app = tApp
|
||||||
suite.ctx = ctx
|
suite.ctx = ctx
|
||||||
|
@ -43,7 +43,7 @@ func GetCmdIssueTokens() *cobra.Command {
|
|||||||
Use: "issue [tokens] [receiver]",
|
Use: "issue [tokens] [receiver]",
|
||||||
Short: "issue new tokens to the receiver address",
|
Short: "issue new tokens to the receiver address",
|
||||||
Long: "The asset owner issues new tokens that will be credited to the receiver address",
|
Long: "The asset owner issues new tokens that will be credited to the receiver address",
|
||||||
Example: fmt.Sprintf(`$ %s tx %s issue 20000000usdtoken kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw
|
Example: fmt.Sprintf(`$ %s tx %s issue 20000000usdtoken 0g15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw
|
||||||
`, version.AppName, types.ModuleName),
|
`, version.AppName, types.ModuleName),
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
@ -106,7 +106,7 @@ func GetCmdBlockAddress() *cobra.Command {
|
|||||||
Use: "block [address] [denom]",
|
Use: "block [address] [denom]",
|
||||||
Short: "block an address for the input denom",
|
Short: "block an address for the input denom",
|
||||||
Long: "The asset owner blocks an address from holding coins of that denomination. Any tokens of the input denomination held by the address will be sent to the owner address",
|
Long: "The asset owner blocks an address from holding coins of that denomination. Any tokens of the input denomination held by the address will be sent to the owner address",
|
||||||
Example: fmt.Sprintf(`$ %s tx %s block kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw usdtoken
|
Example: fmt.Sprintf(`$ %s tx %s block 0g15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw usdtoken
|
||||||
`, version.AppName, types.ModuleName),
|
`, version.AppName, types.ModuleName),
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
@ -139,7 +139,7 @@ func GetCmdUnblockAddress() *cobra.Command {
|
|||||||
Use: "unblock [address] [denom]",
|
Use: "unblock [address] [denom]",
|
||||||
Short: "unblock an address for the input denom",
|
Short: "unblock an address for the input denom",
|
||||||
Long: "The asset owner unblocks an address from holding coins of that denomination.",
|
Long: "The asset owner unblocks an address from holding coins of that denomination.",
|
||||||
Example: fmt.Sprintf(`$ %s tx %s unblock kava15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw usdtoken
|
Example: fmt.Sprintf(`$ %s tx %s unblock 0g15qdefkmwswysgg4qxgqpqr35k3m49pkx2jdfnw usdtoken
|
||||||
`, version.AppName, types.ModuleName),
|
`, version.AppName, types.ModuleName),
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
@ -47,7 +47,7 @@ func (suite *KeeperTestSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
keeper := tApp.GetIssuanceKeeper()
|
keeper := tApp.GetIssuanceKeeper()
|
||||||
modAccount, err := sdk.AccAddressFromBech32("kava1cj7njkw2g9fqx4e768zc75dp9sks8u9znxrf0w")
|
modAccount, err := sdk.AccAddressFromBech32("0g1cj7njkw2g9fqx4e768zc75dp9sks8u9znxrf0w")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
suite.tApp = tApp
|
suite.tApp = tApp
|
||||||
|
@ -50,7 +50,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"blockable": true,
|
"blockable": true,
|
||||||
"blocked_addresses": null,
|
"blocked_addresses": null,
|
||||||
"denom": "hbtc",
|
"denom": "hbtc",
|
||||||
"owner": "kava1dmm9zpdnm6mfhywzt9sstm4p33y0cnsd0m673z",
|
"owner": "0g1dmm9zpdnm6mfhywzt9sstm4p33y0cnsd0m673z",
|
||||||
"paused": false,
|
"paused": false,
|
||||||
"rate_limit": {
|
"rate_limit": {
|
||||||
"active": false,
|
"active": false,
|
||||||
@ -62,7 +62,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
},
|
},
|
||||||
"supplies": [
|
"supplies": [
|
||||||
{
|
{
|
||||||
"current_supply": { "denom": "ukava", "amount": "100" },
|
"current_supply": { "denom": "neuron", "amount": "100000000000000" },
|
||||||
"time_elapsed": "3600000000000"
|
"time_elapsed": "3600000000000"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -83,7 +83,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"blockable": true,
|
"blockable": true,
|
||||||
"blocked_addresses": [],
|
"blocked_addresses": [],
|
||||||
"denom": "hbtc",
|
"denom": "hbtc",
|
||||||
"owner": "kava1dmm9zpdnm6mfhywzt9sstm4p33y0cnsd0m673z",
|
"owner": "0g1dmm9zpdnm6mfhywzt9sstm4p33y0cnsd0m673z",
|
||||||
"paused": false,
|
"paused": false,
|
||||||
"rate_limit": {
|
"rate_limit": {
|
||||||
"active": false,
|
"active": false,
|
||||||
@ -95,7 +95,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
},
|
},
|
||||||
"supplies": [
|
"supplies": [
|
||||||
{
|
{
|
||||||
"current_supply": { "denom": "ukava", "amount": "100" },
|
"current_supply": { "denom": "neuron", "amount": "100000000000000" },
|
||||||
"time_elapsed": "3600s"
|
"time_elapsed": "3600s"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -114,7 +114,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
|
|||||||
Assets: v015issuance.Assets{
|
Assets: v015issuance.Assets{
|
||||||
{
|
{
|
||||||
Owner: s.addresses[0],
|
Owner: s.addresses[0],
|
||||||
Denom: "ukava",
|
Denom: "neuron",
|
||||||
BlockedAddresses: s.addresses[1:2],
|
BlockedAddresses: s.addresses[1:2],
|
||||||
Paused: true,
|
Paused: true,
|
||||||
Blockable: true,
|
Blockable: true,
|
||||||
@ -130,7 +130,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
|
|||||||
Assets: []v016issuance.Asset{
|
Assets: []v016issuance.Asset{
|
||||||
{
|
{
|
||||||
Owner: s.addresses[0].String(),
|
Owner: s.addresses[0].String(),
|
||||||
Denom: "ukava",
|
Denom: "neuron",
|
||||||
BlockedAddresses: []string{s.addresses[1].String()},
|
BlockedAddresses: []string{s.addresses[1].String()},
|
||||||
Paused: true,
|
Paused: true,
|
||||||
Blockable: true,
|
Blockable: true,
|
||||||
@ -149,7 +149,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
|
|||||||
func (s *migrateTestSuite) TestMigrate_Supplies() {
|
func (s *migrateTestSuite) TestMigrate_Supplies() {
|
||||||
s.v15genstate.Supplies = v015issuance.AssetSupplies{
|
s.v15genstate.Supplies = v015issuance.AssetSupplies{
|
||||||
{
|
{
|
||||||
CurrentSupply: sdk.NewCoin("ukava", sdkmath.NewInt(100)),
|
CurrentSupply: sdk.NewCoin("neuron", sdkmath.NewInt(100000000000000)),
|
||||||
TimeElapsed: time.Duration(1 * time.Hour),
|
TimeElapsed: time.Duration(1 * time.Hour),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -159,7 +159,7 @@ func (s *migrateTestSuite) TestMigrate_Supplies() {
|
|||||||
}
|
}
|
||||||
expected := []v016issuance.AssetSupply{
|
expected := []v016issuance.AssetSupply{
|
||||||
{
|
{
|
||||||
CurrentSupply: sdk.NewCoin("ukava", sdkmath.NewInt(100)),
|
CurrentSupply: sdk.NewCoin("neuron", sdkmath.NewInt(100000000000000)),
|
||||||
TimeElapsed: time.Duration(1 * time.Hour),
|
TimeElapsed: time.Duration(1 * time.Hour),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -49,14 +49,14 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"active": true,
|
"active": true,
|
||||||
"base_asset": "bnb",
|
"base_asset": "bnb",
|
||||||
"market_id": "bnb:usd",
|
"market_id": "bnb:usd",
|
||||||
"oracles": ["kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"],
|
"oracles": ["0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"],
|
||||||
"quote_asset": "usd"
|
"quote_asset": "usd"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"active": true,
|
"active": true,
|
||||||
"base_asset": "bnb",
|
"base_asset": "bnb",
|
||||||
"market_id": "bnb:usd:30",
|
"market_id": "bnb:usd:30",
|
||||||
"oracles": ["kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"],
|
"oracles": ["0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"],
|
||||||
"quote_asset": "usd"
|
"quote_asset": "usd"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -65,13 +65,13 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
{
|
{
|
||||||
"expiry": "2022-07-20T00:00:00Z",
|
"expiry": "2022-07-20T00:00:00Z",
|
||||||
"market_id": "bnb:usd",
|
"market_id": "bnb:usd",
|
||||||
"oracle_address": "kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em",
|
"oracle_address": "0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em",
|
||||||
"price": "215.962650000000001782"
|
"price": "215.962650000000001782"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"expiry": "2022-07-20T00:00:00Z",
|
"expiry": "2022-07-20T00:00:00Z",
|
||||||
"market_id": "bnb:usd:30",
|
"market_id": "bnb:usd:30",
|
||||||
"oracle_address": "kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em",
|
"oracle_address": "0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em",
|
||||||
"price": "217.962650000000001782"
|
"price": "217.962650000000001782"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -85,7 +85,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "bnb",
|
"base_asset": "bnb",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -94,7 +94,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "bnb",
|
"base_asset": "bnb",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -103,7 +103,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "atom",
|
"base_asset": "atom",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -112,7 +112,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "atom",
|
"base_asset": "atom",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -121,7 +121,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "akt",
|
"base_asset": "akt",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -130,7 +130,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "akt",
|
"base_asset": "akt",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -139,7 +139,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "luna",
|
"base_asset": "luna",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -148,7 +148,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "luna",
|
"base_asset": "luna",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -157,7 +157,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "osmo",
|
"base_asset": "osmo",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -166,7 +166,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "osmo",
|
"base_asset": "osmo",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -175,7 +175,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "ust",
|
"base_asset": "ust",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
},
|
},
|
||||||
@ -184,7 +184,7 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"base_asset": "ust",
|
"base_asset": "ust",
|
||||||
"quote_asset": "usd",
|
"quote_asset": "usd",
|
||||||
"oracles": [
|
"oracles": [
|
||||||
"kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
"0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em"
|
||||||
],
|
],
|
||||||
"active": true
|
"active": true
|
||||||
}
|
}
|
||||||
@ -193,13 +193,13 @@ func (s *migrateTestSuite) TestMigrate_JSON() {
|
|||||||
"posted_prices": [
|
"posted_prices": [
|
||||||
{
|
{
|
||||||
"market_id": "bnb:usd",
|
"market_id": "bnb:usd",
|
||||||
"oracle_address": "kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em",
|
"oracle_address": "0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em",
|
||||||
"price": "215.962650000000001782",
|
"price": "215.962650000000001782",
|
||||||
"expiry": "2022-07-20T00:00:00Z"
|
"expiry": "2022-07-20T00:00:00Z"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"market_id": "bnb:usd:30",
|
"market_id": "bnb:usd:30",
|
||||||
"oracle_address": "kava1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em",
|
"oracle_address": "0g1acge4tcvhf3q6fh53fgwaa7vsq40wvx6wn50em",
|
||||||
"price": "217.962650000000001782",
|
"price": "217.962650000000001782",
|
||||||
"expiry": "2022-07-20T00:00:00Z"
|
"expiry": "2022-07-20T00:00:00Z"
|
||||||
}
|
}
|
||||||
@ -222,7 +222,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
|
|||||||
Markets: v015pricefeed.Markets{
|
Markets: v015pricefeed.Markets{
|
||||||
{
|
{
|
||||||
MarketID: "market-1",
|
MarketID: "market-1",
|
||||||
BaseAsset: "kava",
|
BaseAsset: "a0gi",
|
||||||
QuoteAsset: "usd",
|
QuoteAsset: "usd",
|
||||||
Oracles: s.addresses,
|
Oracles: s.addresses,
|
||||||
Active: true,
|
Active: true,
|
||||||
@ -233,7 +233,7 @@ func (s *migrateTestSuite) TestMigrate_Params() {
|
|||||||
Markets: v016pricefeed.Markets{
|
Markets: v016pricefeed.Markets{
|
||||||
{
|
{
|
||||||
MarketID: "market-1",
|
MarketID: "market-1",
|
||||||
BaseAsset: "kava",
|
BaseAsset: "a0gi",
|
||||||
QuoteAsset: "usd",
|
QuoteAsset: "usd",
|
||||||
Oracles: s.addresses,
|
Oracles: s.addresses,
|
||||||
Active: true,
|
Active: true,
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func TestRawPriceKey_Iteration(t *testing.T) {
|
func TestRawPriceKey_Iteration(t *testing.T) {
|
||||||
// An iterator key should only match price keys with the same market
|
// An iterator key should only match price keys with the same market
|
||||||
iteratorKey := RawPriceIteratorKey("kava:usd")
|
iteratorKey := RawPriceIteratorKey("a0gi:usd")
|
||||||
|
|
||||||
addr := sdk.AccAddress("test addr")
|
addr := sdk.AccAddress("test addr")
|
||||||
|
|
||||||
@ -20,12 +20,12 @@ func TestRawPriceKey_Iteration(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "equal marketID is included in iteration",
|
name: "equal marketID is included in iteration",
|
||||||
priceKey: RawPriceKey("kava:usd", addr),
|
priceKey: RawPriceKey("a0gi:usd", addr),
|
||||||
expectErr: false,
|
expectErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prefix overlapping marketID excluded from iteration",
|
name: "prefix overlapping marketID excluded from iteration",
|
||||||
priceKey: RawPriceKey("kava:usd:30", addr),
|
priceKey: RawPriceKey("a0gi:usd:30", addr),
|
||||||
expectErr: true,
|
expectErr: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ func queryCirculatingSupply() *cobra.Command {
|
|||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "circulating-supply",
|
Use: "circulating-supply",
|
||||||
Short: "Get circulating supply",
|
Short: "Get circulating supply",
|
||||||
Long: "Get the current circulating supply of kava tokens",
|
Long: "Get the current circulating supply of 0g tokens",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cliCtx, err := client.GetClientQueryContext(cmd)
|
cliCtx, err := client.GetClientQueryContext(cmd)
|
||||||
@ -69,7 +69,7 @@ func queryTotalSupply() *cobra.Command {
|
|||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "total-supply",
|
Use: "total-supply",
|
||||||
Short: "Get total supply",
|
Short: "Get total supply",
|
||||||
Long: "Get the current total supply of kava tokens",
|
Long: "Get the current total supply of 0g tokens",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cliCtx, err := client.GetClientQueryContext(cmd)
|
cliCtx, err := client.GetClientQueryContext(cmd)
|
||||||
|
Loading…
Reference in New Issue
Block a user