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
dde7485ee9
commit
f923983097
@ -7,7 +7,7 @@ FROM golang:1.21-alpine AS build-env
|
||||
RUN apk add bash git make libc-dev gcc linux-headers eudev-dev jq curl
|
||||
|
||||
# Set working directory for the build
|
||||
WORKDIR /root/kava
|
||||
WORKDIR /root/0g-chain
|
||||
# default home directory is /root
|
||||
|
||||
# Copy dependency files first to facilitate dependency caching
|
||||
@ -32,6 +32,6 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
FROM alpine:3.15
|
||||
|
||||
RUN apk add bash jq curl
|
||||
COPY --from=build-env /go/bin/kava /bin/kava
|
||||
COPY --from=build-env /go/bin/0gchaind /bin/0gchaind
|
||||
|
||||
CMD ["kava"]
|
||||
CMD ["0gchaind"]
|
||||
|
@ -1,4 +1,4 @@
|
||||
FROM golang:1.21-bullseye AS kava-builder
|
||||
FROM golang:1.21-bullseye AS chain-builder
|
||||
|
||||
# Set up dependencies
|
||||
RUN apt-get update \
|
||||
@ -19,7 +19,7 @@ RUN git clone https://github.com/facebook/rocksdb.git \
|
||||
&& make -j$(nproc) install-shared \
|
||||
&& ldconfig
|
||||
|
||||
WORKDIR /root/kava
|
||||
WORKDIR /root/0gchain
|
||||
# Copy dependency files first to facilitate dependency caching
|
||||
COPY ./go.mod ./
|
||||
COPY ./go.sum ./
|
||||
@ -32,13 +32,13 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
# Add source files
|
||||
COPY . .
|
||||
|
||||
ARG kava_database_backend=rocksdb
|
||||
ENV KAVA_DATABASE_BACKEND=$kava_database_backend
|
||||
ARG 0gchain_database_backend=rocksdb
|
||||
ENV 0GCHAIN_DATABASE_BACKEND=$0gchain_database_backend
|
||||
|
||||
# Mount go build and mod caches as container caches, persisted between builder invocations
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
make install COSMOS_BUILD_OPTIONS=$KAVA_DATABASE_BACKEND
|
||||
make install COSMOS_BUILD_OPTIONS=$0GCHAIN_DATABASE_BACKEND
|
||||
|
||||
|
||||
FROM ubuntu:22.04
|
||||
@ -48,10 +48,10 @@ RUN apt-get update \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# copy rocksdb shared objects
|
||||
COPY --from=kava-builder /usr/local/lib/ /usr/local/lib/
|
||||
COPY --from=chain-builder /usr/local/lib/ /usr/local/lib/
|
||||
RUN ldconfig
|
||||
|
||||
# copy kava binary
|
||||
COPY --from=kava-builder /go/bin/kava /bin/kava
|
||||
# copy 0g-chain binary
|
||||
COPY --from=chain-builder /go/bin/0gchaind /bin/0gchaind
|
||||
|
||||
CMD ["kava"]
|
||||
CMD ["0gchaind"]
|
||||
|
@ -32,14 +32,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
||||
|
||||
"github.com/0glabs/0g-chain/x/auction"
|
||||
"github.com/0glabs/0g-chain/x/bep3"
|
||||
"github.com/0glabs/0g-chain/x/cdp"
|
||||
"github.com/0glabs/0g-chain/x/committee"
|
||||
"github.com/0glabs/0g-chain/x/incentive"
|
||||
"github.com/0glabs/0g-chain/x/kavadist"
|
||||
"github.com/0glabs/0g-chain/x/pricefeed"
|
||||
"github.com/0glabs/0g-chain/x/swap"
|
||||
validatorvesting "github.com/0glabs/0g-chain/x/validator-vesting"
|
||||
)
|
||||
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
||||
@ -52,9 +53,9 @@ func (suite *SimulateRequestTestSuite) TearDownTest() {
|
||||
}
|
||||
|
||||
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||
fromAddr, err := sdk.AccAddressFromBech32("kava1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||
fromAddr, err := sdk.AccAddressFromBech32("0g1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||
suite.Require().NoError(err)
|
||||
toAddr, err := sdk.AccAddressFromBech32("kava1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||
toAddr, err := sdk.AccAddressFromBech32("0g1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
simRequest := app.SimulateRequest{
|
||||
@ -62,11 +63,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||
bank.MsgSend{
|
||||
FromAddress: fromAddr,
|
||||
ToAddress: toAddr,
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
},
|
||||
Fee: auth.StdFee{
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(5e4))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(5e4))),
|
||||
Gas: 1e6,
|
||||
},
|
||||
Memo: "test memo",
|
||||
|
@ -21,12 +21,13 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
// bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||
// pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
@ -51,7 +52,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
App: *app.NewApp(
|
||||
log.NewNopLogger(),
|
||||
tmdb.NewMemDB(),
|
||||
app.DefaultNodeHome,
|
||||
chaincfg.DefaultNodeHome,
|
||||
nil,
|
||||
encodingConfig,
|
||||
opts,
|
||||
@ -65,7 +66,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
chainID,
|
||||
app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e9)),
|
||||
testAddresses,
|
||||
),
|
||||
// newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
||||
@ -113,7 +114,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
tc.address,
|
||||
testAddresses[0],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
||||
@ -45,7 +46,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -80,12 +81,12 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[2],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
@ -121,7 +122,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
},
|
||||
sdk.NewCoins(), // no fee
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
|
||||
@ -58,7 +59,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||
),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -128,7 +129,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
[]sdk.Msg{banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||
)}),
|
||||
},
|
||||
checkTx: false,
|
||||
@ -161,7 +162,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0],
|
||||
testAddresses[3],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||
),
|
||||
&evmtypes.MsgEthereumTx{},
|
||||
},
|
||||
|
@ -34,6 +34,8 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
// cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||
@ -158,7 +160,7 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
// Genesis states
|
||||
evmGs := evmtypes.NewGenesisState(
|
||||
evmtypes.NewParams(
|
||||
"akava", // evmDenom
|
||||
chaincfg.BaseDenom, // evmDenom
|
||||
false, // allowedUnprotectedTxs
|
||||
true, // enableCreate
|
||||
true, // enableCall
|
||||
@ -267,10 +269,10 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
// pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||
}
|
||||
|
||||
// funds our test accounts with some ukava
|
||||
// funds our test accounts with some a0gi
|
||||
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
||||
tApp.AppCodec(),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e9)),
|
||||
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
||||
)
|
||||
|
||||
@ -357,45 +359,17 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
params := evmKeeper.GetParams(suite.ctx)
|
||||
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
||||
{
|
||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "initiator", Type: "string"},
|
||||
{Name: "receiver", Type: "string"},
|
||||
{Name: "kava_erc20_address", Type: "string"},
|
||||
{Name: "0gchain_erc20_address", Type: "string"},
|
||||
{Name: "amount", Type: "string"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgCreateCDP",
|
||||
MsgValueTypeName: "MsgValueCDPCreate",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "sender", Type: "string"},
|
||||
{Name: "collateral", Type: "Coin"},
|
||||
{Name: "principal", Type: "Coin"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgDeposit",
|
||||
MsgValueTypeName: "MsgValueCDPDeposit",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "owner", Type: "string"},
|
||||
{Name: "collateral", Type: "Coin"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgDeposit",
|
||||
MsgValueTypeName: "MsgValueHardDeposit",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "amount", Type: "Coin[]"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "initiator", Type: "string"},
|
||||
@ -403,23 +377,6 @@ func (suite *EIP712TestSuite) SetupTest() {
|
||||
{Name: "amount", Type: "Coin"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgRepayDebt",
|
||||
MsgValueTypeName: "MsgValueCDPRepayDebt",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "sender", Type: "string"},
|
||||
{Name: "collateral_type", Type: "string"},
|
||||
{Name: "payment", Type: "Coin"},
|
||||
},
|
||||
},
|
||||
{
|
||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgWithdraw",
|
||||
MsgValueTypeName: "MsgValueHardWithdraw",
|
||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||
{Name: "depositor", Type: "string"},
|
||||
{Name: "amount", Type: "Coin[]"},
|
||||
},
|
||||
},
|
||||
}
|
||||
evmKeeper.SetParams(suite.ctx, params)
|
||||
|
||||
@ -465,7 +422,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
|
||||
suite.tApp.FundModuleAccount(
|
||||
suite.ctx,
|
||||
evmutiltypes.ModuleName,
|
||||
sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(0))),
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
||||
@ -565,7 +522,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
errMsg: "insufficient funds",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
bk := suite.tApp.GetBankKeeper()
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, "ukava")
|
||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.DisplayDenom)
|
||||
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
||||
return txBuilder
|
||||
},
|
||||
@ -577,9 +534,9 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx: true,
|
||||
errMsg: "invalid chain-id",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
suite.testAddr, suite.testPrivKey, "0gchaintest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
},
|
||||
},
|
||||
@ -590,7 +547,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
failCheckTx: true,
|
||||
errMsg: "invalid pubkey",
|
||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
return suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -630,7 +587,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
||||
msgs = tc.updateMsgs(msgs)
|
||||
}
|
||||
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||
)
|
||||
@ -716,7 +673,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
||||
}
|
||||
|
||||
// deliver deposit msg
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
||||
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
||||
)
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func mustParseDecCoins(value string) sdk.DecCoins {
|
||||
@ -30,7 +31,7 @@ func TestEvmMinGasFilter(t *testing.T) {
|
||||
|
||||
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
||||
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
||||
EvmDenom: "akava",
|
||||
EvmDenom: chaincfg.BaseDenom,
|
||||
})
|
||||
|
||||
testCases := []struct {
|
||||
@ -44,29 +45,29 @@ func TestEvmMinGasFilter(t *testing.T) {
|
||||
mustParseDecCoins(""),
|
||||
},
|
||||
{
|
||||
"zero ukava gas price",
|
||||
mustParseDecCoins("0ukava"),
|
||||
mustParseDecCoins("0ukava"),
|
||||
"zero a0gi gas price",
|
||||
mustParseDecCoins("0a0gi"),
|
||||
mustParseDecCoins("0a0gi"),
|
||||
},
|
||||
{
|
||||
"non-zero ukava gas price",
|
||||
mustParseDecCoins("0.001ukava"),
|
||||
mustParseDecCoins("0.001ukava"),
|
||||
"non-zero a0gi gas price",
|
||||
mustParseDecCoins("0.001a0gi"),
|
||||
mustParseDecCoins("0.001a0gi"),
|
||||
},
|
||||
{
|
||||
"zero ukava gas price, min akava price",
|
||||
mustParseDecCoins("0ukava;100000akava"),
|
||||
mustParseDecCoins("0ukava"), // akava is removed
|
||||
"zero a0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0a0gi;100000neuron"),
|
||||
mustParseDecCoins("0a0gi"), // neuron is removed
|
||||
},
|
||||
{
|
||||
"zero ukava gas price, min akava price, other token",
|
||||
mustParseDecCoins("0ukava;100000akava;0.001other"),
|
||||
mustParseDecCoins("0ukava;0.001other"), // akava is removed
|
||||
"zero a0gi gas price, min neuron price, other token",
|
||||
mustParseDecCoins("0a0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0a0gi;0.001other"), // neuron is removed
|
||||
},
|
||||
{
|
||||
"non-zero ukava gas price, min akava price",
|
||||
mustParseDecCoins("0.25ukava;100000akava;0.001other"),
|
||||
mustParseDecCoins("0.25ukava;0.001other"), // akava is removed
|
||||
"non-zero a0gi gas price, min neuron price",
|
||||
mustParseDecCoins("0.25a0gi;100000neuron;0.001other"),
|
||||
mustParseDecCoins("0.25a0gi;0.001other"), // neuron is removed
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
)
|
||||
|
||||
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
||||
@ -33,7 +34,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreateVestingAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||
false,
|
||||
),
|
||||
@ -44,7 +45,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"MsgCreateVestingAccount",
|
||||
vesting.NewMsgCreatePermanentLockedAccount(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
true,
|
||||
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||
@ -63,7 +64,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
||||
"other messages not affected",
|
||||
banktypes.NewMsgSend(
|
||||
testAddresses[0], testAddresses[1],
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||
),
|
||||
false,
|
||||
"",
|
||||
|
62
app/app.go
62
app/app.go
@ -3,10 +3,6 @@ package app
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
stdlog "log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
dbm "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
@ -103,10 +99,10 @@ import (
|
||||
"github.com/evmos/ethermint/x/feemarket"
|
||||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/0glabs/0g-chain/app/ante"
|
||||
kavaparams "github.com/0glabs/0g-chain/app/params"
|
||||
chainparams "github.com/0glabs/0g-chain/app/params"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
evmutil "github.com/0glabs/0g-chain/x/evmutil"
|
||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
@ -123,14 +119,7 @@ import (
|
||||
validatorvestingtypes "github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
const (
|
||||
appName = "kava"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaultNodeHome default home directories for the application daemon
|
||||
DefaultNodeHome string
|
||||
|
||||
// ModuleBasics manages simple versions of full app modules.
|
||||
// It's used for things such as codec registration and genesis file verification.
|
||||
ModuleBasics = module.NewBasicManager(
|
||||
@ -208,7 +197,7 @@ var DefaultOptions = Options{
|
||||
EVMMaxGasWanted: ethermintconfig.DefaultMaxTxGasWanted,
|
||||
}
|
||||
|
||||
// App is the Kava ABCI application.
|
||||
// App is the 0gChain ABCI application.
|
||||
type App struct {
|
||||
*baseapp.BaseApp
|
||||
|
||||
@ -260,22 +249,13 @@ type App struct {
|
||||
configurator module.Configurator
|
||||
}
|
||||
|
||||
func init() {
|
||||
userHomeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
stdlog.Printf("Failed to get home dir %v", err)
|
||||
}
|
||||
|
||||
DefaultNodeHome = filepath.Join(userHomeDir, ".kava")
|
||||
}
|
||||
|
||||
// NewApp returns a reference to an initialized App.
|
||||
func NewApp(
|
||||
logger tmlog.Logger,
|
||||
db dbm.DB,
|
||||
homePath string,
|
||||
traceStore io.Writer,
|
||||
encodingConfig kavaparams.EncodingConfig,
|
||||
encodingConfig chainparams.EncodingConfig,
|
||||
options Options,
|
||||
baseAppOptions ...func(*baseapp.BaseApp),
|
||||
) *App {
|
||||
@ -283,7 +263,7 @@ func NewApp(
|
||||
legacyAmino := encodingConfig.Amino
|
||||
interfaceRegistry := encodingConfig.InterfaceRegistry
|
||||
|
||||
bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
|
||||
bApp := baseapp.NewBaseApp(chaincfg.AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
|
||||
bApp.SetCommitMultiStoreTracer(traceStore)
|
||||
bApp.SetVersion(version.Version)
|
||||
bApp.SetInterfaceRegistry(interfaceRegistry)
|
||||
@ -779,7 +759,7 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Store current module versions in kava-10 to setup future in-place upgrades.
|
||||
// Store current module versions in 0gChain-10 to setup future in-place upgrades.
|
||||
// During in-place migrations, the old module versions in the store will be referenced to determine which migrations to run.
|
||||
app.upgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
|
||||
|
||||
@ -818,9 +798,6 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
|
||||
// Register custom REST routes
|
||||
validatorvestingrest.RegisterRoutes(clientCtx, apiSvr.Router)
|
||||
|
||||
// Register rewrite routes
|
||||
RegisterAPIRouteRewrites(apiSvr.Router)
|
||||
|
||||
// Register GRPC Gateway routes
|
||||
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
|
||||
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
|
||||
@ -830,33 +807,6 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
|
||||
// Swagger API configuration is ignored
|
||||
}
|
||||
|
||||
// RegisterAPIRouteRewrites registers overwritten API routes that are
|
||||
// registered after this function is called. This must be called before any
|
||||
// other route registrations on the router in order for rewrites to take effect.
|
||||
// The first route that matches in the mux router wins, so any registrations
|
||||
// here will be prioritized over the later registrations in modules.
|
||||
func RegisterAPIRouteRewrites(router *mux.Router) {
|
||||
// Mapping of client path to backend path. Similar to nginx rewrite rules,
|
||||
// but does not return a 301 or 302 redirect.
|
||||
// Eg: querying /cosmos/distribution/v1beta1/community_pool will return
|
||||
// the same response as querying /kava/community/v1beta1/total_balance
|
||||
routeMap := map[string]string{
|
||||
"/cosmos/distribution/v1beta1/community_pool": "/kava/community/v1beta1/total_balance",
|
||||
}
|
||||
|
||||
for clientPath, backendPath := range routeMap {
|
||||
router.HandleFunc(
|
||||
clientPath,
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
r.URL.Path = backendPath
|
||||
|
||||
// Use handler of the new path
|
||||
router.ServeHTTP(w, r)
|
||||
},
|
||||
).Methods("GET")
|
||||
}
|
||||
}
|
||||
|
||||
// RegisterTxService implements the Application.RegisterTxService method.
|
||||
// It registers transaction related endpoints on the app's grpc server.
|
||||
func (app *App) RegisterTxService(clientCtx client.Context) {
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
db "github.com/cometbft/cometbft-db"
|
||||
abci "github.com/cometbft/cometbft/abci/types"
|
||||
"github.com/cometbft/cometbft/libs/log"
|
||||
@ -25,11 +26,11 @@ import (
|
||||
)
|
||||
|
||||
func TestNewApp(t *testing.T) {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
NewApp(
|
||||
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
||||
db.NewMemDB(),
|
||||
DefaultNodeHome,
|
||||
chaincfg.DefaultNodeHome,
|
||||
nil,
|
||||
MakeEncodingConfig(),
|
||||
DefaultOptions,
|
||||
@ -37,9 +38,9 @@ func TestNewApp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExport(t *testing.T) {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
db := db.NewMemDB()
|
||||
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
||||
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, chaincfg.DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
||||
|
||||
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())
|
||||
|
||||
|
@ -1,41 +0,0 @@
|
||||
package app
|
||||
|
||||
import sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
const (
|
||||
// Bech32MainPrefix defines the Bech32 prefix for account addresses
|
||||
Bech32MainPrefix = "kava"
|
||||
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
||||
Bech32PrefixAccPub = Bech32MainPrefix + "pub"
|
||||
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
||||
Bech32PrefixValAddr = Bech32MainPrefix + "val" + "oper"
|
||||
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
||||
Bech32PrefixValPub = Bech32MainPrefix + "val" + "oper" + "pub"
|
||||
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
||||
Bech32PrefixConsAddr = Bech32MainPrefix + "val" + "cons"
|
||||
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
||||
Bech32PrefixConsPub = Bech32MainPrefix + "val" + "cons" + "pub"
|
||||
|
||||
Bip44CoinType = 459 // see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||
)
|
||||
|
||||
// SetSDKConfig configures the global config with kava app specific parameters.
|
||||
// It does not seal the config to allow modification in tests.
|
||||
func SetSDKConfig() *sdk.Config {
|
||||
config := sdk.GetConfig()
|
||||
SetBech32AddressPrefixes(config)
|
||||
SetBip44CoinType(config)
|
||||
return config
|
||||
}
|
||||
|
||||
// SetBech32AddressPrefixes sets the global prefix to be used when serializing addresses to bech32 strings.
|
||||
func SetBech32AddressPrefixes(config *sdk.Config) {
|
||||
config.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32PrefixAccPub)
|
||||
config.SetBech32PrefixForValidator(Bech32PrefixValAddr, Bech32PrefixValPub)
|
||||
config.SetBech32PrefixForConsensusNode(Bech32PrefixConsAddr, Bech32PrefixConsPub)
|
||||
}
|
||||
|
||||
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
|
||||
func SetBip44CoinType(config *sdk.Config) {
|
||||
config.SetCoinType(Bip44CoinType)
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Package params defines the simulation parameters for the Kava app.
|
||||
Package params defines the simulation parameters for the 0gChain app.
|
||||
|
||||
It contains the default weights used for each transaction used on the module's
|
||||
simulation. These weights define the chance for a transaction to be simulated at
|
||||
|
@ -41,6 +41,7 @@ import (
|
||||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
)
|
||||
|
||||
@ -49,7 +50,7 @@ var (
|
||||
defaultInitialHeight int64 = 1
|
||||
)
|
||||
|
||||
const TestChainId = "kavatest_2221-1"
|
||||
const TestChainId = "0gchaintest_2221-1"
|
||||
|
||||
// TestApp is a simple wrapper around an App. It exposes internal keepers for use in integration tests.
|
||||
// This file also contains test helpers. Ideally they would be in separate package.
|
||||
@ -74,7 +75,7 @@ type TestApp struct {
|
||||
//
|
||||
// Note, it also sets the sdk config with the app's address prefix, coin type, etc.
|
||||
func NewTestApp() TestApp {
|
||||
SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
return NewTestAppFromSealed()
|
||||
}
|
||||
@ -86,7 +87,7 @@ func NewTestAppFromSealed() TestApp {
|
||||
encCfg := MakeEncodingConfig()
|
||||
|
||||
app := NewApp(
|
||||
log.NewNopLogger(), db, DefaultNodeHome, nil,
|
||||
log.NewNopLogger(), db, chaincfg.DefaultNodeHome, nil,
|
||||
encCfg, DefaultOptions, baseapp.SetChainID(TestChainId),
|
||||
)
|
||||
return TestApp{App: *app}
|
||||
@ -103,28 +104,11 @@ func (tApp TestApp) GetGovKeeper() govkeeper.Keeper { return tApp.go
|
||||
func (tApp TestApp) GetCrisisKeeper() crisiskeeper.Keeper { return tApp.crisisKeeper }
|
||||
func (tApp TestApp) GetParamsKeeper() paramskeeper.Keeper { return tApp.paramsKeeper }
|
||||
|
||||
// func (tApp TestApp) GetKavadistKeeper() kavadistkeeper.Keeper { return tApp.kavadistKeeper }
|
||||
// func (tApp TestApp) GetAuctionKeeper() auctionkeeper.Keeper { return tApp.auctionKeeper }
|
||||
// func (tApp TestApp) GetIssuanceKeeper() issuancekeeper.Keeper { return tApp.issuanceKeeper }
|
||||
// func (tApp TestApp) GetBep3Keeper() bep3keeper.Keeper { return tApp.bep3Keeper }
|
||||
|
||||
// func (tApp TestApp) GetPriceFeedKeeper() pricefeedkeeper.Keeper { return tApp.pricefeedKeeper }
|
||||
// func (tApp TestApp) GetSwapKeeper() swapkeeper.Keeper { return tApp.swapKeeper }
|
||||
// func (tApp TestApp) GetCDPKeeper() cdpkeeper.Keeper { return tApp.cdpKeeper }
|
||||
// func (tApp TestApp) GetHardKeeper() hardkeeper.Keeper { return tApp.hardKeeper }
|
||||
// func (tApp TestApp) GetCommitteeKeeper() committeekeeper.Keeper { return tApp.committeeKeeper }
|
||||
// func (tApp TestApp) GetIncentiveKeeper() incentivekeeper.Keeper { return tApp.incentiveKeeper }
|
||||
func (tApp TestApp) GetEvmutilKeeper() evmutilkeeper.Keeper { return tApp.evmutilKeeper }
|
||||
func (tApp TestApp) GetEvmKeeper() *evmkeeper.Keeper { return tApp.evmKeeper }
|
||||
|
||||
// func (tApp TestApp) GetSavingsKeeper() savingskeeper.Keeper { return tApp.savingsKeeper }
|
||||
func (tApp TestApp) GetFeeMarketKeeper() feemarketkeeper.Keeper { return tApp.feeMarketKeeper }
|
||||
|
||||
// func (tApp TestApp) GetLiquidKeeper() liquidkeeper.Keeper { return tApp.liquidKeeper }
|
||||
// func (tApp TestApp) GetEarnKeeper() earnkeeper.Keeper { return tApp.earnKeeper }
|
||||
// func (tApp TestApp) GetRouterKeeper() routerkeeper.Keeper { return tApp.routerKeeper }
|
||||
// func (tApp TestApp) GetCommunityKeeper() communitykeeper.Keeper { return tApp.communityKeeper }
|
||||
|
||||
func (tApp TestApp) GetKVStoreKey(key string) *storetypes.KVStoreKey {
|
||||
return tApp.keys[key]
|
||||
}
|
||||
@ -163,7 +147,7 @@ func GenesisStateWithSingleValidator(
|
||||
balances := []banktypes.Balance{
|
||||
{
|
||||
Address: acc.GetAddress().String(),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(100000000000000))),
|
||||
Coins: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(100000000000000))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -226,7 +210,7 @@ func genesisStateWithValSet(
|
||||
}
|
||||
// set validators and delegations
|
||||
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
||||
currentStakingGenesis.Params.BondDenom = "ukava"
|
||||
currentStakingGenesis.Params.BondDenom = chaincfg.DisplayDenom
|
||||
|
||||
stakingGenesis := stakingtypes.NewGenesisState(
|
||||
currentStakingGenesis.Params,
|
||||
@ -246,13 +230,13 @@ func genesisStateWithValSet(
|
||||
|
||||
for range delegations {
|
||||
// add delegated tokens to total supply
|
||||
totalSupply = totalSupply.Add(sdk.NewCoin("ukava", bondAmt))
|
||||
totalSupply = totalSupply.Add(sdk.NewCoin(chaincfg.DisplayDenom, bondAmt))
|
||||
}
|
||||
|
||||
// add bonded amount to bonded pool module account
|
||||
balances = append(balances, banktypes.Balance{
|
||||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
||||
Coins: sdk.Coins{sdk.NewCoin("ukava", bondAmt)},
|
||||
Coins: sdk.Coins{sdk.NewCoin(chaincfg.DisplayDenom, bondAmt)},
|
||||
})
|
||||
|
||||
bankGenesis := banktypes.NewGenesisState(
|
||||
|
@ -62,36 +62,36 @@ func TestKvCLIKeysAddRecover(t *testing.T) {
|
||||
|
||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
||||
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
|
||||
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.Equal(t, "kava1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
||||
require.Equal(t, "0g1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
||||
|
||||
// Cleanup testing directories
|
||||
f.Cleanup()
|
||||
}
|
||||
|
||||
func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
||||
func TestZgChainCLIKeysAddRecoverHDPath(t *testing.T) {
|
||||
t.Parallel()
|
||||
f := InitFixtures(t)
|
||||
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
||||
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
||||
|
||||
// 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")
|
||||
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")
|
||||
require.False(t, exitSuccess)
|
||||
@ -99,11 +99,11 @@ func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
||||
// 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")
|
||||
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")
|
||||
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
|
||||
f.Cleanup()
|
||||
|
@ -92,7 +92,7 @@ type Fixtures struct {
|
||||
|
||||
// NewFixtures creates a new instance of Fixtures with many vars set
|
||||
func NewFixtures(t *testing.T) *Fixtures {
|
||||
tmpDir, err := ioutil.TempDir("", "kava_integration_"+t.Name()+"_")
|
||||
tmpDir, err := ioutil.TempDir("", "0gchain_integration_"+t.Name()+"_")
|
||||
require.NoError(t, err)
|
||||
|
||||
servAddr, port, err := server.FreeTCPAddr()
|
||||
@ -201,9 +201,9 @@ func (f *Fixtures) Flags() string {
|
||||
}
|
||||
|
||||
//___________________________________________________________________________________
|
||||
// kavad
|
||||
// 0gchaind
|
||||
|
||||
// UnsafeResetAll is kavad unsafe-reset-all
|
||||
// UnsafeResetAll is 0gchaind unsafe-reset-all
|
||||
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
||||
executeWrite(f.T, addFlags(cmd, flags))
|
||||
@ -211,7 +211,7 @@ func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||
require.NoError(f.T, err)
|
||||
}
|
||||
|
||||
// KvInit is kavad init
|
||||
// KvInit is 0gchaind init
|
||||
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
||||
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
|
||||
@ -229,25 +229,25 @@ func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||
f.ChainID = chainID
|
||||
}
|
||||
|
||||
// AddGenesisAccount is kavad add-genesis-account
|
||||
// AddGenesisAccount is 0gchaind add-genesis-account
|
||||
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.KvdBinary, address, coins, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// GenTx is kavad gentx
|
||||
// GenTx is 0gchaind gentx
|
||||
func (f *Fixtures) GenTx(name string, flags ...string) {
|
||||
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s --keyring-backend=test", f.KvdBinary, name, f.KvdHome, f.KvcliHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// CollectGenTxs is kavad collect-gentxs
|
||||
// CollectGenTxs is 0gchaind collect-gentxs
|
||||
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
||||
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||
}
|
||||
|
||||
// GDStart runs kavad start with the appropriate flags and returns a process
|
||||
// GDStart runs 0gchaind start with the appropriate flags and returns a process
|
||||
func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
||||
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v --pruning=everything", f.KvdBinary, f.KvdHome, f.RPCAddr, f.P2PAddr)
|
||||
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
|
||||
@ -256,7 +256,7 @@ func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
||||
return proc
|
||||
}
|
||||
|
||||
// GDTendermint returns the results of kavad tendermint [query]
|
||||
// GDTendermint returns the results of 0gchaind tendermint [query]
|
||||
func (f *Fixtures) GDTendermint(query string) string {
|
||||
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
||||
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
||||
@ -265,7 +265,7 @@ func (f *Fixtures) GDTendermint(query string) string {
|
||||
return strings.TrimSpace(stdout)
|
||||
}
|
||||
|
||||
// ValidateGenesis runs kavad validate-genesis
|
||||
// ValidateGenesis runs 0gchaind validate-genesis
|
||||
func (f *Fixtures) ValidateGenesis() {
|
||||
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
||||
executeWriteCheckErr(f.T, cmd)
|
||||
|
@ -2,14 +2,14 @@
|
||||
swagger: "2.0"
|
||||
info:
|
||||
version: "3.0"
|
||||
title: Kava Light Client RPC
|
||||
title: 0g-chain Light Client RPC
|
||||
description: A REST interface for state queries, transaction generation and broadcasting.
|
||||
tags:
|
||||
- name: Vesting
|
||||
description: Validator vesting module APIs
|
||||
schemes:
|
||||
- https
|
||||
host: api.data.kava.io
|
||||
host: api.data.0g-chain.io
|
||||
securityDefinitions:
|
||||
kms:
|
||||
type: basic
|
||||
@ -17,14 +17,14 @@ paths:
|
||||
/vesting/circulatingsupply:
|
||||
get:
|
||||
deprecated: true
|
||||
summary: Get the current circulating supply of KAVA
|
||||
summary: Get the current circulating supply of 0g-chain
|
||||
tags:
|
||||
- Vesting
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
200:
|
||||
description: KAVA circulating supply
|
||||
description: 0g-chain circulating supply
|
||||
schema:
|
||||
properties:
|
||||
height:
|
||||
@ -38,14 +38,14 @@ paths:
|
||||
/vesting/totalsupply:
|
||||
get:
|
||||
deprecated: true
|
||||
summary: Get the total supply of KAVA
|
||||
summary: Get the total supply of 0g-chain
|
||||
tags:
|
||||
- Vesting
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
200:
|
||||
description: KAVA total supply
|
||||
description: 0g-chain total supply
|
||||
schema:
|
||||
properties:
|
||||
height:
|
||||
|
@ -7,29 +7,29 @@ import (
|
||||
"github.com/0glabs/0g-chain/client/grpc/util"
|
||||
)
|
||||
|
||||
// KavaGrpcClient enables the usage of kava grpc query clients and query utils
|
||||
type KavaGrpcClient struct {
|
||||
config KavaGrpcClientConfig
|
||||
// ZgChainGrpcClient enables the usage of 0gChain grpc query clients and query utils
|
||||
type ZgChainGrpcClient struct {
|
||||
config ZgChainGrpcClientConfig
|
||||
|
||||
// Query clients for cosmos and kava modules
|
||||
// Query clients for cosmos and 0gChain modules
|
||||
Query *query.QueryClient
|
||||
|
||||
// Utils for common queries (ie fetch an unpacked BaseAccount)
|
||||
*util.Util
|
||||
}
|
||||
|
||||
// KavaGrpcClientConfig is a configuration struct for a KavaGrpcClient
|
||||
type KavaGrpcClientConfig struct {
|
||||
// ZgChainGrpcClientConfig is a configuration struct for a ZgChainGrpcClient
|
||||
type ZgChainGrpcClientConfig struct {
|
||||
// note: add future config options here
|
||||
}
|
||||
|
||||
// NewClient creates a new KavaGrpcClient via a grpc url
|
||||
func NewClient(grpcUrl string) (*KavaGrpcClient, error) {
|
||||
// NewClient creates a new ZgChainGrpcClient via a grpc url
|
||||
func NewClient(grpcUrl string) (*ZgChainGrpcClient, error) {
|
||||
return NewClientWithConfig(grpcUrl, NewDefaultConfig())
|
||||
}
|
||||
|
||||
// NewClientWithConfig creates a new KavaGrpcClient via a grpc url and config
|
||||
func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpcClient, error) {
|
||||
// NewClientWithConfig creates a new ZgChainGrpcClient via a grpc url and config
|
||||
func NewClientWithConfig(grpcUrl string, config ZgChainGrpcClientConfig) (*ZgChainGrpcClient, error) {
|
||||
if grpcUrl == "" {
|
||||
return nil, errors.New("grpc url cannot be empty")
|
||||
}
|
||||
@ -37,7 +37,7 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
|
||||
if error != nil {
|
||||
return nil, error
|
||||
}
|
||||
client := &KavaGrpcClient{
|
||||
client := &ZgChainGrpcClient{
|
||||
Query: query,
|
||||
Util: util.NewUtil(query),
|
||||
config: config,
|
||||
@ -45,6 +45,6 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func NewDefaultConfig() KavaGrpcClientConfig {
|
||||
return KavaGrpcClientConfig{}
|
||||
func NewDefaultConfig() ZgChainGrpcClientConfig {
|
||||
return ZgChainGrpcClientConfig{}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
The query package includes Cosmos and Kava gRPC query clients.
|
||||
The query package includes Cosmos and 0gChain gRPC query clients.
|
||||
|
||||
To ensure that the `QueryClient` stays updated, add new module query clients
|
||||
to the `QueryClient` whenever new modules with grpc queries are added to the Kava app.
|
||||
to the `QueryClient` whenever new modules with grpc queries are added to the 0gChain app.
|
||||
*/
|
||||
package query
|
||||
|
@ -24,24 +24,12 @@ import (
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||
|
||||
// auctiontypes "github.com/0glabs/0g-chain/x/auction/types"
|
||||
// bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||
// cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
||||
// committeetypes "github.com/0glabs/0g-chain/x/committee/types"
|
||||
// communitytypes "github.com/0glabs/0g-chain/x/community/types"
|
||||
// earntypes "github.com/0glabs/0g-chain/x/earn/types"
|
||||
committeetypes "github.com/0glabs/0g-chain/x/committee/v1/types"
|
||||
dastypes "github.com/0glabs/0g-chain/x/das/v1/types"
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
// hardtypes "github.com/0glabs/0g-chain/x/hard/types"
|
||||
// incentivetypes "github.com/0glabs/0g-chain/x/incentive/types"
|
||||
// issuancetypes "github.com/0glabs/0g-chain/x/issuance/types"
|
||||
// kavadisttypes "github.com/0glabs/0g-chain/x/kavadist/types"
|
||||
// liquidtypes "github.com/0glabs/0g-chain/x/liquid/types"
|
||||
// pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||
// savingstypes "github.com/0glabs/0g-chain/x/savings/types"
|
||||
// swaptypes "github.com/0glabs/0g-chain/x/swap/types"
|
||||
)
|
||||
|
||||
// QueryClient is a wrapper with all Cosmos and Kava grpc query clients
|
||||
// QueryClient is a wrapper with all Cosmos and 0gChain grpc query clients
|
||||
type QueryClient struct {
|
||||
// cosmos-sdk query clients
|
||||
|
||||
@ -68,23 +56,11 @@ type QueryClient struct {
|
||||
IbcClient ibcclienttypes.QueryClient
|
||||
IbcTransfer ibctransfertypes.QueryClient
|
||||
|
||||
// kava module query clients
|
||||
// 0g-chain module query clients
|
||||
|
||||
// Auction auctiontypes.QueryClient
|
||||
// Bep3 bep3types.QueryClient
|
||||
// Cdp cdptypes.QueryClient
|
||||
// Committee committeetypes.QueryClient
|
||||
// Community communitytypes.QueryClient
|
||||
// Earn earntypes.QueryClient
|
||||
Evmutil evmutiltypes.QueryClient
|
||||
// Hard hardtypes.QueryClient
|
||||
// Incentive incentivetypes.QueryClient
|
||||
// Issuance issuancetypes.QueryClient
|
||||
// Kavadist kavadisttypes.QueryClient
|
||||
// Liquid liquidtypes.QueryClient
|
||||
// Pricefeed pricefeedtypes.QueryClient
|
||||
// Savings savingstypes.QueryClient
|
||||
// Swap swaptypes.QueryClient
|
||||
Committee committeetypes.QueryClient
|
||||
Das dastypes.QueryClient
|
||||
Evmutil evmutiltypes.QueryClient
|
||||
}
|
||||
|
||||
// NewQueryClient creates a new QueryClient and initializes all the module query clients
|
||||
@ -115,21 +91,9 @@ func NewQueryClient(grpcEndpoint string) (*QueryClient, error) {
|
||||
IbcClient: ibcclienttypes.NewQueryClient(conn),
|
||||
IbcTransfer: ibctransfertypes.NewQueryClient(conn),
|
||||
|
||||
// Auction: auctiontypes.NewQueryClient(conn),
|
||||
// Bep3: bep3types.NewQueryClient(conn),
|
||||
// Cdp: cdptypes.NewQueryClient(conn),
|
||||
// Committee: committeetypes.NewQueryClient(conn),
|
||||
// Community: communitytypes.NewQueryClient(conn),
|
||||
// Earn: earntypes.NewQueryClient(conn),
|
||||
Evmutil: evmutiltypes.NewQueryClient(conn),
|
||||
// Hard: hardtypes.NewQueryClient(conn),
|
||||
// Incentive: incentivetypes.NewQueryClient(conn),
|
||||
// Issuance: issuancetypes.NewQueryClient(conn),
|
||||
// Kavadist: kavadisttypes.NewQueryClient(conn),
|
||||
// Liquid: liquidtypes.NewQueryClient(conn),
|
||||
// Pricefeed: pricefeedtypes.NewQueryClient(conn),
|
||||
// Savings: savingstypes.NewQueryClient(conn),
|
||||
// Swap: swaptypes.NewQueryClient(conn),
|
||||
Committee: committeetypes.NewQueryClient(conn),
|
||||
Das: dastypes.NewQueryClient(conn),
|
||||
Evmutil: evmutiltypes.NewQueryClient(conn),
|
||||
}
|
||||
return client, nil
|
||||
}
|
||||
|
@ -54,21 +54,9 @@ func TestNewQueryClient_ValidClient(t *testing.T) {
|
||||
require.NotNil(t, client.IbcClient)
|
||||
require.NotNil(t, client.IbcTransfer)
|
||||
|
||||
// validate kava clients
|
||||
// require.NotNil(t, client.Auction)
|
||||
// require.NotNil(t, client.Bep3)
|
||||
// require.NotNil(t, client.Cdp)
|
||||
// require.NotNil(t, client.Committee)
|
||||
// require.NotNil(t, client.Community)
|
||||
// require.NotNil(t, client.Earn)
|
||||
// validate 0gChain clients
|
||||
require.NotNil(t, client.Evmutil)
|
||||
// require.NotNil(t, client.Hard)
|
||||
// require.NotNil(t, client.Incentive)
|
||||
// require.NotNil(t, client.Issuance)
|
||||
// require.NotNil(t, client.Kavadist)
|
||||
// require.NotNil(t, client.Liquid)
|
||||
// require.NotNil(t, client.Pricefeed)
|
||||
// require.NotNil(t, client.Savings)
|
||||
// require.NotNil(t, client.Swap)
|
||||
require.NotNil(t, client.Committee)
|
||||
require.NotNil(t, client.Das)
|
||||
})
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
The util package contains utility functions for the Kava gRPC client.
|
||||
The util package contains utility functions for the 0gChain gRPC client.
|
||||
|
||||
For example, `account.go` includes account-related query helpers.
|
||||
In this file, utilities such as `client.Util.BaseAccount(addr)` is exposed to
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
query "github.com/0glabs/0g-chain/client/grpc/query"
|
||||
)
|
||||
|
||||
// Util contains utility functions for the Kava gRPC client
|
||||
// Util contains utility functions for the 0gChain gRPC client
|
||||
type Util struct {
|
||||
query *query.QueryClient
|
||||
encodingConfig params.EncodingConfig
|
||||
|
@ -33,7 +33,7 @@ const (
|
||||
flagSkipLoadLatest = "skip-load-latest"
|
||||
)
|
||||
|
||||
// appCreator holds functions used by the sdk server to control the kava app.
|
||||
// appCreator holds functions used by the sdk server to control the 0g-chain app.
|
||||
// The methods implement types in cosmos-sdk/server/types
|
||||
type appCreator struct {
|
||||
encodingConfig params.EncodingConfig
|
||||
|
@ -39,7 +39,7 @@ func newShardCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "shard --home <path-to-home-dir> --start <start-block> --end <end-block> [--only-app-state] [--only-cometbft-state] [--force-app-version <app-version>]",
|
||||
Short: "Strip all blocks from the database outside of a given range",
|
||||
Long: `shard opens a local kava home directory's databases and removes all blocks outside a range defined by --start and --end. The range is inclusive of the end block.
|
||||
Long: `shard opens a local 0g-chainhome directory's databases and removes all blocks outside a range defined by --start and --end. The range is inclusive of the end block.
|
||||
|
||||
It works by first rolling back the latest state to the block before the end block, and then by pruning all state before the start block.
|
||||
|
||||
@ -54,14 +54,14 @@ Similarly, the --only-cometbft-state flag skips pruning app state. This can be u
|
||||
The shard command only flags the iavl tree nodes for deletion. Actual removal from the databases will be performed when each database is compacted.
|
||||
|
||||
WARNING: this is a destructive action.`,
|
||||
Example: `Create a 1M block data shard (keeps blocks kava 1,000,000 to 2,000,000)
|
||||
$ kava shard --home path/to/.kava --start 1000000 --end 2000000
|
||||
Example: `Create a 1M block data shard (keeps blocks a0gi 1,000,000 to 2,000,000)
|
||||
$ 0gchaind shard --home path/to/.0gchain --start 1000000 --end 2000000
|
||||
|
||||
Prune all blocks up to 5,000,000:
|
||||
$ kava shard --home path/to/.kava --start 5000000 --end -1
|
||||
$ 0gchaind shard --home path/to/.0gchain --start 5000000 --end -1
|
||||
|
||||
Prune first 1M blocks _without_ affecting blockstore or cometBFT state:
|
||||
$ kava shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||
$ 0gchaind shard --home path/to/.0gchain --start 1000000 --end -1 --only-app-state`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
//////////////////////////
|
||||
// parse & validate flags
|
||||
|
@ -1,7 +1,7 @@
|
||||
//go:build rocksdb
|
||||
// +build rocksdb
|
||||
|
||||
// Copyright 2023 Kava Labs, Inc.
|
||||
// Copyright 2024 0glabs Labs, Inc.
|
||||
// Copyright 2023 Cronos Labs, Inc.
|
||||
//
|
||||
// Derived from https://github.com/crypto-org-chain/cronos@496ce7e
|
||||
|
@ -4,11 +4,11 @@ pragma solidity ^0.8.18;
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
|
||||
/// @title An ERC20 token contract owned and deployed by the evmutil module of Kava.
|
||||
/// @title An ERC20 token contract owned and deployed by the evmutil module of 0g-chain.
|
||||
/// Tokens are backed one-for-one by cosmos-sdk coins held in the module account.
|
||||
/// @author Kava Labs, LLC
|
||||
/// @custom:security-contact security@kava.io
|
||||
contract ERC20KavaWrappedCosmosCoin is ERC20, Ownable {
|
||||
/// @author 0g Labs, LLC
|
||||
/// @custom:security-contact security@0g.ai
|
||||
contract ERC200gChainWrappedCosmosCoin is ERC20, Ownable {
|
||||
/// @notice The decimals places of the token. For display purposes only.
|
||||
uint8 private immutable _decimals;
|
||||
|
||||
|
@ -5,7 +5,7 @@ const config: HardhatUserConfig = {
|
||||
solidity: {
|
||||
version: "0.8.18",
|
||||
settings: {
|
||||
// istanbul upgrade occurred before the london hardfork, so is compatible with kava's evm
|
||||
// istanbul upgrade occurred before the london hardfork, so is compatible with 0g-chain's evm
|
||||
evmVersion: "istanbul",
|
||||
// optimize build for deployment to mainnet!
|
||||
optimizer: {
|
||||
@ -16,21 +16,21 @@ const config: HardhatUserConfig = {
|
||||
},
|
||||
networks: {
|
||||
// kvtool's local network
|
||||
kava: {
|
||||
chain: {
|
||||
url: "http://127.0.0.1:8545",
|
||||
accounts: [
|
||||
// kava keys unsafe-export-eth-key whale2
|
||||
// 0g-chain keys unsafe-export-eth-key whale2
|
||||
"AA50F4C6C15190D9E18BF8B14FC09BFBA0E7306331A4F232D10A77C2879E7966",
|
||||
],
|
||||
},
|
||||
protonet: {
|
||||
url: "https://evm.app.protonet.us-east.production.kava.io:443",
|
||||
url: "https://evm.app.protonet.us-east.production.0g-chain.io:443",
|
||||
accounts: [
|
||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||
],
|
||||
},
|
||||
internal_testnet: {
|
||||
url: "https://evm.data.internal.testnet.us-east.production.kava.io:443",
|
||||
url: "https://evm.data.internal.testnet.us-east.production.0g-chain.io:443",
|
||||
accounts: [
|
||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||
],
|
||||
|
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",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kava-contracts",
|
||||
"name": "0g-chain-contracts",
|
||||
"version": "0.0.1",
|
||||
"devDependencies": {
|
||||
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "kava-contracts",
|
||||
"name": "0g-chain-contracts",
|
||||
"version": "0.0.1",
|
||||
"author": "Kava Labs",
|
||||
"author": "0g Labs",
|
||||
"private": true,
|
||||
"description": "Solidity contracts for Kava Blockchain",
|
||||
"description": "Solidity contracts for 0g Blockchain",
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
@ -12,7 +12,7 @@
|
||||
"clean": "hardhat clean",
|
||||
"compile": "hardhat compile",
|
||||
"coverage": "hardhat coverage",
|
||||
"ethermint-json": "jq '{ abi: .abi | tostring, bin: .bytecode | ltrimstr(\"0x\")}' artifacts/contracts/ERC20KavaWrappedCosmosCoin.sol/ERC20KavaWrappedCosmosCoin.json > ../x/evmutil/types/ethermint_json/ERC20KavaWrappedCosmosCoin.json",
|
||||
"ethermint-json": "jq '{ abi: .abi | tostring, bin: .bytecode | ltrimstr(\"0x\")}' artifacts/contracts/ERC200gChainWrappedCosmosCoin.sol/ERC200gChainWrappedCosmosCoin.json > ../x/evmutil/types/ethermint_json/ERC200gChainWrappedCosmosCoin.json",
|
||||
"gen-ts-types": "hardhat typechain",
|
||||
"lint": "eslint '**/*.{js,ts}'",
|
||||
"lint-fix": "eslint '**/*.{js,ts}' --fix",
|
||||
|
@ -1,14 +1,14 @@
|
||||
import { ethers } from "hardhat";
|
||||
|
||||
async function main() {
|
||||
const tokenName = "Kava-wrapped ATOM";
|
||||
const tokenName = "0g-chain-wrapped ATOM";
|
||||
const tokenSymbol = "kATOM";
|
||||
const tokenDecimals = 6;
|
||||
|
||||
const ERC20KavaWrappedCosmosCoin = await ethers.getContractFactory(
|
||||
"ERC20KavaWrappedCosmosCoin"
|
||||
const ERC200gChainWrappedCosmosCoin = await ethers.getContractFactory(
|
||||
"ERC200gChainWrappedCosmosCoin"
|
||||
);
|
||||
const token = await ERC20KavaWrappedCosmosCoin.deploy(
|
||||
const token = await ERC200gChainWrappedCosmosCoin.deploy(
|
||||
tokenName,
|
||||
tokenSymbol,
|
||||
tokenDecimals
|
||||
|
@ -2,21 +2,21 @@ import { expect } from "chai";
|
||||
import { Signer } from "ethers";
|
||||
import { ethers } from "hardhat";
|
||||
import {
|
||||
ERC20KavaWrappedCosmosCoin,
|
||||
ERC20KavaWrappedCosmosCoin__factory as ERC20KavaWrappedCosmosCoinFactory,
|
||||
ERC200gChainWrappedCosmosCoin,
|
||||
ERC200gChainWrappedCosmosCoin__factory as ERC200gChainWrappedCosmosCoinFactory,
|
||||
} from "../typechain-types";
|
||||
|
||||
const decimals = 6n;
|
||||
|
||||
describe("ERC20KavaWrappedCosmosCoin", function () {
|
||||
let erc20: ERC20KavaWrappedCosmosCoin;
|
||||
let erc20Factory: ERC20KavaWrappedCosmosCoinFactory;
|
||||
describe("ERC200gChainWrappedCosmosCoin", function () {
|
||||
let erc20: ERC200gChainWrappedCosmosCoin;
|
||||
let erc20Factory: ERC200gChainWrappedCosmosCoinFactory;
|
||||
let owner: Signer;
|
||||
let sender: Signer;
|
||||
|
||||
beforeEach(async function () {
|
||||
erc20Factory = await ethers.getContractFactory(
|
||||
"ERC20KavaWrappedCosmosCoin"
|
||||
"ERC200gChainWrappedCosmosCoin"
|
||||
);
|
||||
erc20 = await erc20Factory.deploy("Wrapped ATOM", "ATOM", decimals);
|
||||
[owner, sender] = await ethers.getSigners();
|
||||
|
@ -3,7 +3,7 @@ version: '3'
|
||||
services:
|
||||
kvdnode0:
|
||||
container_name: kvdnode0
|
||||
image: "kava/kavanode"
|
||||
image: "0glabs/0g-chain-node"
|
||||
ports:
|
||||
- "26656-26657:26656-26657"
|
||||
environment:
|
||||
@ -17,7 +17,7 @@ services:
|
||||
|
||||
kvdnode1:
|
||||
container_name: kvdnode1
|
||||
image: "kava/kavanode"
|
||||
image: "0glabs/0g-chain-node"
|
||||
ports:
|
||||
- "26659-26660:26656-26657"
|
||||
environment:
|
||||
@ -31,7 +31,7 @@ services:
|
||||
|
||||
kvdnode2:
|
||||
container_name: kvdnode2
|
||||
image: "kava/kavanode"
|
||||
image: "0glabs/0g-chain-node"
|
||||
environment:
|
||||
- ID=2
|
||||
- LOG=${LOG:-kvd.log}
|
||||
@ -45,7 +45,7 @@ services:
|
||||
|
||||
kvdnode3:
|
||||
container_name: kvdnode3
|
||||
image: "kava/kavanode"
|
||||
image: "0glabs/0g-chain-node"
|
||||
environment:
|
||||
- ID=3
|
||||
- LOG=${LOG:-kvd.log}
|
||||
|
@ -11,8 +11,8 @@ There are two types of migration:
|
||||
Genesis migration starts a whole new blockchain (with new chain-id) for the new software version.
|
||||
In-Place upgrade keeps the blockchain (and chain-id) the same for the new software version.
|
||||
|
||||
We only support migrations between mainnet kava releases.
|
||||
We only support migrations from the previous mainnet kava version to the current. We don't support migrating between two old versions, use the old software version for this.
|
||||
We only support migrations between mainnet 0g-chain releases.
|
||||
We only support migrations from the previous mainnet 0g-chain version to the current. We don't support migrating between two old versions, use the old software version for this.
|
||||
We only support migrations from old to new versions, not the other way around.
|
||||
|
||||
Genesis Migration
|
||||
@ -22,7 +22,7 @@ The process is:
|
||||
- marshal it to json (using current codec)
|
||||
|
||||
On each release we can delete the previous releases migration and old GenesisState type.
|
||||
eg kava-3 migrates `auth.GenesisState` from kava-2 to `auth.GenesisState` from kava-3,
|
||||
but for kava-4 we don't need to keep around kava-2's `auth.GenesisState` type.
|
||||
eg 0g-chain-3 migrates `auth.GenesisState` from 0g-chain-2 to `auth.GenesisState` from 0g-chain-3,
|
||||
but for 0g-chain-4 we don't need to keep around 0g-chain-2's `auth.GenesisState` type.
|
||||
*/
|
||||
package migrate
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
@ -41,7 +42,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -64,7 +65,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -97,7 +98,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
@ -125,25 +126,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(4e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(4e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +30 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -159,36 +160,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||
expectedPeriods := []vestingtypes.Period{
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
{
|
||||
Length: 15 * 24 * 60 * 60, // 15 days
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||
assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated")
|
||||
assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period")
|
||||
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(3e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
@ -198,35 +199,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||
}
|
||||
|
||||
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
|
||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(3e6)))
|
||||
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3e6)))
|
||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||
|
||||
periods := vestingtypes.Periods{
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
vestingtypes.Period{
|
||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
||||
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||
},
|
||||
}
|
||||
|
||||
vacc := createVestingAccount(balance, vestingStartTime, periods)
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))))
|
||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))))
|
||||
|
||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||
|
||||
assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
all:
|
||||
docker build --tag kava/kavanode kavanode
|
||||
docker build --tag 0glabs/0g-chain-node 0g-chain-node
|
||||
|
||||
.PHONY: all
|
||||
|
@ -10,29 +10,29 @@ import (
|
||||
|
||||
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_NonAuthority() {
|
||||
// // ARRANGE
|
||||
// // setup kava account
|
||||
// funds := ukava(1e5) // .1 KAVA
|
||||
// kavaAcc := suite.Kava.NewFundedAccount("community-non-authority", sdk.NewCoins(funds))
|
||||
// // setup 0g account
|
||||
// funds := a0gi(1e5) // .1 A0GI
|
||||
// zgChainAcc := suite.ZgChain.NewFundedAccount("community-non-authority", sdk.NewCoins(funds))
|
||||
|
||||
// gasLimit := int64(2e5)
|
||||
// fee := ukava(200)
|
||||
// fee := a0gi(200)
|
||||
|
||||
// msg := communitytypes.NewMsgUpdateParams(
|
||||
// kavaAcc.SdkAddress,
|
||||
// zgChainAcc.SdkAddress,
|
||||
// communitytypes.DefaultParams(),
|
||||
// )
|
||||
|
||||
// // ACT
|
||||
// req := util.KavaMsgRequest{
|
||||
// req := util.ZgChainMsgRequest{
|
||||
// Msgs: []sdk.Msg{&msg},
|
||||
// GasLimit: uint64(gasLimit),
|
||||
// FeeAmount: sdk.NewCoins(fee),
|
||||
// Memo: "this is a failure!",
|
||||
// }
|
||||
// res := kavaAcc.SignAndBroadcastKavaTx(req)
|
||||
// res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||
|
||||
// // ASSERT
|
||||
// _, err := util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||
// _, err := util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||
// suite.Require().Error(err)
|
||||
// suite.Require().ErrorContains(
|
||||
// err,
|
||||
@ -43,32 +43,32 @@ import (
|
||||
|
||||
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_Authority() {
|
||||
// // ARRANGE
|
||||
// govParamsRes, err := suite.Kava.Grpc.Query.Gov.Params(context.Background(), &govv1.QueryParamsRequest{
|
||||
// govParamsRes, err := suite.ZgChain.Grpc.Query.Gov.Params(context.Background(), &govv1.QueryParamsRequest{
|
||||
// ParamsType: govv1.ParamDeposit,
|
||||
// })
|
||||
// suite.NoError(err)
|
||||
|
||||
// // Check initial params
|
||||
// communityParamsResInitial, err := suite.Kava.Grpc.Query.Community.Params(
|
||||
// communityParamsResInitial, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||
// context.Background(),
|
||||
// &communitytypes.QueryParamsRequest{},
|
||||
// )
|
||||
// suite.Require().NoError(err)
|
||||
|
||||
// // setup kava account
|
||||
// // .1 KAVA + min deposit amount for proposal
|
||||
// funds := sdk.NewCoins(ukava(1e5)).Add(govParamsRes.DepositParams.MinDeposit...)
|
||||
// kavaAcc := suite.Kava.NewFundedAccount("community-update-params", funds)
|
||||
// // setup 0g account
|
||||
// // .1 A0GI + min deposit amount for proposal
|
||||
// funds := sdk.NewCoins(a0gi(1e5)).Add(govParamsRes.DepositParams.MinDeposit...)
|
||||
// zgChainAcc := suite.ZgChain.NewFundedAccount("community-update-params", funds)
|
||||
|
||||
// gasLimit := int64(2e5)
|
||||
// fee := ukava(200)
|
||||
// fee := a0gi(200)
|
||||
|
||||
// // Wait until switchover actually happens - When testing without the upgrade
|
||||
// // handler that sets a relative switchover time, the switchover time in
|
||||
// // genesis should be set in the past so it runs immediately.
|
||||
// suite.Require().Eventually(
|
||||
// func() bool {
|
||||
// params, err := suite.Kava.Grpc.Query.Community.Params(
|
||||
// params, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||
// context.Background(),
|
||||
// &communitytypes.QueryParamsRequest{},
|
||||
// )
|
||||
@ -108,24 +108,24 @@ import (
|
||||
// proposalMsg, err := govv1.NewMsgSubmitProposal(
|
||||
// []sdk.Msg{&updateParamsMsg},
|
||||
// govParamsRes.Params.MinDeposit,
|
||||
// kavaAcc.SdkAddress.String(),
|
||||
// zgChainAcc.SdkAddress.String(),
|
||||
// "community-update-params",
|
||||
// "title",
|
||||
// "summary",
|
||||
// )
|
||||
// suite.NoError(err)
|
||||
|
||||
// req := util.KavaMsgRequest{
|
||||
// req := util.ZgChainMsgRequest{
|
||||
// Msgs: []sdk.Msg{proposalMsg},
|
||||
// GasLimit: uint64(gasLimit),
|
||||
// FeeAmount: sdk.NewCoins(fee),
|
||||
// Memo: "this is a proposal please accept me",
|
||||
// }
|
||||
// res := kavaAcc.SignAndBroadcastKavaTx(req)
|
||||
// res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||
// suite.Require().NoError(res.Err)
|
||||
|
||||
// // Wait for proposal to be submitted
|
||||
// txRes, err := util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||
// txRes, err := util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.Result.TxHash, 6*time.Second)
|
||||
// suite.Require().NoError(err)
|
||||
|
||||
// // Parse tx response to get proposal id
|
||||
@ -133,7 +133,7 @@ import (
|
||||
// suite.decodeTxMsgResponse(txRes, &govRes)
|
||||
|
||||
// // 2. Vote for proposal from whale account
|
||||
// whale := suite.Kava.GetAccount(testutil.FundedAccountName)
|
||||
// whale := suite.ZgChain.GetAccount(testutil.FundedAccountName)
|
||||
// voteMsg := govv1.NewMsgVote(
|
||||
// whale.SdkAddress,
|
||||
// govRes.ProposalId,
|
||||
@ -141,21 +141,21 @@ import (
|
||||
// "",
|
||||
// )
|
||||
|
||||
// voteReq := util.KavaMsgRequest{
|
||||
// voteReq := util.ZgChainMsgRequest{
|
||||
// Msgs: []sdk.Msg{voteMsg},
|
||||
// GasLimit: uint64(gasLimit),
|
||||
// FeeAmount: sdk.NewCoins(fee),
|
||||
// Memo: "voting",
|
||||
// }
|
||||
// voteRes := whale.SignAndBroadcastKavaTx(voteReq)
|
||||
// voteRes := whale.SignAndBroadcastZgChainTx(voteReq)
|
||||
// suite.Require().NoError(voteRes.Err)
|
||||
|
||||
// _, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, voteRes.Result.TxHash, 6*time.Second)
|
||||
// _, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, voteRes.Result.TxHash, 6*time.Second)
|
||||
// suite.Require().NoError(err)
|
||||
|
||||
// // 3. Wait until proposal passes
|
||||
// suite.Require().Eventually(func() bool {
|
||||
// proposalRes, err := suite.Kava.Grpc.Query.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
||||
// proposalRes, err := suite.ZgChain.Grpc.Query.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
||||
// ProposalId: govRes.ProposalId,
|
||||
// })
|
||||
// suite.NoError(err)
|
||||
@ -164,7 +164,7 @@ import (
|
||||
// }, 60*time.Second, 1*time.Second)
|
||||
|
||||
// // Check parameters are updated
|
||||
// communityParamsRes, err := suite.Kava.Grpc.Query.Community.Params(
|
||||
// communityParamsRes, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||
// context.Background(),
|
||||
// &communitytypes.QueryParamsRequest{},
|
||||
// )
|
||||
@ -180,10 +180,10 @@ func (suite *IntegrationTestSuite) decodeTxMsgResponse(txRes *sdk.TxResponse, pt
|
||||
|
||||
// Unmarshal data to TxMsgData
|
||||
var txMsgData sdk.TxMsgData
|
||||
suite.Kava.EncodingConfig.Marshaler.MustUnmarshal(txResBytes, &txMsgData)
|
||||
suite.ZgChain.EncodingConfig.Marshaler.MustUnmarshal(txResBytes, &txMsgData)
|
||||
suite.T().Logf("txData.MsgResponses: %v", txMsgData.MsgResponses)
|
||||
|
||||
// Parse MsgResponse
|
||||
suite.Kava.EncodingConfig.Marshaler.MustUnmarshal(txMsgData.MsgResponses[0].Value, ptr)
|
||||
suite.ZgChain.EncodingConfig.Marshaler.MustUnmarshal(txMsgData.MsgResponses[0].Value, ptr)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
@ -24,24 +24,24 @@ func setupConvertToCoinTest(
|
||||
) (denom string, initialFunds sdk.Coins, user *testutil.SigningAccount) {
|
||||
// we expect a denom to be registered to the allowed denoms param
|
||||
// and for the funded account to have a balance for that denom
|
||||
params, err := suite.Kava.Grpc.Query.Evmutil.Params(
|
||||
params, err := suite.ZgChain.Grpc.Query.Evmutil.Params(
|
||||
context.Background(),
|
||||
&evmutiltypes.QueryParamsRequest{},
|
||||
)
|
||||
suite.NoError(err)
|
||||
suite.GreaterOrEqual(
|
||||
len(params.Params.AllowedCosmosDenoms), 1,
|
||||
"kava chain expected to have at least one AllowedCosmosDenom for ERC20 conversion",
|
||||
"0g-chain expected to have at least one AllowedCosmosDenom for ERC20 conversion",
|
||||
)
|
||||
|
||||
tokenInfo := params.Params.AllowedCosmosDenoms[0]
|
||||
denom = tokenInfo.CosmosDenom
|
||||
initialFunds = sdk.NewCoins(
|
||||
sdk.NewInt64Coin(suite.Kava.StakingDenom, 1e5), // gas money
|
||||
sdk.NewInt64Coin(suite.ZgChain.StakingDenom, 1e5), // gas money
|
||||
sdk.NewInt64Coin(denom, initialCosmosCoinConversionDenomFunds), // conversion-enabled cosmos coin
|
||||
)
|
||||
|
||||
user = suite.Kava.NewFundedAccount(accountName, initialFunds)
|
||||
user = suite.ZgChain.NewFundedAccount(accountName, initialFunds)
|
||||
|
||||
return denom, initialFunds, user
|
||||
}
|
||||
@ -63,20 +63,20 @@ func (suite *IntegrationTestSuite) setupAccountWithCosmosCoinERC20Balance(
|
||||
user.EvmAddress.Hex(),
|
||||
convertAmount,
|
||||
)
|
||||
tx := util.KavaMsgRequest{
|
||||
tx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&msg},
|
||||
GasLimit: 4e5,
|
||||
FeeAmount: sdk.NewCoins(ukava(400)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(400))),
|
||||
Data: "converting sdk coin to erc20",
|
||||
}
|
||||
res := user.SignAndBroadcastKavaTx(tx)
|
||||
res := user.SignAndBroadcastZgChainTx(tx)
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// adjust sdk balance
|
||||
sdkBalance = sdkBalance.Sub(convertAmount)
|
||||
|
||||
// query for the deployed contract
|
||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
context.Background(),
|
||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||
)
|
||||
@ -92,7 +92,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter")
|
||||
|
||||
convertAmount := int64(5e3)
|
||||
initialModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
initialModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
|
||||
///////////////////////////////
|
||||
// CONVERT COSMOS COIN -> ERC20
|
||||
@ -102,17 +102,17 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
user.EvmAddress.Hex(),
|
||||
sdk.NewInt64Coin(denom, convertAmount),
|
||||
)
|
||||
tx := util.KavaMsgRequest{
|
||||
tx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertToErc20Msg},
|
||||
GasLimit: 2e6,
|
||||
FeeAmount: sdk.NewCoins(ukava(2000)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(2000))),
|
||||
Data: "converting sdk coin to erc20",
|
||||
}
|
||||
res := user.SignAndBroadcastKavaTx(tx)
|
||||
res := user.SignAndBroadcastZgChainTx(tx)
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// query for the deployed contract
|
||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
context.Background(),
|
||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||
)
|
||||
@ -122,17 +122,17 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
||||
|
||||
// check erc20 balance
|
||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
||||
|
||||
// check cosmos coin is deducted from account
|
||||
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
||||
balance := suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
balance := suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(expectedFunds, balance)
|
||||
|
||||
// check that module account has sdk coins
|
||||
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
||||
actualModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
actualModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
||||
|
||||
///////////////////////////////
|
||||
@ -144,26 +144,26 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
||||
sdk.NewInt64Coin(denom, convertAmount),
|
||||
)
|
||||
|
||||
tx = util.KavaMsgRequest{
|
||||
tx = util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertFromErc20Msg},
|
||||
GasLimit: 2e5,
|
||||
FeeAmount: sdk.NewCoins(ukava(200)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||
Data: "converting erc20 to cosmos coin",
|
||||
}
|
||||
res = user.SignAndBroadcastKavaTx(tx)
|
||||
res = user.SignAndBroadcastZgChainTx(tx)
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// check erc20 balance
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
||||
|
||||
// check cosmos coin is added back to account
|
||||
expectedFunds = initialFunds.AmountOf(denom)
|
||||
balance = suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
balance = suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(expectedFunds, balance)
|
||||
|
||||
// check that module account has sdk coins deducted
|
||||
actualModuleBalance = suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
actualModuleBalance = suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
suite.Equal(initialModuleBalance, actualModuleBalance)
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter-eip712")
|
||||
|
||||
convertAmount := int64(5e3)
|
||||
initialModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
initialModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
|
||||
///////////////////////////////
|
||||
// CONVERT COSMOS COIN -> ERC20
|
||||
@ -184,28 +184,28 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
)
|
||||
tx := suite.NewEip712TxBuilder(
|
||||
user,
|
||||
suite.Kava,
|
||||
suite.ZgChain,
|
||||
2e6,
|
||||
sdk.NewCoins(ukava(1e4)),
|
||||
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||
[]sdk.Msg{&convertToErc20Msg},
|
||||
"this is a memo",
|
||||
).GetTx()
|
||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
suite.NoError(err)
|
||||
|
||||
// submit the eip712 message to the chain.
|
||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
TxBytes: txBytes,
|
||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 12*time.Second)
|
||||
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 12*time.Second)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
// query for the deployed contract
|
||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||
context.Background(),
|
||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||
)
|
||||
@ -215,17 +215,17 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
||||
|
||||
// check erc20 balance
|
||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
||||
|
||||
// check cosmos coin is deducted from account
|
||||
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
||||
balance := suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
balance := suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(expectedFunds, balance)
|
||||
|
||||
// check that module account has sdk coins
|
||||
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
||||
actualModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
actualModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
||||
|
||||
///////////////////////////////
|
||||
@ -238,37 +238,37 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
||||
)
|
||||
tx = suite.NewEip712TxBuilder(
|
||||
user,
|
||||
suite.Kava,
|
||||
suite.ZgChain,
|
||||
2e5,
|
||||
sdk.NewCoins(ukava(200)),
|
||||
sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||
[]sdk.Msg{&convertFromErc20Msg},
|
||||
"",
|
||||
).GetTx()
|
||||
txBytes, err = suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
txBytes, err = suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
suite.NoError(err)
|
||||
|
||||
// submit the eip712 message to the chain
|
||||
res, err = suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
res, err = suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
TxBytes: txBytes,
|
||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
suite.NoError(err)
|
||||
|
||||
// check erc20 balance
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
||||
|
||||
// check cosmos coin is added back to account
|
||||
expectedFunds = initialFunds.AmountOf(denom)
|
||||
balance = suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
balance = suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(expectedFunds, balance)
|
||||
|
||||
// check that module account has sdk coins deducted
|
||||
actualModuleBalance = suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
actualModuleBalance = suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||
suite.Equal(initialModuleBalance, actualModuleBalance)
|
||||
}
|
||||
|
||||
@ -334,8 +334,8 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
"cosmo-coin-converter-complex-alice", initialAliceAmount,
|
||||
)
|
||||
|
||||
gasMoney := sdk.NewCoins(ukava(1e5))
|
||||
bob := suite.Kava.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
||||
gasMoney := sdk.NewCoins(a0gi(big.NewInt(1e5)))
|
||||
bob := suite.ZgChain.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
||||
amount := big.NewInt(1e3) // test assumes this is half of alice's balance.
|
||||
|
||||
// bob can't move alice's funds
|
||||
@ -400,10 +400,10 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
suite.Require().NoError(res.Err)
|
||||
|
||||
// alice should have amount deducted
|
||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(initialAliceAmount-amount.Int64()), erc20Balance, "alice has unexpected erc20 balance")
|
||||
// bob should have amount added
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||
suite.BigIntsEqual(amount, erc20Balance, "bob has unexpected erc20 balance")
|
||||
|
||||
// convert bob's new funds back to an sdk.Coin
|
||||
@ -412,24 +412,24 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
bob.SdkAddress.String(),
|
||||
sdk.NewInt64Coin(denom, amount.Int64()),
|
||||
)
|
||||
convertTx := util.KavaMsgRequest{
|
||||
convertTx := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{&convertMsg},
|
||||
GasLimit: 2e5,
|
||||
FeeAmount: sdk.NewCoins(ukava(200)),
|
||||
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||
Data: "bob converts his new erc20 to an sdk.Coin",
|
||||
}
|
||||
convertRes := bob.SignAndBroadcastKavaTx(convertTx)
|
||||
convertRes := bob.SignAndBroadcastZgChainTx(convertTx)
|
||||
suite.NoError(convertRes.Err)
|
||||
|
||||
// bob should have no more erc20 balance
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected no erc20 balance for bob")
|
||||
// bob should have sdk balance
|
||||
balance := suite.Kava.QuerySdkForBalances(bob.SdkAddress).AmountOf(denom)
|
||||
balance := suite.ZgChain.QuerySdkForBalances(bob.SdkAddress).AmountOf(denom)
|
||||
suite.Equal(sdk.NewIntFromBigInt(amount), balance)
|
||||
|
||||
// alice should have the remaining balance
|
||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||
suite.BigIntsEqual(amount, erc20Balance, "expected alice to have half initial funds remaining")
|
||||
|
||||
// convert alice's remaining balance back to sdk coins
|
||||
@ -438,6 +438,6 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
||||
alice.SdkAddress.String(),
|
||||
sdk.NewInt64Coin(denom, amount.Int64()),
|
||||
)
|
||||
convertRes = alice.SignAndBroadcastKavaTx(convertTx)
|
||||
convertRes = alice.SignAndBroadcastZgChainTx(convertTx)
|
||||
suite.NoError(convertRes.Err)
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import (
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
|
||||
// cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
||||
// evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
|
||||
@ -22,10 +24,10 @@ func (suite *IntegrationTestSuite) TestEthCallToGreeterContract() {
|
||||
// this test manipulates state of the Greeter contract which means other tests shouldn't use it.
|
||||
|
||||
// setup funded account to interact with contract
|
||||
user := suite.Kava.NewFundedAccount("greeter-contract-user", sdk.NewCoins(ukava(1e6)))
|
||||
user := suite.ZgChain.NewFundedAccount("greeter-contract-user", sdk.NewCoins(a0gi(big.NewInt(1e6))))
|
||||
|
||||
greeterAddr := suite.Kava.ContractAddrs["greeter"]
|
||||
contract, err := greeter.NewGreeter(greeterAddr, suite.Kava.EvmClient)
|
||||
greeterAddr := suite.ZgChain.ContractAddrs["greeter"]
|
||||
contract, err := greeter.NewGreeter(greeterAddr, suite.ZgChain.EvmClient)
|
||||
suite.NoError(err)
|
||||
|
||||
beforeGreeting, err := contract.Greet(nil)
|
||||
@ -35,7 +37,7 @@ func (suite *IntegrationTestSuite) TestEthCallToGreeterContract() {
|
||||
tx, err := contract.SetGreeting(user.EvmAuth, updatedGreeting)
|
||||
suite.NoError(err)
|
||||
|
||||
_, err = util.WaitForEvmTxReceipt(suite.Kava.EvmClient, tx.Hash(), 10*time.Second)
|
||||
_, err = util.WaitForEvmTxReceipt(suite.ZgChain.EvmClient, tx.Hash(), 10*time.Second)
|
||||
suite.NoError(err)
|
||||
|
||||
afterGreeting, err := contract.Greet(nil)
|
||||
@ -50,14 +52,14 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
||||
amount := big.NewInt(1)
|
||||
|
||||
// make unauthenticated eth_call query to check balance
|
||||
beforeBalance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||
beforeBalance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||
|
||||
// make authenticate eth_call to transfer tokens
|
||||
res := suite.FundKavaErc20Balance(randoReceiver, amount)
|
||||
res := suite.FundZgChainErc20Balance(randoReceiver, amount)
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// make another unauthenticated eth_call query to check new balance
|
||||
afterBalance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||
afterBalance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||
|
||||
suite.BigIntsEqual(big.NewInt(0), beforeBalance, "expected before balance to be zero")
|
||||
suite.BigIntsEqual(amount, afterBalance, "unexpected post-transfer balance")
|
||||
@ -65,42 +67,42 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
||||
|
||||
func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// create new funded account
|
||||
sender := suite.Kava.NewFundedAccount("eip712-msgSend", sdk.NewCoins(ukava(2e4)))
|
||||
sender := suite.ZgChain.NewFundedAccount("eip712-msgSend", sdk.NewCoins(a0gi(big.NewInt(2e4))))
|
||||
receiver := app.RandomAddress()
|
||||
|
||||
// setup message for sending some kava to random receiver
|
||||
// setup message for sending some a0gi to random receiver
|
||||
msgs := []sdk.Msg{
|
||||
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(ukava(1e3))),
|
||||
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(a0gi(big.NewInt(1e3)))),
|
||||
}
|
||||
|
||||
// create tx
|
||||
tx := suite.NewEip712TxBuilder(
|
||||
sender,
|
||||
suite.Kava,
|
||||
suite.ZgChain,
|
||||
1e6,
|
||||
sdk.NewCoins(ukava(1e4)),
|
||||
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||
msgs,
|
||||
"this is a memo",
|
||||
).GetTx()
|
||||
|
||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
suite.NoError(err)
|
||||
|
||||
// broadcast tx
|
||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
TxBytes: txBytes,
|
||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
suite.NoError(err)
|
||||
|
||||
// check that the message was processed & the kava is transferred.
|
||||
balRes, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
// check that the message was processed & the a0gi is transferred.
|
||||
balRes, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
Address: receiver.String(),
|
||||
Denom: "ukava",
|
||||
Denom: chaincfg.DisplayDenom,
|
||||
})
|
||||
suite.NoError(err)
|
||||
suite.Equal(sdk.NewInt(1e3), balRes.Balance.Amount)
|
||||
@ -115,9 +117,9 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// sdkDenom := suite.DeployedErc20.CosmosDenom
|
||||
|
||||
// // create new funded account
|
||||
// depositor := suite.Kava.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(ukava(1e5)))
|
||||
// depositor := suite.ZgChain.NewFundedAccount("eip712-lend-depositor", sdk.NewCoins(a0gi(big.NewInt(1e5)))
|
||||
// // give them erc20 balance to deposit
|
||||
// fundRes := suite.FundKavaErc20Balance(depositor.EvmAddress, amount.BigInt())
|
||||
// fundRes := suite.FundZgChainErc20Balance(depositor.EvmAddress, amount.BigInt())
|
||||
// suite.NoError(fundRes.Err)
|
||||
|
||||
// // setup messages for convert to coin & deposit into earn
|
||||
@ -143,33 +145,33 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// // create tx
|
||||
// tx := suite.NewEip712TxBuilder(
|
||||
// depositor,
|
||||
// suite.Kava,
|
||||
// suite.ZgChain,
|
||||
// 1e6,
|
||||
// sdk.NewCoins(ukava(1e4)),
|
||||
// sdk.NewCoins(a0gi(big.NewInt(1e4)),
|
||||
// msgs,
|
||||
// "doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit",
|
||||
// ).GetTx()
|
||||
|
||||
// txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
// txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||
// suite.NoError(err)
|
||||
|
||||
// // broadcast tx
|
||||
// res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
// res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||
// TxBytes: txBytes,
|
||||
// Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||
// })
|
||||
// suite.NoError(err)
|
||||
// suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||
|
||||
// _, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
// _, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||
// suite.Require().NoError(err)
|
||||
|
||||
// // check that depositor no longer has erc20 balance
|
||||
// balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||
// balance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||
// suite.BigIntsEqual(big.NewInt(0), balance, "expected no erc20 balance")
|
||||
|
||||
// // check that account has cdp
|
||||
// // cdpRes, err := suite.Kava.Grpc.Query.Cdp.Cdp(context.Background(), &cdptypes.QueryCdpRequest{
|
||||
// // cdpRes, err := suite.ZgChain.Grpc.Query.Cdp.Cdp(context.Background(), &cdptypes.QueryCdpRequest{
|
||||
// // CollateralType: suite.DeployedErc20.CdpCollateralType,
|
||||
// // Owner: depositor.SdkAddress.String(),
|
||||
// // })
|
||||
@ -188,15 +190,15 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||
// depositor.EvmAddress.Hex(),
|
||||
// sdk.NewCoin(sdkDenom, amount),
|
||||
// )
|
||||
// withdrawAndConvertBack := util.KavaMsgRequest{
|
||||
// withdrawAndConvertBack := util.ZgChainMsgRequest{
|
||||
// Msgs: []sdk.Msg{&withdraw, &convertBack},
|
||||
// GasLimit: 1e6,
|
||||
// FeeAmount: sdk.NewCoins(ukava(1000)),
|
||||
// FeeAmount: sdk.NewCoins(a0gi(big.NewInt(1000)),
|
||||
// Data: "withdrawing from mint & converting back to erc20",
|
||||
// }
|
||||
// lastRes := depositor.SignAndBroadcastKavaTx(withdrawAndConvertBack)
|
||||
// lastRes := depositor.SignAndBroadcastZgChainTx(withdrawAndConvertBack)
|
||||
// suite.NoError(lastRes.Err)
|
||||
|
||||
// balance = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||
// balance = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, depositor.EvmAddress)
|
||||
// suite.BigIntsEqual(amount.BigInt(), balance, "expected returned erc20 balance")
|
||||
// }
|
||||
|
@ -2,6 +2,7 @@ package e2e_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||
@ -11,13 +12,13 @@ import (
|
||||
|
||||
func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
|
||||
// ARRANGE
|
||||
// setup kava account
|
||||
funds := ukava(1e5) // .1 KAVA
|
||||
kavaAcc := suite.Kava.NewFundedAccount("balance-test", sdk.NewCoins(funds))
|
||||
// setup 0g account
|
||||
funds := a0gi(big.NewInt(1e5)) // .1 A0GI
|
||||
zgChainAcc := suite.ZgChain.NewFundedAccount("balance-test", sdk.NewCoins(funds))
|
||||
|
||||
// ACT
|
||||
rsp, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
Address: kavaAcc.SdkAddress.String(),
|
||||
rsp, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||
Address: zgChainAcc.SdkAddress.String(),
|
||||
Denom: funds.Denom,
|
||||
})
|
||||
|
||||
@ -26,9 +27,9 @@ func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
|
||||
suite.Require().Equal(funds.Amount, rsp.Balance.Amount)
|
||||
}
|
||||
|
||||
func (suite *IntegrationTestSuite) TestGrpcClientQueryKavaModule_EvmParams() {
|
||||
func (suite *IntegrationTestSuite) TestGrpcClientQueryZgChainModule_EvmParams() {
|
||||
// ACT
|
||||
rsp, err := suite.Kava.Grpc.Query.Evmutil.Params(
|
||||
rsp, err := suite.ZgChain.Grpc.Query.Evmutil.Params(
|
||||
context.Background(), &evmutiltypes.QueryParamsRequest{},
|
||||
)
|
||||
|
||||
|
@ -1,20 +1,22 @@
|
||||
package e2e_test
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
func (suite *IntegrationTestSuite) TestGrpcClientUtil_Account() {
|
||||
// ARRANGE
|
||||
// setup kava account
|
||||
kavaAcc := suite.Kava.NewFundedAccount("account-test", sdk.NewCoins(ukava(1e5)))
|
||||
// setup 0g account
|
||||
zgChainAcc := suite.ZgChain.NewFundedAccount("account-test", sdk.NewCoins(a0gi(big.NewInt(1e5))))
|
||||
|
||||
// ACT
|
||||
rsp, err := suite.Kava.Grpc.BaseAccount(kavaAcc.SdkAddress.String())
|
||||
rsp, err := suite.ZgChain.Grpc.BaseAccount(zgChainAcc.SdkAddress.String())
|
||||
|
||||
// ASSERT
|
||||
suite.Require().NoError(err)
|
||||
suite.Equal(kavaAcc.SdkAddress.String(), rsp.Address)
|
||||
suite.Equal(zgChainAcc.SdkAddress.String(), rsp.Address)
|
||||
suite.Greater(rsp.AccountNumber, uint64(1))
|
||||
suite.Equal(uint64(0), rsp.Sequence)
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
|
||||
@ -20,14 +21,14 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
|
||||
suite.SkipIfKvtoolDisabled()
|
||||
|
||||
// read expected min fee from app.toml
|
||||
minGasPrices, err := getMinFeeFromAppToml(util.KavaHomePath())
|
||||
minGasPrices, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||
suite.NoError(err, "failed to read min fee from app.toml")
|
||||
|
||||
// evm uses akava, get akava min fee
|
||||
evmMinGas := minGasPrices.AmountOf("akava").TruncateInt().BigInt()
|
||||
// evm uses neuron, get neuron min fee
|
||||
evmMinGas := minGasPrices.AmountOf(chaincfg.BaseDenom).TruncateInt().BigInt()
|
||||
|
||||
// returns eth_gasPrice, units in kava
|
||||
gasPrice, err := suite.Kava.EvmClient.SuggestGasPrice(context.Background())
|
||||
// returns eth_gasPrice, units in a0gi
|
||||
gasPrice, err := suite.ZgChain.EvmClient.SuggestGasPrice(context.Background())
|
||||
suite.NoError(err, "failed to get gas price")
|
||||
|
||||
suite.Equal(evmMinGas, gasPrice, "gas price should be equal to min fee")
|
||||
@ -37,13 +38,13 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
||||
suite.SkipIfKvtoolDisabled()
|
||||
|
||||
// setup sender & receiver
|
||||
sender := suite.Kava.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(ukava(1e3)))
|
||||
sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(a0gi(big.NewInt(1e3))))
|
||||
randoReceiver := util.SdkToEvmAddress(app.RandomAddress())
|
||||
|
||||
// get min gas price for evm (from app.toml)
|
||||
minFees, err := getMinFeeFromAppToml(util.KavaHomePath())
|
||||
minFees, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||
suite.NoError(err)
|
||||
minGasPrice := minFees.AmountOf("akava").TruncateInt()
|
||||
minGasPrice := minFees.AmountOf(chaincfg.BaseDenom).TruncateInt()
|
||||
|
||||
// attempt tx with less than min gas price (min fee - 1)
|
||||
tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt()
|
||||
@ -58,12 +59,12 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
||||
suite.ErrorContains(res.Err, "insufficient fee")
|
||||
}
|
||||
|
||||
func getMinFeeFromAppToml(kavaHome string) (sdk.DecCoins, error) {
|
||||
func getMinFeeFromAppToml(zgChainHome string) (sdk.DecCoins, error) {
|
||||
// read the expected min gas price from app.toml
|
||||
parsed := struct {
|
||||
MinGasPrices string `toml:"minimum-gas-prices"`
|
||||
}{}
|
||||
appToml, err := os.ReadFile(filepath.Join(kavaHome, "config", "app.toml"))
|
||||
appToml, err := os.ReadFile(filepath.Join(zgChainHome, "config", "app.toml"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -19,16 +19,17 @@ import (
|
||||
emtypes "github.com/evmos/ethermint/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/tests/e2e/testutil"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
|
||||
var (
|
||||
minEvmGasPrice = big.NewInt(1e10) // akava
|
||||
minEvmGasPrice = big.NewInt(1e10) // neuron
|
||||
)
|
||||
|
||||
func ukava(amt int64) sdk.Coin {
|
||||
return sdk.NewCoin("ukava", sdkmath.NewInt(amt))
|
||||
func a0gi(amt *big.Int) sdk.Coin {
|
||||
return sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewIntFromBigInt(amt))
|
||||
}
|
||||
|
||||
type IntegrationTestSuite struct {
|
||||
@ -39,63 +40,63 @@ func TestIntegrationTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(IntegrationTestSuite))
|
||||
}
|
||||
|
||||
// example test that queries kava via SDK and EVM
|
||||
// example test that queries 0gchain via SDK and EVM
|
||||
func (suite *IntegrationTestSuite) TestChainID() {
|
||||
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.Kava.ChainID)
|
||||
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.ZgChain.ChainID)
|
||||
suite.NoError(err)
|
||||
|
||||
// EVM query
|
||||
evmNetworkId, err := suite.Kava.EvmClient.NetworkID(context.Background())
|
||||
evmNetworkId, err := suite.ZgChain.EvmClient.NetworkID(context.Background())
|
||||
suite.NoError(err)
|
||||
suite.Equal(expectedEvmNetworkId, evmNetworkId)
|
||||
|
||||
// SDK query
|
||||
nodeInfo, err := suite.Kava.Grpc.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||
nodeInfo, err := suite.ZgChain.Grpc.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||
suite.NoError(err)
|
||||
suite.Equal(suite.Kava.ChainID, nodeInfo.DefaultNodeInfo.Network)
|
||||
suite.Equal(suite.ZgChain.ChainID, nodeInfo.DefaultNodeInfo.Network)
|
||||
}
|
||||
|
||||
// example test that funds a new account & queries its balance
|
||||
func (suite *IntegrationTestSuite) TestFundedAccount() {
|
||||
funds := ukava(1e3)
|
||||
acc := suite.Kava.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
||||
funds := a0gi(big.NewInt(1e3))
|
||||
acc := suite.ZgChain.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
||||
|
||||
// check that the sdk & evm signers are for the same account
|
||||
suite.Equal(acc.SdkAddress.String(), util.EvmToSdkAddress(acc.EvmAddress).String())
|
||||
suite.Equal(acc.EvmAddress.Hex(), util.SdkToEvmAddress(acc.SdkAddress).Hex())
|
||||
|
||||
// check balance via SDK query
|
||||
res, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
||||
acc.SdkAddress, "ukava",
|
||||
res, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
||||
acc.SdkAddress, chaincfg.DisplayDenom,
|
||||
))
|
||||
suite.NoError(err)
|
||||
suite.Equal(funds, *res.Balance)
|
||||
|
||||
// check balance via EVM query
|
||||
akavaBal, err := suite.Kava.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
|
||||
neuronBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
|
||||
suite.NoError(err)
|
||||
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), akavaBal)
|
||||
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), neuronBal)
|
||||
}
|
||||
|
||||
// example test that signs & broadcasts an EVM tx
|
||||
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||
// fund an account that can perform the transfer
|
||||
initialFunds := ukava(1e6) // 1 KAVA
|
||||
acc := suite.Kava.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
|
||||
initialFunds := a0gi(big.NewInt(1e6)) // 1 A0GI
|
||||
acc := suite.ZgChain.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
|
||||
|
||||
// get a rando account to send kava to
|
||||
// get a rando account to send 0gchain to
|
||||
randomAddr := app.RandomAddress()
|
||||
to := util.SdkToEvmAddress(randomAddr)
|
||||
|
||||
// example fetching of nonce (account sequence)
|
||||
nonce, err := suite.Kava.EvmClient.PendingNonceAt(context.Background(), acc.EvmAddress)
|
||||
nonce, err := suite.ZgChain.EvmClient.PendingNonceAt(context.Background(), acc.EvmAddress)
|
||||
suite.NoError(err)
|
||||
suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs
|
||||
|
||||
// transfer kava over EVM
|
||||
kavaToTransfer := big.NewInt(1e17) // .1 KAVA; akava has 18 decimals.
|
||||
// transfer a0gi over EVM
|
||||
a0giToTransfer := big.NewInt(1e17) // .1 A0GI; neuron has 18 decimals.
|
||||
req := util.EvmTxRequest{
|
||||
Tx: ethtypes.NewTransaction(nonce, to, kavaToTransfer, 1e5, minEvmGasPrice, nil),
|
||||
Tx: ethtypes.NewTransaction(nonce, to, a0giToTransfer, 1e5, minEvmGasPrice, nil),
|
||||
Data: "any ol' data to track this through the system",
|
||||
}
|
||||
res := acc.SignAndBroadcastEvmTx(req)
|
||||
@ -103,36 +104,36 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||
suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status)
|
||||
|
||||
// evm txs refund unused gas. so to know the expected balance we need to know how much gas was used.
|
||||
ukavaUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
|
||||
a0giUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
|
||||
Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)).
|
||||
QuoRaw(1e12) // convert akava to ukava
|
||||
QuoRaw(1e12) // convert neuron to a0gi
|
||||
|
||||
// expect (9 - gas used) KAVA remaining in account.
|
||||
balance := suite.Kava.QuerySdkForBalances(acc.SdkAddress)
|
||||
suite.Equal(sdkmath.NewInt(9e5).Sub(ukavaUsedForGas), balance.AmountOf("ukava"))
|
||||
// expect (9 - gas used) A0GI remaining in account.
|
||||
balance := suite.ZgChain.QuerySdkForBalances(acc.SdkAddress)
|
||||
suite.Equal(sdkmath.NewInt(9e5).Sub(a0giUsedForGas), balance.AmountOf(chaincfg.DisplayDenom))
|
||||
}
|
||||
|
||||
// TestIbcTransfer transfers KAVA from the primary kava chain (suite.Kava) to the ibc chain (suite.Ibc).
|
||||
// Note that because the IBC chain also runs kava's binary, this tests both the sending & receiving.
|
||||
// TestIbcTransfer transfers A0GI from the primary 0g-chain (suite.ZgChain) to the ibc chain (suite.Ibc).
|
||||
// Note that because the IBC chain also runs 0g-chain's binary, this tests both the sending & receiving.
|
||||
func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
||||
suite.SkipIfIbcDisabled()
|
||||
|
||||
// ARRANGE
|
||||
// setup kava account
|
||||
funds := ukava(1e5) // .1 KAVA
|
||||
kavaAcc := suite.Kava.NewFundedAccount("ibc-transfer-kava-side", sdk.NewCoins(funds))
|
||||
// setup 0g-chain account
|
||||
funds := a0gi(big.NewInt(1e5)) // .1 A0GI
|
||||
zgChainAcc := suite.ZgChain.NewFundedAccount("ibc-transfer-0g-side", sdk.NewCoins(funds))
|
||||
// setup ibc account
|
||||
ibcAcc := suite.Ibc.NewFundedAccount("ibc-transfer-ibc-side", sdk.NewCoins())
|
||||
|
||||
gasLimit := int64(2e5)
|
||||
fee := ukava(200)
|
||||
fee := a0gi(big.NewInt(200))
|
||||
|
||||
fundsToSend := ukava(5e4) // .005 KAVA
|
||||
fundsToSend := a0gi(big.NewInt(5e4)) // .005 A0GI
|
||||
transferMsg := ibctypes.NewMsgTransfer(
|
||||
testutil.IbcPort,
|
||||
testutil.IbcChannel,
|
||||
fundsToSend,
|
||||
kavaAcc.SdkAddress.String(),
|
||||
zgChainAcc.SdkAddress.String(),
|
||||
ibcAcc.SdkAddress.String(),
|
||||
ibcclienttypes.NewHeight(0, 0), // timeout height disabled when 0
|
||||
uint64(time.Now().Add(30*time.Second).UnixNano()),
|
||||
@ -142,22 +143,22 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
||||
expectedSrcBalance := funds.Sub(fundsToSend).Sub(fee)
|
||||
|
||||
// ACT
|
||||
// IBC transfer from kava -> ibc
|
||||
transferTo := util.KavaMsgRequest{
|
||||
// IBC transfer from 0g-chain -> ibc
|
||||
transferTo := util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{transferMsg},
|
||||
GasLimit: uint64(gasLimit),
|
||||
FeeAmount: sdk.NewCoins(fee),
|
||||
Memo: "sent from Kava!",
|
||||
Memo: "sent from ZgChain!",
|
||||
}
|
||||
res := kavaAcc.SignAndBroadcastKavaTx(transferTo)
|
||||
res := zgChainAcc.SignAndBroadcastZgChainTx(transferTo)
|
||||
|
||||
// ASSERT
|
||||
suite.NoError(res.Err)
|
||||
|
||||
// the balance should be deducted from kava account
|
||||
// the balance should be deducted from 0g-chain account
|
||||
suite.Eventually(func() bool {
|
||||
balance := suite.Kava.QuerySdkForBalances(kavaAcc.SdkAddress)
|
||||
return balance.AmountOf("ukava").Equal(expectedSrcBalance.Amount)
|
||||
balance := suite.ZgChain.QuerySdkForBalances(zgChainAcc.SdkAddress)
|
||||
return balance.AmountOf(chaincfg.DisplayDenom).Equal(expectedSrcBalance.Amount)
|
||||
}, 10*time.Second, 1*time.Second)
|
||||
|
||||
// expect the balance to be transferred to the ibc chain!
|
||||
|
@ -13,6 +13,6 @@ func (suite *IntegrationTestSuite) TestUpgradeHandler() {
|
||||
suite.True(true)
|
||||
|
||||
// Uncomment & use these contexts to compare chain state before & after the upgrade occurs.
|
||||
// beforeUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
|
||||
// afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||
// beforeUpgradeCtx := suite.ZgChain.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
|
||||
// afterUpgradeCtx := suite.ZgChain.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
rpchttpclient "github.com/cometbft/cometbft/rpc/client/http"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
)
|
||||
@ -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.
|
||||
// someday they may be accepted as configurable parameters.
|
||||
var (
|
||||
kvtoolKavaChain = ChainDetails{
|
||||
kvtoolZgChainChain = ChainDetails{
|
||||
RpcUrl: "http://localhost:26657",
|
||||
GrpcUrl: "http://localhost:9090",
|
||||
EvmRpcUrl: "http://localhost:8545",
|
||||
|
||||
ChainId: "kavalocalnet_8888-1",
|
||||
StakingDenom: "ukava",
|
||||
ChainId: "0gchainlocalnet_8888-1",
|
||||
StakingDenom: chaincfg.DisplayDenom,
|
||||
}
|
||||
kvtoolIbcChain = ChainDetails{
|
||||
RpcUrl: "http://localhost:26658",
|
||||
GrpcUrl: "http://localhost:9092",
|
||||
EvmRpcUrl: "http://localhost:8547",
|
||||
|
||||
ChainId: "kavalocalnet_8889-2",
|
||||
ChainId: "0gchainlocalnet_8889-2",
|
||||
StakingDenom: "uatom",
|
||||
}
|
||||
)
|
||||
|
@ -8,24 +8,24 @@ import (
|
||||
)
|
||||
|
||||
type KvtoolRunnerConfig struct {
|
||||
KavaConfigTemplate string
|
||||
ZgChainConfigTemplate string
|
||||
|
||||
ImageTag string
|
||||
IncludeIBC bool
|
||||
|
||||
EnableAutomatedUpgrade bool
|
||||
KavaUpgradeName string
|
||||
KavaUpgradeHeight int64
|
||||
KavaUpgradeBaseImageTag string
|
||||
EnableAutomatedUpgrade bool
|
||||
ZgChainUpgradeName string
|
||||
ZgChainUpgradeHeight int64
|
||||
ZgChainUpgradeBaseImageTag string
|
||||
|
||||
SkipShutdown bool
|
||||
}
|
||||
|
||||
// KvtoolRunner implements a NodeRunner that spins up local chains with kvtool.
|
||||
// It has support for the following:
|
||||
// - running a Kava node
|
||||
// - optionally, running an IBC node with a channel opened to the Kava node
|
||||
// - optionally, start the Kava node on one version and upgrade to another
|
||||
// - running a ZgChain node
|
||||
// - optionally, running an IBC node with a channel opened to the ZgChain node
|
||||
// - optionally, start the ZgChain node on one version and upgrade to another
|
||||
type KvtoolRunner struct {
|
||||
config KvtoolRunnerConfig
|
||||
}
|
||||
@ -51,8 +51,8 @@ func (k *KvtoolRunner) StartChains() Chains {
|
||||
}
|
||||
|
||||
// start local test network with kvtool
|
||||
log.Println("starting kava node")
|
||||
kvtoolArgs := []string{"testnet", "bootstrap", "--kava.configTemplate", k.config.KavaConfigTemplate}
|
||||
log.Println("starting 0gchain node")
|
||||
kvtoolArgs := []string{"testnet", "bootstrap", "--0gchain.configTemplate", k.config.ZgChainConfigTemplate}
|
||||
// include an ibc chain if desired
|
||||
if k.config.IncludeIBC {
|
||||
kvtoolArgs = append(kvtoolArgs, "--ibc")
|
||||
@ -60,32 +60,32 @@ func (k *KvtoolRunner) StartChains() Chains {
|
||||
// handle automated upgrade functionality, if defined
|
||||
if k.config.EnableAutomatedUpgrade {
|
||||
kvtoolArgs = append(kvtoolArgs,
|
||||
"--upgrade-name", k.config.KavaUpgradeName,
|
||||
"--upgrade-height", fmt.Sprint(k.config.KavaUpgradeHeight),
|
||||
"--upgrade-base-image-tag", k.config.KavaUpgradeBaseImageTag,
|
||||
"--upgrade-name", k.config.ZgChainUpgradeName,
|
||||
"--upgrade-height", fmt.Sprint(k.config.ZgChainUpgradeHeight),
|
||||
"--upgrade-base-image-tag", k.config.ZgChainUpgradeBaseImageTag,
|
||||
)
|
||||
}
|
||||
// start the chain
|
||||
startKavaCmd := exec.Command("kvtool", kvtoolArgs...)
|
||||
startKavaCmd.Env = os.Environ()
|
||||
startKavaCmd.Env = append(startKavaCmd.Env, fmt.Sprintf("KAVA_TAG=%s", k.config.ImageTag))
|
||||
startKavaCmd.Stdout = os.Stdout
|
||||
startKavaCmd.Stderr = os.Stderr
|
||||
log.Println(startKavaCmd.String())
|
||||
if err := startKavaCmd.Run(); err != nil {
|
||||
panic(fmt.Sprintf("failed to start kava: %s", err.Error()))
|
||||
startZgChainCmd := exec.Command("kvtool", kvtoolArgs...)
|
||||
startZgChainCmd.Env = os.Environ()
|
||||
startZgChainCmd.Env = append(startZgChainCmd.Env, fmt.Sprintf("0GCHAIN_TAG=%s", k.config.ImageTag))
|
||||
startZgChainCmd.Stdout = os.Stdout
|
||||
startZgChainCmd.Stderr = os.Stderr
|
||||
log.Println(startZgChainCmd.String())
|
||||
if err := startZgChainCmd.Run(); err != nil {
|
||||
panic(fmt.Sprintf("failed to start 0gchain: %s", err.Error()))
|
||||
}
|
||||
|
||||
// wait for chain to be live.
|
||||
// if an upgrade is defined, this waits for the upgrade to be completed.
|
||||
if err := waitForChainStart(kvtoolKavaChain); err != nil {
|
||||
if err := waitForChainStart(kvtoolZgChainChain); err != nil {
|
||||
k.Shutdown()
|
||||
panic(err)
|
||||
}
|
||||
log.Println("kava is started!")
|
||||
log.Println("0gchain is started!")
|
||||
|
||||
chains := NewChains()
|
||||
chains.Register("kava", &kvtoolKavaChain)
|
||||
chains.Register("0gchain", &kvtoolZgChainChain)
|
||||
if k.config.IncludeIBC {
|
||||
chains.Register("ibc", &kvtoolIbcChain)
|
||||
}
|
||||
@ -101,11 +101,11 @@ func (k *KvtoolRunner) Shutdown() {
|
||||
log.Printf("would shut down but SkipShutdown is true")
|
||||
return
|
||||
}
|
||||
log.Println("shutting down kava node")
|
||||
shutdownKavaCmd := exec.Command("kvtool", "testnet", "down")
|
||||
shutdownKavaCmd.Stdout = os.Stdout
|
||||
shutdownKavaCmd.Stderr = os.Stderr
|
||||
if err := shutdownKavaCmd.Run(); err != nil {
|
||||
log.Println("shutting down 0gchain node")
|
||||
shutdownZgChainCmd := exec.Command("kvtool", "testnet", "down")
|
||||
shutdownZgChainCmd.Stdout = os.Stdout
|
||||
shutdownZgChainCmd.Stderr = os.Stderr
|
||||
if err := shutdownZgChainCmd.Run(); err != nil {
|
||||
panic(fmt.Sprintf("failed to shutdown kvtool: %s", err.Error()))
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ import (
|
||||
// LiveNodeRunnerConfig implements NodeRunner.
|
||||
// It connects to a running network via the RPC, GRPC, and EVM urls.
|
||||
type LiveNodeRunnerConfig struct {
|
||||
KavaRpcUrl string
|
||||
KavaGrpcUrl string
|
||||
KavaEvmRpcUrl string
|
||||
ZgChainRpcUrl string
|
||||
ZgChainGrpcUrl string
|
||||
ZgChainEvmRpcUrl string
|
||||
|
||||
UpgradeHeight int64
|
||||
}
|
||||
@ -37,41 +37,41 @@ func NewLiveNodeRunner(config LiveNodeRunnerConfig) *LiveNodeRunner {
|
||||
// It initializes connections to the chain based on parameters.
|
||||
// It attempts to ping the necessary endpoints and panics if they cannot be reached.
|
||||
func (r LiveNodeRunner) StartChains() Chains {
|
||||
fmt.Println("establishing connection to live kava network")
|
||||
fmt.Println("establishing connection to live 0g-chain network")
|
||||
chains := NewChains()
|
||||
|
||||
kavaChain := ChainDetails{
|
||||
RpcUrl: r.config.KavaRpcUrl,
|
||||
GrpcUrl: r.config.KavaGrpcUrl,
|
||||
EvmRpcUrl: r.config.KavaEvmRpcUrl,
|
||||
zgChain := ChainDetails{
|
||||
RpcUrl: r.config.ZgChainRpcUrl,
|
||||
GrpcUrl: r.config.ZgChainGrpcUrl,
|
||||
EvmRpcUrl: r.config.ZgChainEvmRpcUrl,
|
||||
}
|
||||
|
||||
if err := waitForChainStart(kavaChain); err != nil {
|
||||
if err := waitForChainStart(zgChain); err != nil {
|
||||
panic(fmt.Sprintf("failed to ping chain: %s", err))
|
||||
}
|
||||
|
||||
// determine chain id
|
||||
client, err := grpc.NewClient(kavaChain.GrpcUrl)
|
||||
client, err := grpc.NewClient(zgChain.GrpcUrl)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to create kava grpc client: %s", err))
|
||||
panic(fmt.Sprintf("failed to create 0gchain grpc client: %s", err))
|
||||
}
|
||||
|
||||
nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to fetch kava node info: %s", err))
|
||||
panic(fmt.Sprintf("failed to fetch 0gchain node info: %s", err))
|
||||
}
|
||||
kavaChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
||||
zgChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
||||
|
||||
// determine staking denom
|
||||
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to fetch kava staking params: %s", err))
|
||||
panic(fmt.Sprintf("failed to fetch 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
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func waitForChainStart(chainDetails ChainDetails) error {
|
||||
b := backoff.NewExponentialBackOff()
|
||||
b.MaxInterval = 5 * time.Second
|
||||
b.MaxElapsedTime = 30 * time.Second
|
||||
if err := backoff.Retry(func() error { return pingKava(chainDetails.RpcUrl) }, b); err != nil {
|
||||
if err := backoff.Retry(func() error { return pingZgChain(chainDetails.RpcUrl) }, b); err != nil {
|
||||
return fmt.Errorf("failed connect to chain: %s", err)
|
||||
}
|
||||
|
||||
@ -34,9 +34,9 @@ func waitForChainStart(chainDetails ChainDetails) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func pingKava(rpcUrl string) error {
|
||||
func pingZgChain(rpcUrl string) error {
|
||||
statusUrl := fmt.Sprintf("%s/status", rpcUrl)
|
||||
log.Printf("pinging kava chain: %s\n", statusUrl)
|
||||
log.Printf("pinging 0g-chain: %s\n", statusUrl)
|
||||
res, err := http.Get(statusUrl)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -45,7 +45,7 @@ func pingKava(rpcUrl string) error {
|
||||
if res.StatusCode >= 400 {
|
||||
return fmt.Errorf("ping to status failed: %d", res.StatusCode)
|
||||
}
|
||||
log.Println("successfully started Kava!")
|
||||
log.Println("successfully started ZgChain!")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ import (
|
||||
emtests "github.com/evmos/ethermint/tests"
|
||||
emtypes "github.com/evmos/ethermint/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
|
||||
@ -43,9 +43,9 @@ type SigningAccount struct {
|
||||
evmReqChan chan<- util.EvmTxRequest
|
||||
evmResChan <-chan util.EvmTxResponse
|
||||
|
||||
kavaSigner *util.KavaSigner
|
||||
sdkReqChan chan<- util.KavaMsgRequest
|
||||
sdkResChan <-chan util.KavaMsgResponse
|
||||
zgChainSigner *util.ZgChainSigner
|
||||
sdkReqChan chan<- util.ZgChainMsgRequest
|
||||
sdkResChan <-chan util.ZgChainMsgResponse
|
||||
|
||||
EvmAuth *bind.TransactOpts
|
||||
|
||||
@ -72,7 +72,7 @@ func (chain *Chain) AddNewSigningAccount(name string, hdPath *hd.BIP44Params, ch
|
||||
chain.t.Fatalf("account with name %s already exists", name)
|
||||
}
|
||||
|
||||
// Kava signing account for SDK side
|
||||
// 0gChain signing account for SDK side
|
||||
privKeyBytes, err := hd.Secp256k1.Derive()(mnemonic, "", hdPath.String())
|
||||
require.NoErrorf(chain.t, err, "failed to derive private key from mnemonic for %s: %s", name, err)
|
||||
privKey := ðsecp256k1.PrivKey{Key: privKeyBytes}
|
||||
@ -97,8 +97,8 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
||||
chain.t.Fatalf("account with name %s already exists", name)
|
||||
}
|
||||
|
||||
// Kava signing account for SDK side
|
||||
kavaSigner := util.NewKavaSigner(
|
||||
// 0gChain signing account for SDK side
|
||||
zgChainSigner := util.NewZgChainSigner(
|
||||
chainId,
|
||||
chain.EncodingConfig,
|
||||
chain.Grpc.Query.Auth,
|
||||
@ -107,11 +107,11 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
||||
100,
|
||||
)
|
||||
|
||||
sdkReqChan := make(chan util.KavaMsgRequest)
|
||||
sdkResChan, err := kavaSigner.Run(sdkReqChan)
|
||||
sdkReqChan := make(chan util.ZgChainMsgRequest)
|
||||
sdkResChan, err := zgChainSigner.Run(sdkReqChan)
|
||||
require.NoErrorf(chain.t, err, "failed to start signer for account %s: %s", name, err)
|
||||
|
||||
// Kava signing account for EVM side
|
||||
// 0gChain signing account for EVM side
|
||||
evmChainId, err := emtypes.ParseChainID(chainId)
|
||||
require.NoErrorf(chain.t, err, "unable to parse ethermint-compatible chain id from %s", chainId)
|
||||
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes()))
|
||||
@ -141,21 +141,21 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
||||
evmReqChan: evmReqChan,
|
||||
evmResChan: evmResChan,
|
||||
|
||||
kavaSigner: kavaSigner,
|
||||
sdkReqChan: sdkReqChan,
|
||||
sdkResChan: sdkResChan,
|
||||
zgChainSigner: zgChainSigner,
|
||||
sdkReqChan: sdkReqChan,
|
||||
sdkResChan: sdkResChan,
|
||||
|
||||
EvmAuth: evmSigner.Auth,
|
||||
|
||||
EvmAddress: evmSigner.Address(),
|
||||
SdkAddress: kavaSigner.Address(),
|
||||
SdkAddress: zgChainSigner.Address(),
|
||||
}
|
||||
|
||||
return chain.accounts[name]
|
||||
}
|
||||
|
||||
// SignAndBroadcastKavaTx sends a request to the signer and awaits its response.
|
||||
func (a *SigningAccount) SignAndBroadcastKavaTx(req util.KavaMsgRequest) util.KavaMsgResponse {
|
||||
// SignAndBroadcastZgChainTx sends a request to the signer and awaits its response.
|
||||
func (a *SigningAccount) SignAndBroadcastZgChainTx(req util.ZgChainMsgRequest) util.ZgChainMsgResponse {
|
||||
a.l.Printf("broadcasting sdk tx. has data = %+v\n", req.Data)
|
||||
// send the request to signer
|
||||
a.sdkReqChan <- req
|
||||
@ -222,7 +222,7 @@ func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccou
|
||||
|
||||
acc := chain.AddNewSigningAccount(
|
||||
name,
|
||||
hd.CreateHDPath(app.Bip44CoinType, 0, 0),
|
||||
hd.CreateHDPath(chaincfg.Bip44CoinType, 0, 0),
|
||||
chain.ChainID,
|
||||
mnemonic,
|
||||
)
|
||||
@ -257,12 +257,12 @@ func (a *SigningAccount) NextNonce() (uint64, error) {
|
||||
}
|
||||
|
||||
// BankSend is a helper method for sending funds via x/bank's MsgSend
|
||||
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.KavaMsgResponse {
|
||||
return a.SignAndBroadcastKavaTx(
|
||||
util.KavaMsgRequest{
|
||||
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.ZgChainMsgResponse {
|
||||
return a.SignAndBroadcastZgChainTx(
|
||||
util.ZgChainMsgRequest{
|
||||
Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)},
|
||||
GasLimit: 2e5, // 200,000 gas
|
||||
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001ukava
|
||||
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001a0gi
|
||||
Data: fmt.Sprintf("sending %s to %s", amount, to),
|
||||
},
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
kavaparams "github.com/0glabs/0g-chain/app/params"
|
||||
chainparams "github.com/0glabs/0g-chain/app/params"
|
||||
"github.com/0glabs/0g-chain/client/grpc"
|
||||
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
@ -41,11 +41,11 @@ type Chain struct {
|
||||
ContractAddrs map[string]common.Address
|
||||
erc20s map[common.Address]struct{}
|
||||
|
||||
EncodingConfig kavaparams.EncodingConfig
|
||||
EncodingConfig chainparams.EncodingConfig
|
||||
|
||||
TmSignClient tmclient.SignClient
|
||||
|
||||
Grpc *grpc.KavaGrpcClient
|
||||
Grpc *grpc.ZgChainGrpcClient
|
||||
}
|
||||
|
||||
// NewChain creates the query clients & signing account management for a chain run on a set of ports.
|
||||
@ -65,7 +65,7 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
||||
kr, err := keyring.New(
|
||||
sdk.KeyringServiceName(),
|
||||
keyring.BackendTest,
|
||||
util.KavaHomePath(),
|
||||
util.ZgChainHomePath(),
|
||||
nil,
|
||||
chain.EncodingConfig.Marshaler,
|
||||
evmhd.EthSecp256k1Option(),
|
||||
@ -77,7 +77,7 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
||||
|
||||
client, err := grpc.NewClient(details.GrpcUrl)
|
||||
if err != nil {
|
||||
chain.t.Fatalf("failed to create kava grpc client: %s", err)
|
||||
chain.t.Fatalf("failed to create 0gchain grpc client: %s", err)
|
||||
}
|
||||
chain.Grpc = client
|
||||
|
||||
|
@ -36,26 +36,26 @@ type SuiteConfig struct {
|
||||
// KvtoolConfig wraps configuration options for running the end-to-end test suite against
|
||||
// a locally running chain. This config must be defined if E2E_RUN_KVTOOL_NETWORKS is true.
|
||||
type KvtoolConfig struct {
|
||||
// The kava.configTemplate flag to be passed to kvtool, usually "master".
|
||||
// The 0gchain.configTemplate flag to be passed to kvtool, usually "master".
|
||||
// This allows one to change the base genesis used to start the chain.
|
||||
KavaConfigTemplate string
|
||||
ZgChainConfigTemplate string
|
||||
|
||||
// Whether or not to run a chain upgrade & run post-upgrade tests. Use `suite.SkipIfUpgradeDisabled()` in post-upgrade tests.
|
||||
IncludeAutomatedUpgrade bool
|
||||
// Name of the upgrade, if upgrade is enabled.
|
||||
KavaUpgradeName string
|
||||
ZgChainUpgradeName string
|
||||
// Height upgrade will be applied to the test chain, if upgrade is enabled.
|
||||
KavaUpgradeHeight int64
|
||||
// Tag of kava docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
|
||||
KavaUpgradeBaseImageTag string
|
||||
ZgChainUpgradeHeight int64
|
||||
// Tag of 0gchain docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
|
||||
ZgChainUpgradeBaseImageTag string
|
||||
}
|
||||
|
||||
// LiveNetworkConfig wraps configuration options for running the end-to-end test suite
|
||||
// against a live network. It must be defined if E2E_RUN_KVTOOL_NETWORKS is false.
|
||||
type LiveNetworkConfig struct {
|
||||
KavaRpcUrl string
|
||||
KavaGrpcUrl string
|
||||
KavaEvmRpcUrl string
|
||||
ZgChainRpcUrl string
|
||||
ZgChainGrpcUrl string
|
||||
ZgChainEvmRpcUrl string
|
||||
|
||||
UpgradeHeight int64
|
||||
}
|
||||
@ -65,8 +65,8 @@ func ParseSuiteConfig() SuiteConfig {
|
||||
config := SuiteConfig{
|
||||
// this mnemonic is expected to be a funded account that can seed the funds for all
|
||||
// new accounts created during tests. it will be available under Accounts["whale"]
|
||||
FundedAccountMnemonic: nonemptyStringEnv("E2E_KAVA_FUNDED_ACCOUNT_MNEMONIC"),
|
||||
ZgchainERC20Address: nonemptyStringEnv("E2E_KAVA_ERC20_ADDRESS"),
|
||||
FundedAccountMnemonic: nonemptyStringEnv("E2E_0GCHAIN_FUNDED_ACCOUNT_MNEMONIC"),
|
||||
ZgchainERC20Address: nonemptyStringEnv("E2E_0GCHAIN_ERC20_ADDRESS"),
|
||||
IncludeIbcTests: mustParseBool("E2E_INCLUDE_IBC_TESTS"),
|
||||
}
|
||||
|
||||
@ -90,18 +90,18 @@ func ParseSuiteConfig() SuiteConfig {
|
||||
// ParseKvtoolConfig builds a KvtoolConfig from environment variables.
|
||||
func ParseKvtoolConfig() KvtoolConfig {
|
||||
config := KvtoolConfig{
|
||||
KavaConfigTemplate: nonemptyStringEnv("E2E_KVTOOL_KAVA_CONFIG_TEMPLATE"),
|
||||
ZgChainConfigTemplate: nonemptyStringEnv("E2E_KVTOOL_0GCHAIN_CONFIG_TEMPLATE"),
|
||||
IncludeAutomatedUpgrade: mustParseBool("E2E_INCLUDE_AUTOMATED_UPGRADE"),
|
||||
}
|
||||
|
||||
if config.IncludeAutomatedUpgrade {
|
||||
config.KavaUpgradeName = nonemptyStringEnv("E2E_KAVA_UPGRADE_NAME")
|
||||
config.KavaUpgradeBaseImageTag = nonemptyStringEnv("E2E_KAVA_UPGRADE_BASE_IMAGE_TAG")
|
||||
upgradeHeight, err := strconv.ParseInt(nonemptyStringEnv("E2E_KAVA_UPGRADE_HEIGHT"), 10, 64)
|
||||
config.ZgChainUpgradeName = nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_NAME")
|
||||
config.ZgChainUpgradeBaseImageTag = nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_BASE_IMAGE_TAG")
|
||||
upgradeHeight, err := strconv.ParseInt(nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_HEIGHT"), 10, 64)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("E2E_KAVA_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
panic(fmt.Sprintf("E2E_0GCHAIN_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
}
|
||||
config.KavaUpgradeHeight = upgradeHeight
|
||||
config.ZgChainUpgradeHeight = upgradeHeight
|
||||
}
|
||||
|
||||
return config
|
||||
@ -110,16 +110,16 @@ func ParseKvtoolConfig() KvtoolConfig {
|
||||
// ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.
|
||||
func ParseLiveNetworkConfig() LiveNetworkConfig {
|
||||
config := LiveNetworkConfig{
|
||||
KavaRpcUrl: nonemptyStringEnv("E2E_KAVA_RPC_URL"),
|
||||
KavaGrpcUrl: nonemptyStringEnv("E2E_KAVA_GRPC_URL"),
|
||||
KavaEvmRpcUrl: nonemptyStringEnv("E2E_KAVA_EVM_RPC_URL"),
|
||||
ZgChainRpcUrl: nonemptyStringEnv("E2E_0GCHAIN_RPC_URL"),
|
||||
ZgChainGrpcUrl: nonemptyStringEnv("E2E_0GCHAIN_GRPC_URL"),
|
||||
ZgChainEvmRpcUrl: nonemptyStringEnv("E2E_0GCHAIN_EVM_RPC_URL"),
|
||||
}
|
||||
|
||||
upgradeHeight := os.Getenv("E2E_KAVA_UPGRADE_HEIGHT")
|
||||
upgradeHeight := os.Getenv("E2E_0GCHAIN_UPGRADE_HEIGHT")
|
||||
if upgradeHeight != "" {
|
||||
parsedHeight, err := strconv.ParseInt(upgradeHeight, 10, 64)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("E2E_KAVA_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
panic(fmt.Sprintf("E2E_0GCHAIN_UPGRADE_HEIGHT must be a number: %s", err))
|
||||
}
|
||||
|
||||
config.UpgradeHeight = parsedHeight
|
||||
|
@ -12,13 +12,13 @@ import (
|
||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
// InitKavaEvmData is run after the chain is running, but before the tests are run.
|
||||
// InitZgChainEvmData is run after the chain is running, but before the tests are run.
|
||||
// It is used to initialize some EVM state, such as deploying contracts.
|
||||
func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
||||
func (suite *E2eTestSuite) InitZgChainEvmData() {
|
||||
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||
|
||||
// ensure funded account has nonzero erc20 balance
|
||||
balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
balance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
if balance.Cmp(big.NewInt(0)) != 1 {
|
||||
panic(fmt.Sprintf(
|
||||
"expected funded account (%s) to have erc20 balance of token %s",
|
||||
@ -28,7 +28,7 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
}
|
||||
|
||||
// expect the erc20 to be enabled for conversion to sdk.Coin
|
||||
params, err := suite.Kava.Grpc.Query.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
|
||||
params, err := suite.ZgChain.Grpc.Query.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to fetch evmutil params during init: %s", err))
|
||||
}
|
||||
@ -43,10 +43,10 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
if !found {
|
||||
panic(fmt.Sprintf("erc20 %s must be enabled for conversion to cosmos coin", erc20Addr))
|
||||
}
|
||||
suite.Kava.RegisterErc20(suite.DeployedErc20.Address)
|
||||
suite.ZgChain.RegisterErc20(suite.DeployedErc20.Address)
|
||||
|
||||
// expect the erc20's cosmos denom to be a supported cdp collateral type
|
||||
// cdpParams, err := suite.Kava.Grpc.Query.Cdp.Params(context.Background(), &types.QueryParamsRequest{})
|
||||
// cdpParams, err := suite.ZgChain.Grpc.Query.Cdp.Params(context.Background(), &types.QueryParamsRequest{})
|
||||
// suite.Require().NoError(err)
|
||||
// found = false
|
||||
// for _, cp := range cdpParams.Params.CollateralParams {
|
||||
@ -69,13 +69,13 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
||||
"what's up!",
|
||||
)
|
||||
suite.NoError(err, "failed to deploy a contract to the EVM")
|
||||
suite.Kava.ContractAddrs["greeter"] = greeterAddr
|
||||
suite.ZgChain.ContractAddrs["greeter"] = greeterAddr
|
||||
}
|
||||
|
||||
// FundKavaErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.
|
||||
func (suite *E2eTestSuite) FundKavaErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
|
||||
// FundZgChainErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.
|
||||
func (suite *E2eTestSuite) FundZgChainErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
|
||||
// funded account should have erc20 balance
|
||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
||||
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||
res, err := whale.TransferErc20(suite.DeployedErc20.Address, toAddress, amount)
|
||||
suite.NoError(err)
|
||||
return res
|
||||
|
@ -10,14 +10,14 @@ import (
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
|
||||
const (
|
||||
FundedAccountName = "whale"
|
||||
// use coin type 60 so we are compatible with accounts from `kava add keys --eth <name>`
|
||||
// use coin type 60 so we are compatible with accounts from `0gchaind add keys --eth <name>`
|
||||
// these accounts use the ethsecp256k1 signing algorithm that allows the signing client
|
||||
// to manage both sdk & evm txs.
|
||||
Bip44CoinType = 60
|
||||
@ -33,7 +33,7 @@ const (
|
||||
// - the funded account has a nonzero balance of the erc20
|
||||
// - the erc20 is enabled for conversion to sdk.Coin
|
||||
// - the corresponding sdk.Coin is enabled as a cdp collateral type
|
||||
// These requirements are checked in InitKavaEvmData().
|
||||
// These requirements are checked in InitZgChainEvmData().
|
||||
type DeployedErc20 struct {
|
||||
Address common.Address
|
||||
CosmosDenom string
|
||||
@ -41,15 +41,15 @@ type DeployedErc20 struct {
|
||||
CdpCollateralType string
|
||||
}
|
||||
|
||||
// E2eTestSuite is a testify test suite for running end-to-end integration tests on Kava.
|
||||
// E2eTestSuite is a testify test suite for running end-to-end integration tests on ZgChain.
|
||||
type E2eTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
config SuiteConfig
|
||||
runner runner.NodeRunner
|
||||
|
||||
Kava *Chain
|
||||
Ibc *Chain
|
||||
ZgChain *Chain
|
||||
Ibc *Chain
|
||||
|
||||
UpgradeHeight int64
|
||||
DeployedErc20 DeployedErc20
|
||||
@ -85,13 +85,13 @@ func (s costSummary) String() string {
|
||||
func (suite *E2eTestSuite) SetupSuite() {
|
||||
var err error
|
||||
fmt.Println("setting up test suite.")
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
suiteConfig := ParseSuiteConfig()
|
||||
suite.config = suiteConfig
|
||||
suite.DeployedErc20 = DeployedErc20{
|
||||
Address: common.HexToAddress(suiteConfig.ZgchainERC20Address),
|
||||
// Denom & CdpCollateralType are fetched in InitKavaEvmData()
|
||||
// Denom & CdpCollateralType are fetched in InitZgChainEvmData()
|
||||
}
|
||||
|
||||
// setup the correct NodeRunner for the given config
|
||||
@ -104,11 +104,11 @@ func (suite *E2eTestSuite) SetupSuite() {
|
||||
}
|
||||
|
||||
chains := suite.runner.StartChains()
|
||||
kavachain := chains.MustGetChain("kava")
|
||||
suite.Kava, err = NewChain(suite.T(), kavachain, suiteConfig.FundedAccountMnemonic)
|
||||
zgchain := chains.MustGetChain("0gchain")
|
||||
suite.ZgChain, err = NewChain(suite.T(), zgchain, suiteConfig.FundedAccountMnemonic)
|
||||
if err != nil {
|
||||
suite.runner.Shutdown()
|
||||
suite.T().Fatalf("failed to create kava chain querier: %s", err)
|
||||
suite.T().Fatalf("failed to create 0g-chain querier: %s", err)
|
||||
}
|
||||
|
||||
if suiteConfig.IncludeIbcTests {
|
||||
@ -120,14 +120,14 @@ func (suite *E2eTestSuite) SetupSuite() {
|
||||
}
|
||||
}
|
||||
|
||||
suite.InitKavaEvmData()
|
||||
suite.InitZgChainEvmData()
|
||||
|
||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
||||
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||
suite.cost = costSummary{
|
||||
sdkAddress: whale.SdkAddress.String(),
|
||||
evmAddress: whale.EvmAddress.Hex(),
|
||||
sdkBalanceBefore: suite.Kava.QuerySdkForBalances(whale.SdkAddress),
|
||||
erc20BalanceBefore: suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress),
|
||||
sdkBalanceBefore: suite.ZgChain.QuerySdkForBalances(whale.SdkAddress),
|
||||
erc20BalanceBefore: suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress),
|
||||
}
|
||||
}
|
||||
|
||||
@ -136,27 +136,27 @@ func (suite *E2eTestSuite) SetupSuite() {
|
||||
func (suite *E2eTestSuite) TearDownSuite() {
|
||||
fmt.Println("tearing down test suite.")
|
||||
|
||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
||||
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||
|
||||
if suite.enableRefunds {
|
||||
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
|
||||
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
suite.cost.sdkBalanceAfter = suite.ZgChain.QuerySdkForBalances(whale.SdkAddress)
|
||||
suite.cost.erc20BalanceAfter = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
fmt.Println("==BEFORE REFUNDS==")
|
||||
fmt.Println(suite.cost)
|
||||
|
||||
fmt.Println("attempting to return all unused funds")
|
||||
suite.Kava.ReturnAllFunds()
|
||||
suite.ZgChain.ReturnAllFunds()
|
||||
|
||||
fmt.Println("==AFTER REFUNDS==")
|
||||
}
|
||||
|
||||
// calculate & output cost summary for funded account
|
||||
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
|
||||
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
suite.cost.sdkBalanceAfter = suite.ZgChain.QuerySdkForBalances(whale.SdkAddress)
|
||||
suite.cost.erc20BalanceAfter = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||
fmt.Println(suite.cost)
|
||||
|
||||
// close all account request channels
|
||||
suite.Kava.Shutdown()
|
||||
suite.ZgChain.Shutdown()
|
||||
if suite.Ibc != nil {
|
||||
suite.Ibc.Shutdown()
|
||||
}
|
||||
@ -167,19 +167,19 @@ func (suite *E2eTestSuite) TearDownSuite() {
|
||||
// SetupKvtoolNodeRunner is a helper method for building a KvtoolRunnerConfig from the suite config.
|
||||
func (suite *E2eTestSuite) SetupKvtoolNodeRunner() *runner.KvtoolRunner {
|
||||
// upgrade tests are only supported on kvtool networks
|
||||
suite.UpgradeHeight = suite.config.Kvtool.KavaUpgradeHeight
|
||||
suite.UpgradeHeight = suite.config.Kvtool.ZgChainUpgradeHeight
|
||||
suite.enableRefunds = false
|
||||
|
||||
runnerConfig := runner.KvtoolRunnerConfig{
|
||||
KavaConfigTemplate: suite.config.Kvtool.KavaConfigTemplate,
|
||||
ZgChainConfigTemplate: suite.config.Kvtool.ZgChainConfigTemplate,
|
||||
|
||||
IncludeIBC: suite.config.IncludeIbcTests,
|
||||
ImageTag: "local",
|
||||
|
||||
EnableAutomatedUpgrade: suite.config.Kvtool.IncludeAutomatedUpgrade,
|
||||
KavaUpgradeName: suite.config.Kvtool.KavaUpgradeName,
|
||||
KavaUpgradeHeight: suite.config.Kvtool.KavaUpgradeHeight,
|
||||
KavaUpgradeBaseImageTag: suite.config.Kvtool.KavaUpgradeBaseImageTag,
|
||||
EnableAutomatedUpgrade: suite.config.Kvtool.IncludeAutomatedUpgrade,
|
||||
ZgChainUpgradeName: suite.config.Kvtool.ZgChainUpgradeName,
|
||||
ZgChainUpgradeHeight: suite.config.Kvtool.ZgChainUpgradeHeight,
|
||||
ZgChainUpgradeBaseImageTag: suite.config.Kvtool.ZgChainUpgradeBaseImageTag,
|
||||
|
||||
SkipShutdown: suite.config.SkipShutdown,
|
||||
}
|
||||
@ -199,10 +199,10 @@ func (suite *E2eTestSuite) SetupLiveNetworkNodeRunner() *runner.LiveNodeRunner {
|
||||
suite.enableRefunds = true
|
||||
|
||||
runnerConfig := runner.LiveNodeRunnerConfig{
|
||||
KavaRpcUrl: suite.config.LiveNetwork.KavaRpcUrl,
|
||||
KavaGrpcUrl: suite.config.LiveNetwork.KavaGrpcUrl,
|
||||
KavaEvmRpcUrl: suite.config.LiveNetwork.KavaEvmRpcUrl,
|
||||
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
||||
ZgChainRpcUrl: suite.config.LiveNetwork.ZgChainRpcUrl,
|
||||
ZgChainGrpcUrl: suite.config.LiveNetwork.ZgChainGrpcUrl,
|
||||
ZgChainEvmRpcUrl: suite.config.LiveNetwork.ZgChainEvmRpcUrl,
|
||||
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
||||
}
|
||||
|
||||
return runner.NewLiveNodeRunner(runnerConfig)
|
||||
|
@ -8,13 +8,13 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/tests/util"
|
||||
)
|
||||
|
||||
func TestAddressConversion(t *testing.T) {
|
||||
app.SetSDKConfig()
|
||||
bech32Addr := sdk.MustAccAddressFromBech32("kava17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5")
|
||||
chaincfg.SetSDKConfig()
|
||||
bech32Addr := sdk.MustAccAddressFromBech32("0g17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5")
|
||||
hexAddr := common.HexToAddress("0xf354ee99e2bc863cE19d80b843353476394EbC35")
|
||||
require.Equal(t, bech32Addr, util.EvmToSdkAddress(hexAddr))
|
||||
require.Equal(t, hexAddr, util.SdkToEvmAddress(bech32Addr))
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// KavaHomePath returns the OS-specific filepath for the kava home directory
|
||||
// ZgChainHomePath returns the OS-specific filepath for the 0g-chain home directory
|
||||
// Assumes network is running with kvtool installed from the sub-repository in tests/e2e/kvtool
|
||||
func KavaHomePath() string {
|
||||
return filepath.Join("kvtool", "full_configs", "generated", "kava", "initstate", ".kava")
|
||||
func ZgChainHomePath() string {
|
||||
return filepath.Join("kvtool", "full_configs", "generated", "0gchaind", "initstate", ".0gchain")
|
||||
}
|
||||
|
@ -27,18 +27,18 @@ var (
|
||||
ErrUnsuccessfulTx = errors.New("tx committed but returned nonzero code")
|
||||
)
|
||||
|
||||
type KavaMsgRequest struct {
|
||||
type ZgChainMsgRequest struct {
|
||||
Msgs []sdk.Msg
|
||||
GasLimit uint64
|
||||
FeeAmount sdk.Coins
|
||||
Memo string
|
||||
// Arbitrary data to be referenced in the corresponding KavaMsgResponse, unused
|
||||
// in signing. This is mostly useful to match KavaMsgResponses with KavaMsgRequests.
|
||||
// Arbitrary data to be referenced in the corresponding ZgChainMsgResponse, unused
|
||||
// in signing. This is mostly useful to match ZgChainMsgResponses with ZgChainMsgRequests.
|
||||
Data interface{}
|
||||
}
|
||||
|
||||
type KavaMsgResponse struct {
|
||||
Request KavaMsgRequest
|
||||
type ZgChainMsgResponse struct {
|
||||
Request ZgChainMsgRequest
|
||||
Tx authsigning.Tx
|
||||
TxBytes []byte
|
||||
Result sdk.TxResponse
|
||||
@ -55,8 +55,8 @@ const (
|
||||
txResetSequence
|
||||
)
|
||||
|
||||
// KavaSigner broadcasts msgs to a single kava node
|
||||
type KavaSigner struct {
|
||||
// ZgChainSigner broadcasts msgs to a single 0g-chain node
|
||||
type ZgChainSigner struct {
|
||||
chainID string
|
||||
encodingConfig params.EncodingConfig
|
||||
authClient authtypes.QueryClient
|
||||
@ -65,15 +65,15 @@ type KavaSigner struct {
|
||||
inflightTxLimit uint64
|
||||
}
|
||||
|
||||
func NewKavaSigner(
|
||||
func NewZgChainSigner(
|
||||
chainID string,
|
||||
encodingConfig params.EncodingConfig,
|
||||
authClient authtypes.QueryClient,
|
||||
txClient txtypes.ServiceClient,
|
||||
privKey cryptotypes.PrivKey,
|
||||
inflightTxLimit uint64) *KavaSigner {
|
||||
inflightTxLimit uint64) *ZgChainSigner {
|
||||
|
||||
return &KavaSigner{
|
||||
return &ZgChainSigner{
|
||||
chainID: chainID,
|
||||
encodingConfig: encodingConfig,
|
||||
authClient: authClient,
|
||||
@ -83,7 +83,7 @@ func NewKavaSigner(
|
||||
}
|
||||
}
|
||||
|
||||
func (s *KavaSigner) pollAccountState() <-chan authtypes.AccountI {
|
||||
func (s *ZgChainSigner) pollAccountState() <-chan authtypes.AccountI {
|
||||
accountState := make(chan authtypes.AccountI)
|
||||
|
||||
go func() {
|
||||
@ -109,7 +109,7 @@ func (s *KavaSigner) pollAccountState() <-chan authtypes.AccountI {
|
||||
return accountState
|
||||
}
|
||||
|
||||
func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse, error) {
|
||||
func (s *ZgChainSigner) Run(requests <-chan ZgChainMsgRequest) (<-chan ZgChainMsgResponse, error) {
|
||||
// poll account state in it's own goroutine
|
||||
// and send status updates to the signing goroutine
|
||||
//
|
||||
@ -117,15 +117,15 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
||||
// websocket events with a fallback to polling
|
||||
accountState := s.pollAccountState()
|
||||
|
||||
responses := make(chan KavaMsgResponse)
|
||||
responses := make(chan ZgChainMsgResponse)
|
||||
go func() {
|
||||
// wait until account is loaded to start signing
|
||||
account := <-accountState
|
||||
// store current request waiting to be broadcasted
|
||||
var currentRequest *KavaMsgRequest
|
||||
var currentRequest *ZgChainMsgRequest
|
||||
// keep track of all successfully broadcasted txs
|
||||
// index is sequence % inflightTxLimit
|
||||
inflight := make([]*KavaMsgResponse, s.inflightTxLimit)
|
||||
inflight := make([]*ZgChainMsgResponse, s.inflightTxLimit)
|
||||
// used for confirming sent txs only
|
||||
prevDeliverTxSeq := account.GetSequence()
|
||||
// tx sequence of already signed messages
|
||||
@ -252,7 +252,7 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
||||
|
||||
tx, txBytes, err := Sign(s.encodingConfig.TxConfig, s.privKey, txBuilder, signerData)
|
||||
|
||||
response = &KavaMsgResponse{
|
||||
response = &ZgChainMsgResponse{
|
||||
Request: *currentRequest,
|
||||
Tx: tx,
|
||||
TxBytes: txBytes,
|
||||
@ -376,7 +376,7 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
||||
}
|
||||
|
||||
// Address returns the address of the Signer
|
||||
func (s *KavaSigner) Address() sdk.AccAddress {
|
||||
func (s *ZgChainSigner) Address() sdk.AccAddress {
|
||||
return GetAccAddress(s.privKey)
|
||||
}
|
||||
|
||||
|
@ -46,12 +46,12 @@ func ParseOrQueryConversionPairAddress(
|
||||
|
||||
if err := sdk.ValidateDenom(addrOrDenom); err != nil {
|
||||
return common.Address{}, fmt.Errorf(
|
||||
"Kava ERC20 '%s' is not a valid hex address or denom",
|
||||
"0gChain ERC20 '%s' is not a valid hex address or denom",
|
||||
addrOrDenom,
|
||||
)
|
||||
}
|
||||
|
||||
// Valid denom, try looking up as denom to get corresponding Kava ERC20 address
|
||||
// Valid denom, try looking up as denom to get corresponding 0gChain ERC20 address
|
||||
paramsRes, err := queryClient.Params(
|
||||
context.Background(),
|
||||
&types.QueryParamsRequest{},
|
||||
@ -67,7 +67,7 @@ func ParseOrQueryConversionPairAddress(
|
||||
}
|
||||
|
||||
return common.Address{}, fmt.Errorf(
|
||||
"Kava ERC20 '%s' is not a valid hex address or denom (did not match any denoms in queried enabled conversion pairs)",
|
||||
"0gChain ERC20 '%s' is not a valid hex address or denom (did not match any denoms in queried enabled conversion pairs)",
|
||||
addrOrDenom,
|
||||
)
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func GetTxCmd() *cobra.Command {
|
||||
|
||||
func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "convert-evm-erc20-from-coin [Kava EVM address] [coin]",
|
||||
Use: "convert-evm-erc20-from-coin [0gChain EVM address] [coin]",
|
||||
Short: "EVM-native asset: converts a coin on Cosmos co-chain to an ERC20 on EVM co-chain",
|
||||
Example: fmt.Sprintf(
|
||||
`%s tx %s convert-evm-erc20-from-coin 0x7Bbf300890857b8c241b219C6a489431669b3aFA 500000000erc20/usdc --from <key> --gas 2000000`,
|
||||
@ -81,10 +81,10 @@ func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
||||
|
||||
func getCmdConvertEvmERC20ToCoin() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "convert-evm-erc20-to-coin [Kava receiver address] [Kava ERC20 address] [amount]",
|
||||
Use: "convert-evm-erc20-to-coin [0gChain receiver address] [0gChain ERC20 address] [amount]",
|
||||
Short: "EVM-native asset: converts an ERC20 on EVM co-chain to a coin on Cosmos co-chain",
|
||||
Example: fmt.Sprintf(`
|
||||
%[1]s tx %[2]s convert-evm-erc20-to-coin kava10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t 0xeA7100edA2f805356291B0E55DaD448599a72C6d 1000000000000000 --from <key> --gas 1000000
|
||||
%[1]s tx %[2]s convert-evm-erc20-to-coin 0g10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t 0xeA7100edA2f805356291B0E55DaD448599a72C6d 1000000000000000 --from <key> --gas 1000000
|
||||
`, version.AppName, types.ModuleName,
|
||||
),
|
||||
Args: cobra.ExactArgs(3),
|
||||
@ -163,11 +163,11 @@ func getCmdMsgConvertCosmosCoinToERC20() *cobra.Command {
|
||||
|
||||
func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "convert-cosmos-coin-from-erc20 [receiver_kava_address] [amount] [flags]",
|
||||
Use: "convert-cosmos-coin-from-erc20 [receiver_0g_address] [amount] [flags]",
|
||||
Short: "Cosmos-native asset: converts an ERC20 on EVM co-chain back to a coin on Cosmos co-chain",
|
||||
Example: fmt.Sprintf(
|
||||
`Convert ERC20 representation of 500 ATOM back to a Cosmos coin, sending to kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a:
|
||||
%s tx %s convert-cosmos-coin-from-erc20 kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a 500000000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 --from <key> --gas 2000000`,
|
||||
`Convert ERC20 representation of 500 ATOM back to a Cosmos coin, sending to 0g1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a:
|
||||
%s tx %s convert-cosmos-coin-from-erc20 0g1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a 500000000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 --from <key> --gas 2000000`,
|
||||
version.AppName, types.ModuleName,
|
||||
),
|
||||
Args: cobra.ExactArgs(2),
|
||||
@ -179,7 +179,7 @@ func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
||||
|
||||
receiver, err := sdk.AccAddressFromBech32(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("receiver '%s' is an invalid kava address", args[0])
|
||||
return fmt.Errorf("receiver '%s' is an invalid 0g-chain address", args[0])
|
||||
}
|
||||
|
||||
amount, err := sdk.ParseCoinNormalized(args[1])
|
||||
|
@ -98,7 +98,7 @@ func (s *genesisTestSuite) TestExportGenesis() {
|
||||
params.AllowedCosmosDenoms = []types.AllowedCosmosCoinERC20Token{
|
||||
{
|
||||
CosmosDenom: "hard",
|
||||
Name: "Kava EVM HARD",
|
||||
Name: "0gChain EVM HARD",
|
||||
Symbol: "HARD",
|
||||
Decimals: 6,
|
||||
},
|
||||
|
@ -9,56 +9,49 @@ import (
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// EvmDenom is the gas denom used by the evm
|
||||
EvmDenom = "akava"
|
||||
|
||||
// CosmosDenom is the gas denom used by the kava app
|
||||
CosmosDenom = "ukava"
|
||||
)
|
||||
|
||||
// ConversionMultiplier is the conversion multiplier between akava and ukava
|
||||
var ConversionMultiplier = sdkmath.NewInt(1_000_000_000_000)
|
||||
// ConversionMultiplier is the conversion multiplier between neuron and a0gi
|
||||
var ConversionMultiplier = sdkmath.NewInt(chaincfg.ConversionMultiplier)
|
||||
|
||||
var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
||||
|
||||
// EvmBankKeeper is a BankKeeper wrapper for the x/evm module to allow the use
|
||||
// of the 18 decimal akava coin on the evm.
|
||||
// x/evm consumes gas and send coins by minting and burning akava coins in its module
|
||||
// of the 18 decimal neuron coin on the evm.
|
||||
// x/evm consumes gas and send coins by minting and burning neuron coins in its module
|
||||
// account and then sending the funds to the target account.
|
||||
// This keeper uses both the ukava coin and a separate akava balance to manage the
|
||||
// This keeper uses both the a0gi coin and a separate neuron balance to manage the
|
||||
// extra percision needed by the evm.
|
||||
type EvmBankKeeper struct {
|
||||
akavaKeeper Keeper
|
||||
bk types.BankKeeper
|
||||
ak types.AccountKeeper
|
||||
baseKeeper Keeper
|
||||
bk types.BankKeeper
|
||||
ak types.AccountKeeper
|
||||
}
|
||||
|
||||
func NewEvmBankKeeper(akavaKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
||||
func NewEvmBankKeeper(baseKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
||||
return EvmBankKeeper{
|
||||
akavaKeeper: akavaKeeper,
|
||||
bk: bk,
|
||||
ak: ak,
|
||||
baseKeeper: baseKeeper,
|
||||
bk: bk,
|
||||
ak: ak,
|
||||
}
|
||||
}
|
||||
|
||||
// GetBalance returns the total **spendable** balance of akava for a given account by address.
|
||||
// GetBalance returns the total **spendable** balance of neuron for a given account by address.
|
||||
func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
||||
if denom != EvmDenom {
|
||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", EvmDenom))
|
||||
if denom != chaincfg.BaseDenom {
|
||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.BaseDenom))
|
||||
}
|
||||
|
||||
spendableCoins := k.bk.SpendableCoins(ctx, addr)
|
||||
ukava := spendableCoins.AmountOf(CosmosDenom)
|
||||
akava := k.akavaKeeper.GetBalance(ctx, addr)
|
||||
total := ukava.Mul(ConversionMultiplier).Add(akava)
|
||||
return sdk.NewCoin(EvmDenom, total)
|
||||
a0gi := spendableCoins.AmountOf(chaincfg.DisplayDenom)
|
||||
neuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||
total := a0gi.Mul(ConversionMultiplier).Add(neuron)
|
||||
return sdk.NewCoin(chaincfg.BaseDenom, total)
|
||||
}
|
||||
|
||||
// SendCoins transfers akava coins from a AccAddress to an AccAddress.
|
||||
// SendCoins transfers neuron coins from a AccAddress to an AccAddress.
|
||||
func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
||||
// SendCoins method is not used by the evm module, but is required by the
|
||||
// evmtypes.BankKeeper interface. This must be updated if the evm module
|
||||
@ -66,101 +59,101 @@ func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, rec
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// SendCoinsFromModuleToAccount transfers akava coins from a ModuleAccount to an AccAddress.
|
||||
// SendCoinsFromModuleToAccount transfers neuron coins from a ModuleAccount to an AccAddress.
|
||||
// It will panic if the module account does not exist. An error is returned if the recipient
|
||||
// address is black-listed or if sending the tokens fails.
|
||||
func (k EvmBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
||||
ukava, akava, err := SplitAkavaCoins(amt)
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ukava.Amount.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(ukava)); err != nil {
|
||||
if a0gi.Amount.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
senderAddr := k.GetModuleAddress(senderModule)
|
||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, senderAddr, akava); err != nil {
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := k.akavaKeeper.SendBalance(ctx, senderAddr, recipientAddr, akava); err != nil {
|
||||
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// SendCoinsFromAccountToModule transfers akava coins from an AccAddress to a ModuleAccount.
|
||||
// SendCoinsFromAccountToModule transfers neuron coins from an AccAddress to a ModuleAccount.
|
||||
// It will panic if the module account does not exist.
|
||||
func (k EvmBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error {
|
||||
ukava, akavaNeeded, err := SplitAkavaCoins(amt)
|
||||
a0gi, neuronNeeded, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ukava.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(ukava)); err != nil {
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, senderAddr, akavaNeeded); err != nil {
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
recipientAddr := k.GetModuleAddress(recipientModule)
|
||||
if err := k.akavaKeeper.SendBalance(ctx, senderAddr, recipientAddr, akavaNeeded); err != nil {
|
||||
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuronNeeded); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// MintCoins mints akava coins by minting the equivalent ukava coins and any remaining akava coins.
|
||||
// MintCoins mints neuron coins by minting the equivalent a0gi coins and any remaining neuron coins.
|
||||
// It will panic if the module account does not exist or is unauthorized.
|
||||
func (k EvmBankKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
||||
ukava, akava, err := SplitAkavaCoins(amt)
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ukava.IsPositive() {
|
||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(ukava)); err != nil {
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
recipientAddr := k.GetModuleAddress(moduleName)
|
||||
if err := k.akavaKeeper.AddBalance(ctx, recipientAddr, akava); err != nil {
|
||||
if err := k.baseKeeper.AddBalance(ctx, recipientAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
||||
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||
}
|
||||
|
||||
// BurnCoins burns akava coins by burning the equivalent ukava coins and any remaining akava coins.
|
||||
// BurnCoins burns neuron coins by burning the equivalent a0gi coins and any remaining neuron coins.
|
||||
// It will panic if the module account does not exist or is unauthorized.
|
||||
func (k EvmBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
||||
ukava, akava, err := SplitAkavaCoins(amt)
|
||||
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ukava.IsPositive() {
|
||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(ukava)); err != nil {
|
||||
if a0gi.IsPositive() {
|
||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
moduleAddr := k.GetModuleAddress(moduleName)
|
||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, moduleAddr, akava); err != nil {
|
||||
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, moduleAddr, neuron); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return k.akavaKeeper.RemoveBalance(ctx, moduleAddr, akava)
|
||||
return k.baseKeeper.RemoveBalance(ctx, moduleAddr, neuron)
|
||||
}
|
||||
|
||||
// IsSendEnabledCoins checks the coins provided and returns an ErrSendDisabled
|
||||
@ -173,51 +166,51 @@ func (k EvmBankKeeper) IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) er
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// ConvertOneUkavaToAkavaIfNeeded converts 1 ukava to akava for an address if
|
||||
// its akava balance is smaller than the akavaNeeded amount.
|
||||
func (k EvmBankKeeper) ConvertOneUkavaToAkavaIfNeeded(ctx sdk.Context, addr sdk.AccAddress, akavaNeeded sdkmath.Int) error {
|
||||
akavaBal := k.akavaKeeper.GetBalance(ctx, addr)
|
||||
if akavaBal.GTE(akavaNeeded) {
|
||||
// ConvertOneA0giToNeuronIfNeeded converts 1 a0gi to neuron for an address if
|
||||
// its neuron balance is smaller than the neuronNeeded amount.
|
||||
func (k EvmBankKeeper) ConvertOneA0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error {
|
||||
neuronBal := k.baseKeeper.GetBalance(ctx, addr)
|
||||
if neuronBal.GTE(neuronNeeded) {
|
||||
return nil
|
||||
}
|
||||
|
||||
ukavaToStore := sdk.NewCoins(sdk.NewCoin(CosmosDenom, sdk.OneInt()))
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, ukavaToStore); err != nil {
|
||||
a0giToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdk.OneInt()))
|
||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, a0giToStore); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// add 1ukava equivalent of akava to addr
|
||||
akavaToReceive := ConversionMultiplier
|
||||
if err := k.akavaKeeper.AddBalance(ctx, addr, akavaToReceive); err != nil {
|
||||
// add 1a0gi equivalent of neuron to addr
|
||||
neuronToReceive := ConversionMultiplier
|
||||
if err := k.baseKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ConvertAkavaToUkava converts all available akava to ukava for a given AccAddress.
|
||||
func (k EvmBankKeeper) ConvertAkavaToUkava(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||
totalAkava := k.akavaKeeper.GetBalance(ctx, addr)
|
||||
ukava, _, err := SplitAkavaCoins(sdk.NewCoins(sdk.NewCoin(EvmDenom, totalAkava)))
|
||||
// ConvertNeuronToA0gi converts all available neuron to a0gi for a given AccAddress.
|
||||
func (k EvmBankKeeper) ConvertNeuronToA0gi(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||
totalNeuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||
a0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, totalNeuron)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// do nothing if account does not have enough akava for a single ukava
|
||||
ukavaToReceive := ukava.Amount
|
||||
if !ukavaToReceive.IsPositive() {
|
||||
// do nothing if account does not have enough neuron for a single a0gi
|
||||
a0giToReceive := a0gi.Amount
|
||||
if !a0giToReceive.IsPositive() {
|
||||
return nil
|
||||
}
|
||||
|
||||
// remove akava used for converting to ukava
|
||||
akavaToBurn := ukavaToReceive.Mul(ConversionMultiplier)
|
||||
finalBal := totalAkava.Sub(akavaToBurn)
|
||||
if err := k.akavaKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||
// remove neuron used for converting to a0gi
|
||||
neuronToBurn := a0giToReceive.Mul(ConversionMultiplier)
|
||||
finalBal := totalNeuron.Sub(neuronToBurn)
|
||||
if err := k.baseKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fromAddr := k.GetModuleAddress(types.ModuleName)
|
||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(ukava)); err != nil {
|
||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(a0gi)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -232,35 +225,35 @@ func (k EvmBankKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
|
||||
return addr
|
||||
}
|
||||
|
||||
// SplitAkavaCoins splits akava coins to the equivalent ukava coins and any remaining akava balance.
|
||||
// An error will be returned if the coins are not valid or if the coins are not the akava denom.
|
||||
func SplitAkavaCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
akava := sdk.ZeroInt()
|
||||
ukava := sdk.NewCoin(CosmosDenom, sdk.ZeroInt())
|
||||
// SplitNeuronCoins splits neuron coins to the equivalent a0gi coins and any remaining neuron balance.
|
||||
// An error will be returned if the coins are not valid or if the coins are not the neuron denom.
|
||||
func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||
neuron := sdk.ZeroInt()
|
||||
a0gi := sdk.NewCoin(chaincfg.DisplayDenom, sdk.ZeroInt())
|
||||
|
||||
if len(coins) == 0 {
|
||||
return ukava, akava, nil
|
||||
return a0gi, neuron, nil
|
||||
}
|
||||
|
||||
if err := ValidateEvmCoins(coins); err != nil {
|
||||
return ukava, akava, err
|
||||
return a0gi, neuron, err
|
||||
}
|
||||
|
||||
// note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate.
|
||||
coin := coins[0]
|
||||
remainingBalance := coin.Amount.Mod(ConversionMultiplier)
|
||||
if remainingBalance.IsPositive() {
|
||||
akava = remainingBalance
|
||||
neuron = remainingBalance
|
||||
}
|
||||
ukavaAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||
if ukavaAmount.IsPositive() {
|
||||
ukava = sdk.NewCoin(CosmosDenom, ukavaAmount)
|
||||
a0giAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||
if a0giAmount.IsPositive() {
|
||||
a0gi = sdk.NewCoin(chaincfg.DisplayDenom, a0giAmount)
|
||||
}
|
||||
|
||||
return ukava, akava, nil
|
||||
return a0gi, neuron, nil
|
||||
}
|
||||
|
||||
// ValidateEvmCoins validates the coins from evm is valid and is the EvmDenom (akava).
|
||||
// ValidateEvmCoins validates the coins from evm is valid and is the chaincfg.BaseDenom (neuron).
|
||||
func ValidateEvmCoins(coins sdk.Coins) error {
|
||||
if len(coins) == 0 {
|
||||
return nil
|
||||
@ -271,9 +264,9 @@ func ValidateEvmCoins(coins sdk.Coins) error {
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
|
||||
}
|
||||
|
||||
// validate that coin denom is akava
|
||||
if len(coins) != 1 || coins[0].Denom != EvmDenom {
|
||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", EvmDenom)
|
||||
// validate that coin denom is neuron
|
||||
if len(coins) != 1 || coins[0].Denom != chaincfg.BaseDenom {
|
||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.BaseDenom)
|
||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
@ -27,8 +28,8 @@ func (suite *evmBankKeeperTestSuite) SetupTest() {
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
||||
startingCoins := sdk.NewCoins(sdk.NewInt64Coin("ukava", 10))
|
||||
startingAkava := sdkmath.NewInt(100)
|
||||
startingCoins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10))
|
||||
startingNeuron := sdkmath.NewInt(100)
|
||||
|
||||
now := tmtime.Now()
|
||||
endTime := now.Add(24 * time.Hour)
|
||||
@ -38,20 +39,20 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
||||
|
||||
err := suite.App.FundAccount(suite.Ctx, suite.Addrs[0], startingCoins)
|
||||
suite.Require().NoError(err)
|
||||
err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingAkava)
|
||||
err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingNeuron)
|
||||
suite.Require().NoError(err)
|
||||
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "akava")
|
||||
suite.Require().Equal(startingAkava, coin.Amount)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
suite.Require().Equal(startingNeuron, coin.Amount)
|
||||
|
||||
ctx := suite.Ctx.WithBlockTime(now.Add(12 * time.Hour))
|
||||
coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], "akava")
|
||||
coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
suite.Require().Equal(sdkmath.NewIntFromUint64(5_000_000_000_100), coin.Amount)
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_NotEvmDenom() {
|
||||
suite.Require().Panics(func() {
|
||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
})
|
||||
suite.Require().Panics(func() {
|
||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "busd")
|
||||
@ -65,39 +66,39 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
expAmount sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"ukava with akava",
|
||||
"a0gi with neuron",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 100),
|
||||
sdk.NewInt64Coin("ukava", 10),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 10),
|
||||
),
|
||||
sdkmath.NewInt(10_000_000_000_100),
|
||||
},
|
||||
{
|
||||
"just akava",
|
||||
"just neuron",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 100),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin("busd", 100),
|
||||
),
|
||||
sdkmath.NewInt(100),
|
||||
},
|
||||
{
|
||||
"just ukava",
|
||||
"just a0gi",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("ukava", 10),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 10),
|
||||
sdk.NewInt64Coin("busd", 100),
|
||||
),
|
||||
sdkmath.NewInt(10_000_000_000_000),
|
||||
},
|
||||
{
|
||||
"no ukava or akava",
|
||||
"no a0gi or neuron",
|
||||
sdk.NewCoins(),
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"with avaka that is more than 1 ukava",
|
||||
"with avaka that is more than 1 a0gi",
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 20_000_000_000_220),
|
||||
sdk.NewInt64Coin("ukava", 11),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 20_000_000_000_220),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 11),
|
||||
),
|
||||
sdkmath.NewInt(31_000_000_000_220),
|
||||
},
|
||||
@ -107,8 +108,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingAmount)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "akava")
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAmount)
|
||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||
suite.Require().Equal(tt.expAmount, coin.Amount)
|
||||
})
|
||||
}
|
||||
@ -116,8 +117,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
startingModuleCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 200),
|
||||
sdk.NewInt64Coin("ukava", 100),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||
)
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -127,102 +128,102 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
hasErr bool
|
||||
}{
|
||||
{
|
||||
"send more than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_010)),
|
||||
"send more than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 10),
|
||||
sdk.NewInt64Coin("ukava", 12),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 10),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 12),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send less than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
||||
"send less than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 122),
|
||||
sdk.NewInt64Coin("ukava", 0),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 122),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 0),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send an exact amount of ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
||||
"send an exact amount of a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 0o0),
|
||||
sdk.NewInt64Coin("ukava", 98),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 0o0),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 98),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send no akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
||||
"send no neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
sdk.Coins{},
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 0),
|
||||
sdk.NewInt64Coin("ukava", 0),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 0),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 0),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"errors if sending other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough total akava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_001_000)),
|
||||
"errors if not enough total neuron to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough ukava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
||||
"errors if not enough a0gi to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"converts receiver's akava to ukava if there's enough akava after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_000_000_000_200)),
|
||||
"converts receiver's neuron to a0gi if there's enough neuron after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_000_200)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 999_999_999_900),
|
||||
sdk.NewInt64Coin("ukava", 1),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 999_999_999_900),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 100),
|
||||
sdk.NewInt64Coin("ukava", 101),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 101),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts all of receiver's akava to ukava even if somehow receiver has more than 1ukava of akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_100)),
|
||||
"converts all of receiver's neuron to a0gi even if somehow receiver has more than 1a0gi of neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_100)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 5_999_999_999_990),
|
||||
sdk.NewInt64Coin("ukava", 1),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 5_999_999_999_990),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 90),
|
||||
sdk.NewInt64Coin("ukava", 19),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 90),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 19),
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"swap 1 ukava for akava if module account doesn't have enough akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_000_000_001_000)),
|
||||
"swap 1 a0gi for neuron if module account doesn't have enough neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_001_000)),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 200),
|
||||
sdk.NewInt64Coin("ukava", 1),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||
),
|
||||
sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 1200),
|
||||
sdk.NewInt64Coin("ukava", 100),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 1200),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||
),
|
||||
false,
|
||||
},
|
||||
@ -232,11 +233,11 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingAccBal)
|
||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingModuleCoins)
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAccBal)
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||
|
||||
// fund our module with some ukava to account for converting extra akava back to ukava
|
||||
suite.FundModuleAccountWithKava(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
||||
// fund our module with some a0gi to account for converting extra neuron back to a0gi
|
||||
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||
|
||||
err := suite.EvmBankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, evmtypes.ModuleName, suite.Addrs[0], tt.sendCoins)
|
||||
if tt.hasErr {
|
||||
@ -246,24 +247,24 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check ukava
|
||||
ukavaSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
||||
// check a0gi
|
||||
a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||
|
||||
// check akava
|
||||
actualAkava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf("akava").Int64(), actualAkava.Int64())
|
||||
// check neuron
|
||||
actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
startingAccCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 200),
|
||||
sdk.NewInt64Coin("ukava", 100),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||
)
|
||||
startingModuleCoins := sdk.NewCoins(
|
||||
sdk.NewInt64Coin("akava", 100_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000),
|
||||
)
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -273,36 +274,36 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
hasErr bool
|
||||
}{
|
||||
{
|
||||
"send more than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_010)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 190), sdk.NewInt64Coin("ukava", 88)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_010), sdk.NewInt64Coin("ukava", 12)),
|
||||
"send more than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 190), sdk.NewInt64Coin(chaincfg.DisplayDenom, 88)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_010), sdk.NewInt64Coin(chaincfg.DisplayDenom, 12)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send less than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 78), sdk.NewInt64Coin("ukava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_122), sdk.NewInt64Coin("ukava", 0)),
|
||||
"send less than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 78), sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_122), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send an exact amount of ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 2)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 98)),
|
||||
"send an exact amount of a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 2)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 98)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"send no akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 0)),
|
||||
"send no neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"errors if sending other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
@ -310,39 +311,39 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
},
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough total akava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_001_000)),
|
||||
"errors if not enough total neuron to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"errors if not enough ukava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
||||
"errors if not enough a0gi to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
sdk.Coins{},
|
||||
sdk.Coins{},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"converts 1 ukava to akava if not enough akava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_001_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 999_000_000_200), sdk.NewInt64Coin("ukava", 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 101_000_000_000), sdk.NewInt64Coin("ukava", 99)),
|
||||
"converts 1 a0gi to neuron if not enough neuron to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_001_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 999_000_000_200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 101_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 99)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts receiver's akava to ukava if there's enough akava after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 5_900_000_000_200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 94)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 6)),
|
||||
"converts receiver's neuron to a0gi if there's enough neuron after the transfer",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_900_000_000_200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 94)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 6)),
|
||||
false,
|
||||
},
|
||||
}
|
||||
@ -350,8 +351,8 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
suite.FundAccountWithKava(suite.Addrs[0], startingAccCoins)
|
||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingModuleCoins)
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], startingAccCoins)
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||
|
||||
err := suite.EvmBankKeeper.SendCoinsFromAccountToModule(suite.Ctx, suite.Addrs[0], evmtypes.ModuleName, tt.sendCoins)
|
||||
if tt.hasErr {
|
||||
@ -362,67 +363,67 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||
}
|
||||
|
||||
// check sender balance
|
||||
ukavaSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
||||
actualAkava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf("akava").Int64(), actualAkava.Int64())
|
||||
a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||
actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||
|
||||
// check module balance
|
||||
moduleAddr := suite.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
|
||||
ukavaSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, "ukava")
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
||||
actualAkava = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf("akava").Int64(), actualAkava.Int64())
|
||||
a0giSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||
actualNeuron = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
||||
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
startingUkava := sdkmath.NewInt(100)
|
||||
startingA0gi := sdkmath.NewInt(100)
|
||||
tests := []struct {
|
||||
name string
|
||||
burnCoins sdk.Coins
|
||||
expUkava sdkmath.Int
|
||||
expAkava sdkmath.Int
|
||||
hasErr bool
|
||||
akavaStart sdkmath.Int
|
||||
name string
|
||||
burnCoins sdk.Coins
|
||||
expA0gi sdkmath.Int
|
||||
expNeuron sdkmath.Int
|
||||
hasErr bool
|
||||
neuronStart sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"burn more than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
||||
"burn more than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(88),
|
||||
sdkmath.NewInt(100_000_000_000),
|
||||
false,
|
||||
sdkmath.NewInt(121_000_000_002),
|
||||
},
|
||||
{
|
||||
"burn less than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
||||
"burn less than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||
sdkmath.NewInt(100),
|
||||
sdkmath.NewInt(878),
|
||||
false,
|
||||
sdkmath.NewInt(1000),
|
||||
},
|
||||
{
|
||||
"burn an exact amount of ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
||||
"burn an exact amount of a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||
sdkmath.NewInt(2),
|
||||
sdkmath.NewInt(10),
|
||||
false,
|
||||
sdkmath.NewInt(10),
|
||||
},
|
||||
{
|
||||
"burn no akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
||||
startingUkava,
|
||||
"burn no neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
startingA0gi,
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"errors if burning other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
startingUkava,
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
startingA0gi,
|
||||
sdkmath.NewInt(100),
|
||||
true,
|
||||
sdkmath.NewInt(100),
|
||||
@ -430,41 +431,41 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
},
|
||||
startingUkava,
|
||||
startingA0gi,
|
||||
sdk.ZeroInt(),
|
||||
true,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"errors if burn amount is negative",
|
||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-100)}},
|
||||
startingUkava,
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||
startingA0gi,
|
||||
sdkmath.NewInt(50),
|
||||
true,
|
||||
sdkmath.NewInt(50),
|
||||
},
|
||||
{
|
||||
"errors if not enough akava to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_999_000_000_000)),
|
||||
"errors if not enough neuron to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_999_000_000_000)),
|
||||
sdkmath.NewInt(0),
|
||||
sdkmath.NewInt(99_000_000_000),
|
||||
true,
|
||||
sdkmath.NewInt(99_000_000_000),
|
||||
},
|
||||
{
|
||||
"errors if not enough ukava to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
||||
"errors if not enough a0gi to cover burn",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||
sdkmath.NewInt(100),
|
||||
sdk.ZeroInt(),
|
||||
true,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"converts 1 ukava to akava if not enough akava to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
||||
"converts 1 a0gi to neuron if not enough neuron to cover",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(87),
|
||||
sdkmath.NewInt(980_000_000_000),
|
||||
false,
|
||||
@ -476,10 +477,10 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
startingCoins := sdk.NewCoins(
|
||||
sdk.NewCoin("ukava", startingUkava),
|
||||
sdk.NewCoin("akava", tt.akavaStart),
|
||||
sdk.NewCoin(chaincfg.DisplayDenom, startingA0gi),
|
||||
sdk.NewCoin(chaincfg.BaseDenom, tt.neuronStart),
|
||||
)
|
||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingCoins)
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingCoins)
|
||||
|
||||
err := suite.EvmBankKeeper.BurnCoins(suite.Ctx, evmtypes.ModuleName, tt.burnCoins)
|
||||
if tt.hasErr {
|
||||
@ -489,53 +490,53 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check ukava
|
||||
ukavaActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ukava")
|
||||
suite.Require().Equal(tt.expUkava, ukavaActual.Amount)
|
||||
// check a0gi
|
||||
a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expA0gi, a0giActual.Amount)
|
||||
|
||||
// check akava
|
||||
akavaActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.expAkava, akavaActual)
|
||||
// check neuron
|
||||
neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.expNeuron, neuronActual)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
tests := []struct {
|
||||
name string
|
||||
mintCoins sdk.Coins
|
||||
ukava sdkmath.Int
|
||||
akava sdkmath.Int
|
||||
hasErr bool
|
||||
akavaStart sdkmath.Int
|
||||
name string
|
||||
mintCoins sdk.Coins
|
||||
a0gi sdkmath.Int
|
||||
neuron sdkmath.Int
|
||||
hasErr bool
|
||||
neuronStart sdkmath.Int
|
||||
}{
|
||||
{
|
||||
"mint more than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
||||
"mint more than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(21_000_000_002),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint less than 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 901_000_000_001)),
|
||||
"mint less than 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 901_000_000_001)),
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(901_000_000_001),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint an exact amount of ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 123_000_000_000_000_000)),
|
||||
"mint an exact amount of a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 123_000_000_000_000_000)),
|
||||
sdkmath.NewInt(123_000),
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
sdk.ZeroInt(),
|
||||
},
|
||||
{
|
||||
"mint no akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
||||
"mint no neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||
sdk.ZeroInt(),
|
||||
sdk.ZeroInt(),
|
||||
false,
|
||||
@ -543,7 +544,7 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
},
|
||||
{
|
||||
"errors if minting other coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(100),
|
||||
true,
|
||||
@ -552,8 +553,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
{
|
||||
"errors if have dup coins",
|
||||
sdk.Coins{
|
||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||
},
|
||||
sdk.ZeroInt(),
|
||||
sdk.ZeroInt(),
|
||||
@ -562,23 +563,23 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
},
|
||||
{
|
||||
"errors if mint amount is negative",
|
||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-100)}},
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||
sdk.ZeroInt(),
|
||||
sdkmath.NewInt(50),
|
||||
true,
|
||||
sdkmath.NewInt(50),
|
||||
},
|
||||
{
|
||||
"adds to existing akava balance",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
||||
"adds to existing neuron balance",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(21_000_000_102),
|
||||
false,
|
||||
sdkmath.NewInt(100),
|
||||
},
|
||||
{
|
||||
"convert akava balance to ukava if it exceeds 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_999_000_000_000)),
|
||||
"convert neuron balance to a0gi if it exceeds 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_999_000_000_000)),
|
||||
sdkmath.NewInt(12),
|
||||
sdkmath.NewInt(1_200_000_001),
|
||||
false,
|
||||
@ -589,8 +590,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
suite.FundModuleAccountWithKava(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin("akava", tt.akavaStart)))
|
||||
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, tt.neuronStart)))
|
||||
|
||||
err := suite.EvmBankKeeper.MintCoins(suite.Ctx, evmtypes.ModuleName, tt.mintCoins)
|
||||
if tt.hasErr {
|
||||
@ -600,13 +601,13 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
|
||||
// check ukava
|
||||
ukavaActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ukava")
|
||||
suite.Require().Equal(tt.ukava, ukavaActual.Amount)
|
||||
// check a0gi
|
||||
a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.a0gi, a0giActual.Amount)
|
||||
|
||||
// check akava
|
||||
akavaActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.akava, akavaActual)
|
||||
// check neuron
|
||||
neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||
suite.Require().Equal(tt.neuron, neuronActual)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -619,22 +620,22 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
||||
}{
|
||||
{
|
||||
"valid coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"dup coins",
|
||||
sdk.Coins{sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("akava", 500)},
|
||||
sdk.Coins{sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin(chaincfg.BaseDenom, 500)},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"not evm coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 500)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"negative coins",
|
||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-500)}},
|
||||
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-500)}},
|
||||
true,
|
||||
},
|
||||
}
|
||||
@ -650,8 +651,8 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
||||
akavaNeeded := sdkmath.NewInt(200)
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertOneA0giToNeuronIfNeeded() {
|
||||
neuronNeeded := sdkmath.NewInt(200)
|
||||
tests := []struct {
|
||||
name string
|
||||
startingCoins sdk.Coins
|
||||
@ -659,21 +660,21 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
||||
success bool
|
||||
}{
|
||||
{
|
||||
"not enough ukava for conversion",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
||||
"not enough a0gi for conversion",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"converts 1 ukava to akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 9), sdk.NewInt64Coin("akava", 1_000_000_000_100)),
|
||||
"converts 1 a0gi to neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 9), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_100)),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"conversion not needed",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||
true,
|
||||
},
|
||||
}
|
||||
@ -681,67 +682,67 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingCoins)
|
||||
err := suite.EvmBankKeeper.ConvertOneUkavaToAkavaIfNeeded(suite.Ctx, suite.Addrs[0], akavaNeeded)
|
||||
moduleKava := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), "ukava")
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||
err := suite.EvmBankKeeper.ConvertOneA0giToNeuronIfNeeded(suite.Ctx, suite.Addrs[0], neuronNeeded)
|
||||
moduleZgChain := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), chaincfg.DisplayDenom)
|
||||
if tt.success {
|
||||
suite.Require().NoError(err)
|
||||
if tt.startingCoins.AmountOf("akava").LT(akavaNeeded) {
|
||||
suite.Require().Equal(sdk.OneInt(), moduleKava.Amount)
|
||||
if tt.startingCoins.AmountOf(chaincfg.BaseDenom).LT(neuronNeeded) {
|
||||
suite.Require().Equal(sdk.OneInt(), moduleZgChain.Amount)
|
||||
}
|
||||
} else {
|
||||
suite.Require().Error(err)
|
||||
suite.Require().Equal(sdk.ZeroInt(), moduleKava.Amount)
|
||||
suite.Require().Equal(sdk.ZeroInt(), moduleZgChain.Amount)
|
||||
}
|
||||
|
||||
akava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
||||
ukava := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
||||
neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||
a0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertAkavaToUkava() {
|
||||
func (suite *evmBankKeeperTestSuite) TestConvertNeuronToA0gi() {
|
||||
tests := []struct {
|
||||
name string
|
||||
startingCoins sdk.Coins
|
||||
expectedCoins sdk.Coins
|
||||
}{
|
||||
{
|
||||
"not enough ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100), sdk.NewInt64Coin("ukava", 0)),
|
||||
"not enough a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||
},
|
||||
{
|
||||
"converts akava for 1 ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 1_000_000_000_003)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 11), sdk.NewInt64Coin("akava", 3)),
|
||||
"converts neuron for 1 a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_003)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 11), sdk.NewInt64Coin(chaincfg.BaseDenom, 3)),
|
||||
},
|
||||
{
|
||||
"converts more than 1 ukava of akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 18), sdk.NewInt64Coin("akava", 123)),
|
||||
"converts more than 1 a0gi of neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 18), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
suite.SetupTest()
|
||||
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||
suite.Require().NoError(err)
|
||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingCoins)
|
||||
err = suite.EvmBankKeeper.ConvertAkavaToUkava(suite.Ctx, suite.Addrs[0])
|
||||
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||
err = suite.EvmBankKeeper.ConvertNeuronToA0gi(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().NoError(err)
|
||||
akava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
||||
ukava := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
||||
neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||
a0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
||||
func (suite *evmBankKeeperTestSuite) TestSplitNeuronCoins() {
|
||||
tests := []struct {
|
||||
name string
|
||||
coins sdk.Coins
|
||||
@ -750,7 +751,7 @@ func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
||||
}{
|
||||
{
|
||||
"invalid coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 500)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 500)),
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
@ -761,33 +762,33 @@ func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
||||
false,
|
||||
},
|
||||
{
|
||||
"ukava & akava coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 8), sdk.NewInt64Coin("akava", 123)),
|
||||
"a0gi & neuron coins",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 8), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"only akava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_123)),
|
||||
"only neuron",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"only ukava",
|
||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 5_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 5)),
|
||||
"only a0gi",
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_000_000_000_000)),
|
||||
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 5)),
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
suite.Run(tt.name, func() {
|
||||
ukava, akava, err := keeper.SplitAkavaCoins(tt.coins)
|
||||
a0gi, neuron, err := keeper.SplitNeuronCoins(tt.coins)
|
||||
if tt.shouldErr {
|
||||
suite.Require().Error(err)
|
||||
} else {
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ func (suite *convertCosmosCoinToERC20Suite) TestConvertCosmosCoinToERC20() {
|
||||
caller, key := testutil.RandomEvmAccount()
|
||||
query := func(method string, args ...interface{}) ([]interface{}, error) {
|
||||
return suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
key,
|
||||
contractAddress,
|
||||
@ -90,7 +90,7 @@ func (suite *convertCosmosCoinToERC20Suite) TestConvertCosmosCoinToERC20() {
|
||||
// make the denom allowed for conversion
|
||||
params := suite.Keeper.GetParams(suite.Ctx)
|
||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||
)
|
||||
suite.Keeper.SetParams(suite.Ctx, params)
|
||||
|
||||
@ -215,7 +215,7 @@ func (suite *convertCosmosCoinFromERC20Suite) SetupTest() {
|
||||
caller, key := testutil.RandomEvmAccount()
|
||||
suite.query = func(method string, args ...interface{}) ([]interface{}, error) {
|
||||
return suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
key,
|
||||
suite.contractAddress,
|
||||
|
@ -43,7 +43,7 @@ func (suite *Bep3ConversionTestSuite) setEnabledConversionPairDenom(denom string
|
||||
}
|
||||
|
||||
func (suite *Bep3ConversionTestSuite) testConvertBep3CoinToERC20(denom string) {
|
||||
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||
invoker, err := sdk.AccAddressFromBech32("0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||
receiverAddr := testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
|
@ -68,10 +68,10 @@ func (k Keeper) DeployTestMintableERC20Contract(
|
||||
return types.NewInternalEVMAddress(contractAddr), nil
|
||||
}
|
||||
|
||||
// DeployKavaWrappedCosmosCoinERC20Contract validates token details and then deploys an ERC20
|
||||
// DeployZgChainWrappedCosmosCoinERC20Contract validates token details and then deploys an ERC20
|
||||
// contract with the token metadata.
|
||||
// This method does NOT check if a token for the provided SdkDenom has already been deployed.
|
||||
func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
||||
func (k Keeper) DeployZgChainWrappedCosmosCoinERC20Contract(
|
||||
ctx sdk.Context,
|
||||
token types.AllowedCosmosCoinERC20Token,
|
||||
) (types.InternalEVMAddress, error) {
|
||||
@ -79,7 +79,7 @@ func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
||||
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to deploy erc20 for sdk denom %s", token.CosmosDenom)
|
||||
}
|
||||
|
||||
packedAbi, err := types.ERC20KavaWrappedCosmosCoinContract.ABI.Pack(
|
||||
packedAbi, err := types.ERC20ZgChainWrappedCosmosCoinContract.ABI.Pack(
|
||||
"", // Empty string for contract constructor
|
||||
token.Name,
|
||||
token.Symbol,
|
||||
@ -89,13 +89,13 @@ func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
||||
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to pack token with details %+v", token)
|
||||
}
|
||||
|
||||
data := make([]byte, len(types.ERC20KavaWrappedCosmosCoinContract.Bin)+len(packedAbi))
|
||||
data := make([]byte, len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin)+len(packedAbi))
|
||||
copy(
|
||||
data[:len(types.ERC20KavaWrappedCosmosCoinContract.Bin)],
|
||||
types.ERC20KavaWrappedCosmosCoinContract.Bin,
|
||||
data[:len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin)],
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.Bin,
|
||||
)
|
||||
copy(
|
||||
data[len(types.ERC20KavaWrappedCosmosCoinContract.Bin):],
|
||||
data[len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin):],
|
||||
packedAbi,
|
||||
)
|
||||
|
||||
@ -126,7 +126,7 @@ func (k *Keeper) GetOrDeployCosmosCoinERC20Contract(
|
||||
}
|
||||
|
||||
// deploy a new contract
|
||||
contractAddress, err := k.DeployKavaWrappedCosmosCoinERC20Contract(ctx, tokenInfo)
|
||||
contractAddress, err := k.DeployZgChainWrappedCosmosCoinERC20Contract(ctx, tokenInfo)
|
||||
if err != nil {
|
||||
return contractAddress, err
|
||||
}
|
||||
@ -170,7 +170,7 @@ func (k Keeper) BurnERC20(
|
||||
) error {
|
||||
_, err := k.CallEVM(
|
||||
ctx,
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
types.ModuleEVMAddress,
|
||||
contractAddr,
|
||||
erc20BurnMethod,
|
||||
@ -213,7 +213,7 @@ func (k Keeper) QueryERC20TotalSupply(
|
||||
) (*big.Int, error) {
|
||||
res, err := k.CallEVM(
|
||||
ctx,
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
types.ModuleEVMAddress,
|
||||
contractAddr,
|
||||
erc20TotalSupplyMethod,
|
||||
|
@ -107,11 +107,11 @@ func (suite *ERC20TestSuite) TestQueryERC20TotalSupply() {
|
||||
})
|
||||
}
|
||||
|
||||
func (suite *ERC20TestSuite) TestDeployKavaWrappedCosmosCoinERC20Contract() {
|
||||
func (suite *ERC20TestSuite) TestDeployZgChainWrappedCosmosCoinERC20Contract() {
|
||||
suite.Run("fails to deploy invalid contract", func() {
|
||||
// empty other fields means this token is invalid.
|
||||
invalidToken := types.AllowedCosmosCoinERC20Token{CosmosDenom: "nope"}
|
||||
_, err := suite.Keeper.DeployKavaWrappedCosmosCoinERC20Contract(suite.Ctx, invalidToken)
|
||||
_, err := suite.Keeper.DeployZgChainWrappedCosmosCoinERC20Contract(suite.Ctx, invalidToken)
|
||||
suite.ErrorContains(err, "token's name cannot be empty")
|
||||
})
|
||||
|
||||
@ -119,13 +119,13 @@ func (suite *ERC20TestSuite) TestDeployKavaWrappedCosmosCoinERC20Contract() {
|
||||
caller, privKey := testutil.RandomEvmAccount()
|
||||
|
||||
token := types.NewAllowedCosmosCoinERC20Token("hard", "EVM HARD", "HARD", 6)
|
||||
addr, err := suite.Keeper.DeployKavaWrappedCosmosCoinERC20Contract(suite.Ctx, token)
|
||||
addr, err := suite.Keeper.DeployZgChainWrappedCosmosCoinERC20Contract(suite.Ctx, token)
|
||||
suite.NoError(err)
|
||||
suite.NotNil(addr)
|
||||
|
||||
callContract := func(method string, args ...interface{}) ([]interface{}, error) {
|
||||
return suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
privKey,
|
||||
addr,
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
|
||||
@ -50,7 +51,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant {
|
||||
})
|
||||
|
||||
bankAddr := authtypes.NewModuleAddress(types.ModuleName)
|
||||
bankBalance := bankK.GetBalance(ctx, bankAddr, CosmosDenom).Amount.Mul(ConversionMultiplier)
|
||||
bankBalance := bankK.GetBalance(ctx, bankAddr, chaincfg.DisplayDenom).Amount.Mul(ConversionMultiplier)
|
||||
|
||||
broken = totalMinorBalances.GT(bankBalance)
|
||||
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
@ -46,10 +47,10 @@ func (suite *invariantTestSuite) SetupValidState() {
|
||||
keeper.ConversionMultiplier.QuoRaw(2),
|
||||
))
|
||||
}
|
||||
suite.FundModuleAccountWithKava(
|
||||
suite.FundModuleAccountWithZgChain(
|
||||
types.ModuleName,
|
||||
sdk.NewCoins(
|
||||
sdk.NewCoin("ukava", sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||
sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||
),
|
||||
)
|
||||
|
||||
@ -159,8 +160,8 @@ func (suite *invariantTestSuite) TestSmallBalances() {
|
||||
|
||||
// increase minor balance at least above conversion multiplier
|
||||
suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], keeper.ConversionMultiplier)
|
||||
// add same number of ukava to avoid breaking other invariants
|
||||
amt := sdk.NewCoins(sdk.NewInt64Coin(keeper.CosmosDenom, 1))
|
||||
// add same number of a0gi to avoid breaking other invariants
|
||||
amt := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1))
|
||||
suite.Require().NoError(
|
||||
suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, amt),
|
||||
)
|
||||
@ -190,7 +191,7 @@ func (suite *invariantTestSuite) TestSendToModuleAccountNotAllowed() {
|
||||
ToAddress: maccAddress.String(),
|
||||
Amount: coins,
|
||||
})
|
||||
suite.ErrorContains(err, "kava1w9vxuke5dz6hyza2j932qgmxltnfxwl78u920k is not allowed to receive funds: unauthorized")
|
||||
suite.ErrorContains(err, "0g1w9vxuke5dz6hyza2j932qgmxltnfxwl78u920k is not allowed to receive funds: unauthorized")
|
||||
}
|
||||
|
||||
func (suite *invariantTestSuite) TestCosmosCoinsFullyBackedInvariant() {
|
||||
|
@ -115,7 +115,7 @@ func (k Keeper) SetAccount(ctx sdk.Context, account types.Account) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetBalance returns the total balance of akava for a given account by address.
|
||||
// GetBalance returns the total balance of neuron for a given account by address.
|
||||
func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
||||
account := k.GetAccount(ctx, addr)
|
||||
if account == nil {
|
||||
@ -124,7 +124,7 @@ func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
||||
return account.Balance
|
||||
}
|
||||
|
||||
// SetBalance sets the total balance of akava for a given account by address.
|
||||
// SetBalance sets the total balance of neuron for a given account by address.
|
||||
func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int) error {
|
||||
account := k.GetAccount(ctx, addr)
|
||||
if account == nil {
|
||||
@ -140,10 +140,10 @@ func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int
|
||||
return k.SetAccount(ctx, *account)
|
||||
}
|
||||
|
||||
// SendBalance transfers the akava balance from sender addr to recipient addr.
|
||||
// SendBalance transfers the neuron balance from sender addr to recipient addr.
|
||||
func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdkmath.Int) error {
|
||||
if amt.IsNegative() {
|
||||
return fmt.Errorf("cannot send a negative amount of akava: %d", amt)
|
||||
return fmt.Errorf("cannot send a negative amount of neuron: %d", amt)
|
||||
}
|
||||
|
||||
if amt.IsZero() {
|
||||
@ -162,13 +162,13 @@ func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipien
|
||||
return k.SetBalance(ctx, recipientAddr, receiverBal)
|
||||
}
|
||||
|
||||
// AddBalance increments the akava balance of an address.
|
||||
// AddBalance increments the neuron balance of an address.
|
||||
func (k Keeper) AddBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
||||
bal := k.GetBalance(ctx, addr)
|
||||
return k.SetBalance(ctx, addr, amt.Add(bal))
|
||||
}
|
||||
|
||||
// RemoveBalance decrements the akava balance of an address.
|
||||
// RemoveBalance decrements the neuron balance of an address.
|
||||
func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
||||
if amt.IsNegative() {
|
||||
return fmt.Errorf("cannot remove a negative amount from balance: %d", amt)
|
||||
@ -184,7 +184,7 @@ func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.
|
||||
return k.SetBalance(ctx, addr, finalBal)
|
||||
}
|
||||
|
||||
// SetDeployedCosmosCoinContract stores a single deployed ERC20KavaWrappedCosmosCoin contract address
|
||||
// SetDeployedCosmosCoinContract stores a single deployed ERC20ZgChainWrappedCosmosCoin contract address
|
||||
func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string, contractAddress types.InternalEVMAddress) error {
|
||||
if err := sdk.ValidateDenom(cosmosDenom); err != nil {
|
||||
return errorsmod.Wrap(types.ErrInvalidCosmosDenom, cosmosDenom)
|
||||
@ -203,7 +203,7 @@ func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom stri
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetDeployedCosmosCoinContract gets a deployed ERC20KavaWrappedCosmosCoin contract address by cosmos denom
|
||||
// SetDeployedCosmosCoinContract gets a deployed ERC20ZgChainWrappedCosmosCoin contract address by cosmos denom
|
||||
// Returns the stored address and a bool indicating if it was found or not
|
||||
func (k *Keeper) GetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string) (types.InternalEVMAddress, bool) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
|
@ -26,7 +26,7 @@ var _ types.MsgServer = msgServer{}
|
||||
////////////////////////////
|
||||
|
||||
// ConvertCoinToERC20 handles a MsgConvertCoinToERC20 message to convert
|
||||
// sdk.Coin to Kava EVM tokens.
|
||||
// sdk.Coin to 0gChain EVM tokens.
|
||||
func (s msgServer) ConvertCoinToERC20(
|
||||
goCtx context.Context,
|
||||
msg *types.MsgConvertCoinToERC20,
|
||||
@ -64,7 +64,7 @@ func (s msgServer) ConvertCoinToERC20(
|
||||
}
|
||||
|
||||
// ConvertERC20ToCoin handles a MsgConvertERC20ToCoin message to convert
|
||||
// sdk.Coin to Kava EVM tokens.
|
||||
// sdk.Coin to 0gChain EVM tokens.
|
||||
func (s msgServer) ConvertERC20ToCoin(
|
||||
goCtx context.Context,
|
||||
msg *types.MsgConvertERC20ToCoin,
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (suite *MsgServerSuite) TestConvertCoinToERC20_Bep3() {
|
||||
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||
invoker, err := sdk.AccAddressFromBech32("0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||
receiverAddr := testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
|
@ -34,7 +34,7 @@ func TestMsgServerSuite(t *testing.T) {
|
||||
}
|
||||
|
||||
func (suite *MsgServerSuite) TestConvertCoinToERC20() {
|
||||
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||
invoker, err := sdk.AccAddressFromBech32("0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||
suite.Require().NoError(err)
|
||||
|
||||
err = suite.App.FundAccount(suite.Ctx, invoker, sdk.NewCoins(sdk.NewCoin("erc20/usdc", sdkmath.NewInt(10000))))
|
||||
@ -282,7 +282,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
||||
// make the denom allowed for conversion
|
||||
params := suite.Keeper.GetParams(suite.Ctx)
|
||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||
)
|
||||
suite.Keeper.SetParams(suite.Ctx, params)
|
||||
|
||||
@ -331,7 +331,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
||||
{
|
||||
name: "invalid - bad initiator",
|
||||
msg: types.NewMsgConvertCosmosCoinToERC20(
|
||||
"invalid-kava-address",
|
||||
"invalid-0g-address",
|
||||
testutil.RandomEvmAddress().Hex(),
|
||||
sdk.NewInt64Coin(allowedDenom, 1e4),
|
||||
),
|
||||
@ -452,7 +452,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_AlreadyDeployedContrac
|
||||
// make the denom allowed for conversion
|
||||
params := suite.Keeper.GetParams(suite.Ctx)
|
||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||
)
|
||||
suite.Keeper.SetParams(suite.Ctx, params)
|
||||
|
||||
@ -499,7 +499,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_AlreadyDeployedContrac
|
||||
// check total supply
|
||||
caller, key := testutil.RandomEvmAccount()
|
||||
totalSupply, err := suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
key,
|
||||
contractAddress,
|
||||
@ -639,7 +639,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinFromERC20() {
|
||||
// expect erc20 total supply to reflect new value
|
||||
caller, key := testutil.RandomEvmAccount()
|
||||
totalSupply, err := suite.QueryContract(
|
||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
||||
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||
caller,
|
||||
key,
|
||||
contractAddress,
|
||||
|
@ -66,9 +66,9 @@ func (suite *keeperTestSuite) TestGetAllowedTokenMetadata() {
|
||||
|
||||
atom := types.NewAllowedCosmosCoinERC20Token(
|
||||
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
|
||||
"Kava EVM ATOM", "ATOM", 6,
|
||||
"0gChain EVM ATOM", "ATOM", 6,
|
||||
)
|
||||
hard := types.NewAllowedCosmosCoinERC20Token("hard", "Kava EVM Hard", "HARD", 6)
|
||||
hard := types.NewAllowedCosmosCoinERC20Token("hard", "0gChain EVM Hard", "HARD", 6)
|
||||
|
||||
// init state with some allowed tokens
|
||||
params := suite.Keeper.GetParams(suite.Ctx)
|
||||
|
@ -37,6 +37,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
@ -81,14 +82,14 @@ func (suite *Suite) SetupTest() {
|
||||
suite.Addrs = addrs
|
||||
|
||||
evmGenesis := evmtypes.DefaultGenesisState()
|
||||
evmGenesis.Params.EvmDenom = "akava"
|
||||
evmGenesis.Params.EvmDenom = chaincfg.BaseDenom
|
||||
|
||||
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
||||
feemarketGenesis.Params.EnableHeight = 1
|
||||
feemarketGenesis.Params.NoBaseFee = false
|
||||
|
||||
cdc := suite.App.AppCodec()
|
||||
coins := sdk.NewCoins(sdk.NewInt64Coin("ukava", 1000_000_000_000_000_000))
|
||||
coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1000_000_000_000_000_000))
|
||||
authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{
|
||||
sdk.AccAddress(suite.Key1.PubKey().Address()),
|
||||
sdk.AccAddress(suite.Key2.PubKey().Address()),
|
||||
@ -184,29 +185,29 @@ func (suite *Suite) ModuleBalance(denom string) sdk.Int {
|
||||
return suite.App.GetModuleAccountBalance(suite.Ctx, types.ModuleName, denom)
|
||||
}
|
||||
|
||||
func (suite *Suite) FundAccountWithKava(addr sdk.AccAddress, coins sdk.Coins) {
|
||||
ukava := coins.AmountOf("ukava")
|
||||
if ukava.IsPositive() {
|
||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin("ukava", ukava)))
|
||||
func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) {
|
||||
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||
if a0gi.IsPositive() {
|
||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
akava := coins.AmountOf("akava")
|
||||
if akava.IsPositive() {
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, akava)
|
||||
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||
if neuron.IsPositive() {
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *Suite) FundModuleAccountWithKava(moduleName string, coins sdk.Coins) {
|
||||
ukava := coins.AmountOf("ukava")
|
||||
if ukava.IsPositive() {
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin("ukava", ukava)))
|
||||
func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) {
|
||||
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||
if a0gi.IsPositive() {
|
||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
akava := coins.AmountOf("akava")
|
||||
if akava.IsPositive() {
|
||||
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||
if neuron.IsPositive() {
|
||||
addr := suite.AccountKeeper.GetModuleAddress(moduleName)
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, akava)
|
||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||
suite.Require().NoError(err)
|
||||
}
|
||||
}
|
||||
@ -217,7 +218,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress {
|
||||
suite.App.FundModuleAccount(
|
||||
suite.Ctx,
|
||||
types.ModuleName,
|
||||
sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(0))),
|
||||
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||
)
|
||||
|
||||
contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18))
|
||||
@ -318,7 +319,7 @@ func (suite *Suite) SendTx(
|
||||
// Mint the max gas to the FeeCollector to ensure balance in case of refund
|
||||
suite.MintFeeCollector(sdk.NewCoins(
|
||||
sdk.NewCoin(
|
||||
"ukava",
|
||||
chaincfg.DisplayDenom,
|
||||
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
|
||||
)))
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// InternalEVMAddress is a type alias of common.Address to represent an address
|
||||
// on the Kava EVM.
|
||||
// on the 0gChain EVM.
|
||||
type InternalEVMAddress struct {
|
||||
common.Address
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ var (
|
||||
// ERC20MintableBurnableAddress is the erc20 module address
|
||||
ERC20MintableBurnableAddress common.Address
|
||||
|
||||
//go:embed ethermint_json/ERC20KavaWrappedCosmosCoin.json
|
||||
ERC20KavaWrappedCosmosCoinJSON []byte
|
||||
//go:embed ethermint_json/ERC20ZgChainWrappedCosmosCoin.json
|
||||
ERC20ZgChainWrappedCosmosCoinJSON []byte
|
||||
|
||||
// ERC20KavaWrappedCosmosCoinContract is the compiled erc20 contract
|
||||
ERC20KavaWrappedCosmosCoinContract evmtypes.CompiledContract
|
||||
// ERC20ZgChainWrappedCosmosCoinContract is the compiled erc20 contract
|
||||
ERC20ZgChainWrappedCosmosCoinContract evmtypes.CompiledContract
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -53,12 +53,12 @@ func init() {
|
||||
panic("loading ERC20MintableBurnable contract failed")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(ERC20KavaWrappedCosmosCoinJSON, &ERC20KavaWrappedCosmosCoinContract)
|
||||
err = json.Unmarshal(ERC20ZgChainWrappedCosmosCoinJSON, &ERC20ZgChainWrappedCosmosCoinContract)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("failed to unmarshal ERC20KavaWrappedCosmosCoinJSON: %s. %s", err, string(ERC20KavaWrappedCosmosCoinJSON)))
|
||||
panic(fmt.Sprintf("failed to unmarshal ERC20ZgChainWrappedCosmosCoinJSON: %s. %s", err, string(ERC20ZgChainWrappedCosmosCoinJSON)))
|
||||
}
|
||||
|
||||
if len(ERC20KavaWrappedCosmosCoinContract.Bin) == 0 {
|
||||
panic("loading ERC20KavaWrappedCosmosCoin contract failed")
|
||||
if len(ERC20ZgChainWrappedCosmosCoinContract.Bin) == 0 {
|
||||
panic("loading ERC20ZgChainWrappedCosmosCoin contract failed")
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
return NewInternalEVMAddress(common.BytesToAddress(pair.ZgchainERC20Address))
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package types_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -142,7 +143,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||
"kava",
|
||||
chaincfg.DisplayDenom,
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
@ -162,7 +163,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
||||
"kava",
|
||||
chaincfg.DisplayDenom,
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
@ -183,16 +184,16 @@ func TestConversionPairs_Validate(t *testing.T) {
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||
"kava",
|
||||
chaincfg.DisplayDenom,
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
"kava",
|
||||
chaincfg.DisplayDenom,
|
||||
),
|
||||
),
|
||||
errArgs{
|
||||
expectPass: false,
|
||||
contains: "found duplicate enabled conversion pair denom kava",
|
||||
contains: "found duplicate enabled conversion pair denom a0gi",
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -208,7 +209,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
"kava",
|
||||
chaincfg.DisplayDenom,
|
||||
),
|
||||
),
|
||||
errArgs{
|
||||
@ -240,12 +241,12 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "valid token",
|
||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 6),
|
||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 6),
|
||||
expErr: "",
|
||||
},
|
||||
{
|
||||
name: "valid - highest allowed decimals",
|
||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 255),
|
||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 255),
|
||||
expErr: "",
|
||||
},
|
||||
{
|
||||
@ -280,7 +281,7 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "invalid - decimals higher than uint8",
|
||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 256),
|
||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 256),
|
||||
expErr: "decimals must be less than 256",
|
||||
},
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -21,7 +21,7 @@ const (
|
||||
var (
|
||||
// AccountStoreKeyPrefix is the prefix for keys that store accounts
|
||||
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}
|
||||
)
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -13,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
type errArgs struct {
|
||||
expectPass bool
|
||||
@ -29,7 +30,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"valid",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
||||
errArgs{
|
||||
@ -38,7 +39,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"valid-bnb",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
sdk.NewCoin("bnb", sdkmath.NewInt(1234)),
|
||||
errArgs{
|
||||
@ -47,7 +48,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - odd length hex address",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
||||
errArgs{
|
||||
@ -57,7 +58,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - zero amount",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(0)),
|
||||
errArgs{
|
||||
@ -67,7 +68,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - negative amount",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
// Create manually so there is no validation
|
||||
sdk.Coin{Denom: "erc20/weth", Amount: sdkmath.NewInt(-1234)},
|
||||
@ -78,7 +79,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - empty denom",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
sdk.Coin{Denom: "", Amount: sdkmath.NewInt(-1234)},
|
||||
errArgs{
|
||||
@ -88,7 +89,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - invalid denom",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
sdk.Coin{Denom: "h", Amount: sdkmath.NewInt(-1234)},
|
||||
errArgs{
|
||||
@ -118,7 +119,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMsgConvertERC20ToCoin(t *testing.T) {
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
|
||||
type errArgs struct {
|
||||
expectPass bool
|
||||
@ -135,7 +136,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
"valid",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||
sdkmath.NewInt(1234),
|
||||
@ -145,7 +146,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - odd length hex address",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||
sdkmath.NewInt(1234),
|
||||
@ -156,7 +157,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - zero amount",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||
sdkmath.NewInt(0),
|
||||
@ -167,7 +168,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - negative amount",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||
sdkmath.NewInt(-1234),
|
||||
@ -178,7 +179,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"invalid - invalid contract address",
|
||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369",
|
||||
sdkmath.NewInt(1234),
|
||||
@ -210,7 +211,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
||||
validKavaAddr := app.RandomAddress()
|
||||
validZgChainAddr := app.RandomAddress()
|
||||
validHexAddr, _ := testutil.RandomEvmAccount()
|
||||
invalidAddr := "not-an-address"
|
||||
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
||||
@ -224,14 +225,14 @@ func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "valid",
|
||||
initiator: validKavaAddr.String(),
|
||||
initiator: validZgChainAddr.String(),
|
||||
receiver: validHexAddr.String(),
|
||||
amount: validAmount,
|
||||
expectedErr: "",
|
||||
},
|
||||
{
|
||||
name: "invalid - sending to kava addr",
|
||||
initiator: validKavaAddr.String(),
|
||||
name: "invalid - sending to 0g addr",
|
||||
initiator: validZgChainAddr.String(),
|
||||
receiver: app.RandomAddress().String(),
|
||||
amount: validAmount,
|
||||
expectedErr: "receiver is not a valid hex address",
|
||||
@ -245,35 +246,35 @@ func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "invalid - invalid receiver",
|
||||
initiator: validKavaAddr.String(),
|
||||
initiator: validZgChainAddr.String(),
|
||||
receiver: invalidAddr,
|
||||
amount: validAmount,
|
||||
expectedErr: "receiver is not a valid hex address",
|
||||
},
|
||||
{
|
||||
name: "invalid - invalid amount - nil",
|
||||
initiator: validKavaAddr.String(),
|
||||
initiator: validZgChainAddr.String(),
|
||||
receiver: validHexAddr.String(),
|
||||
amount: sdk.Coin{},
|
||||
expectedErr: "invalid coins",
|
||||
},
|
||||
{
|
||||
name: "invalid - invalid amount - zero",
|
||||
initiator: validKavaAddr.String(),
|
||||
initiator: validZgChainAddr.String(),
|
||||
receiver: validHexAddr.String(),
|
||||
amount: sdk.NewInt64Coin("magic", 0),
|
||||
expectedErr: "invalid coins",
|
||||
},
|
||||
{
|
||||
name: "invalid - invalid amount - negative",
|
||||
initiator: validKavaAddr.String(),
|
||||
initiator: validZgChainAddr.String(),
|
||||
receiver: validHexAddr.String(),
|
||||
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
||||
expectedErr: "invalid coins",
|
||||
},
|
||||
{
|
||||
name: "invalid - invalid amount - invalid denom",
|
||||
initiator: validKavaAddr.String(),
|
||||
initiator: validZgChainAddr.String(),
|
||||
receiver: validHexAddr.String(),
|
||||
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
||||
expectedErr: "invalid coins",
|
||||
@ -322,7 +323,7 @@ func TestConvertCosmosCoinToERC20_GetSigners(t *testing.T) {
|
||||
|
||||
func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
||||
validHexAddr := testutil.RandomEvmAddress()
|
||||
validKavaAddr := app.RandomAddress()
|
||||
validZgChainAddr := app.RandomAddress()
|
||||
invalidAddr := "not-an-address"
|
||||
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
||||
|
||||
@ -336,7 +337,7 @@ func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
||||
{
|
||||
name: "valid",
|
||||
initiator: validHexAddr.String(),
|
||||
receiver: validKavaAddr.String(),
|
||||
receiver: validZgChainAddr.String(),
|
||||
amount: validAmount,
|
||||
expectedErr: "",
|
||||
},
|
||||
@ -364,28 +365,28 @@ func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
||||
{
|
||||
name: "invalid - invalid amount - nil",
|
||||
initiator: validHexAddr.String(),
|
||||
receiver: validKavaAddr.String(),
|
||||
receiver: validZgChainAddr.String(),
|
||||
amount: sdk.Coin{},
|
||||
expectedErr: "invalid coins",
|
||||
},
|
||||
{
|
||||
name: "invalid - invalid amount - zero",
|
||||
initiator: validHexAddr.String(),
|
||||
receiver: validKavaAddr.String(),
|
||||
receiver: validZgChainAddr.String(),
|
||||
amount: sdk.NewInt64Coin("magic", 0),
|
||||
expectedErr: "invalid coins",
|
||||
},
|
||||
{
|
||||
name: "invalid - invalid amount - negative",
|
||||
initiator: validHexAddr.String(),
|
||||
receiver: validKavaAddr.String(),
|
||||
receiver: validZgChainAddr.String(),
|
||||
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
||||
expectedErr: "invalid coins",
|
||||
},
|
||||
{
|
||||
name: "invalid - invalid amount - invalid denom",
|
||||
initiator: validHexAddr.String(),
|
||||
receiver: validKavaAddr.String(),
|
||||
receiver: validZgChainAddr.String(),
|
||||
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
||||
expectedErr: "invalid coins",
|
||||
},
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||
)
|
||||
@ -19,7 +19,7 @@ type ParamsTestSuite struct {
|
||||
}
|
||||
|
||||
func (suite *ParamsTestSuite) SetupTest() {
|
||||
app.SetSDKConfig()
|
||||
chaincfg.SetSDKConfig()
|
||||
}
|
||||
|
||||
func (suite *ParamsTestSuite) TestDefault() {
|
||||
@ -107,11 +107,11 @@ func (suite *ParamsTestSuite) TestParams_Validate() {
|
||||
invalidConversionPairs := types.NewConversionPairs(
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||
"kava",
|
||||
chaincfg.DisplayDenom,
|
||||
),
|
||||
types.NewConversionPair(
|
||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||
"kava", // duplicate denom!
|
||||
chaincfg.DisplayDenom, // duplicate denom!
|
||||
),
|
||||
)
|
||||
validAllowedCosmosDenoms := types.NewAllowedCosmosCoinERC20Tokens(
|
||||
|
@ -40,7 +40,7 @@ func queryCirculatingSupply() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "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,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx, err := client.GetClientQueryContext(cmd)
|
||||
@ -62,7 +62,7 @@ func queryTotalSupply() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "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,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx, err := client.GetClientQueryContext(cmd)
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
@ -20,23 +21,23 @@ func NewQueryServerImpl(bk types.BankKeeper) types.QueryServer {
|
||||
return &queryServer{bk: bk}
|
||||
}
|
||||
|
||||
// CirculatingSupply implements the gRPC service handler for querying the circulating supply of the kava token.
|
||||
// CirculatingSupply implements the gRPC service handler for querying the circulating supply of the 0g token.
|
||||
func (s queryServer) CirculatingSupply(c context.Context, req *types.QueryCirculatingSupplyRequest) (*types.
|
||||
QueryCirculatingSupplyResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
totalSupply := s.bk.GetSupply(ctx, "ukava").Amount
|
||||
totalSupply := s.bk.GetSupply(ctx, chaincfg.DisplayDenom).Amount
|
||||
supplyInt := getCirculatingSupply(ctx.BlockTime(), totalSupply)
|
||||
return &types.QueryCirculatingSupplyResponse{
|
||||
Amount: supplyInt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TotalSupply returns the total amount of ukava tokens
|
||||
// TotalSupply returns the total amount of a0gi tokens
|
||||
func (s queryServer) TotalSupply(c context.Context, req *types.QueryTotalSupplyRequest) (*types.QueryTotalSupplyResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
totalSupply := s.bk.GetSupply(ctx, "ukava").Amount
|
||||
totalSupply := s.bk.GetSupply(ctx, chaincfg.DisplayDenom).Amount
|
||||
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt()
|
||||
return &types.QueryTotalSupplyResponse{
|
||||
Amount: supplyInt,
|
||||
@ -255,7 +256,7 @@ func (s queryServer) CirculatingSupplySWP(c context.Context, req *types.QueryCir
|
||||
monthlyStakersSwp := int64(520_833)
|
||||
monthlyLPIncentivesSwp := int64(2_343_750)
|
||||
|
||||
// []{Ecosystem, Team, Treasury, Kava Stakers, LP Incentives}
|
||||
// []{Ecosystem, Team, Treasury, 0gChain Stakers, LP Incentives}
|
||||
scheduleAmounts := [][]int64{
|
||||
{12_500_000, 0, 15_625_000, monthlyStakersSwp, monthlyLPIncentivesSwp}, // *** Year ONE ***
|
||||
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 1
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/0glabs/0g-chain/app"
|
||||
"github.com/0glabs/0g-chain/chaincfg"
|
||||
"github.com/0glabs/0g-chain/x/validator-vesting/keeper"
|
||||
"github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||
)
|
||||
@ -52,7 +53,7 @@ func TestGrpcQueryTestSuite(t *testing.T) {
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestCirculatingSupply() {
|
||||
suite.Run("vesting period supply", func() {
|
||||
suite.bk.SetSupply(suite.ctx, "ukava", sdkmath.NewInt(2_500_000_000_000))
|
||||
suite.bk.SetSupply(suite.ctx, chaincfg.DisplayDenom, sdkmath.NewInt(2_500_000_000_000))
|
||||
lastVestingPeriod := time.Date(2022, 8, 5, 24, 0, 0, 0, time.UTC)
|
||||
queryClient := suite.queryClientWithBlockTime(lastVestingPeriod)
|
||||
res, err := queryClient.CirculatingSupply(context.Background(), &types.QueryCirculatingSupplyRequest{})
|
||||
@ -61,7 +62,7 @@ func (suite *grpcQueryTestSuite) TestCirculatingSupply() {
|
||||
})
|
||||
|
||||
suite.Run("supply after last vesting period", func() {
|
||||
suite.bk.SetSupply(suite.ctx, "ukava", sdkmath.NewInt(100_000_000))
|
||||
suite.bk.SetSupply(suite.ctx, chaincfg.DisplayDenom, sdkmath.NewInt(100_000_000))
|
||||
res, err := suite.queryClient.CirculatingSupply(context.Background(), &types.QueryCirculatingSupplyRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(100), res.Amount)
|
||||
@ -69,7 +70,7 @@ func (suite *grpcQueryTestSuite) TestCirculatingSupply() {
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestTotalSupply() {
|
||||
suite.bk.SetSupply(suite.ctx, "ukava", sdkmath.NewInt(100_000_000))
|
||||
suite.bk.SetSupply(suite.ctx, chaincfg.DisplayDenom, sdkmath.NewInt(100_000_000))
|
||||
res, err := suite.queryClient.TotalSupply(context.Background(), &types.QueryTotalSupplyRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(100), res.Amount)
|
||||
|
Loading…
Reference in New Issue
Block a user