mirror of
https://github.com/0glabs/0g-chain.git
synced 2025-01-12 16:25:17 +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
|
RUN apk add bash git make libc-dev gcc linux-headers eudev-dev jq curl
|
||||||
|
|
||||||
# Set working directory for the build
|
# Set working directory for the build
|
||||||
WORKDIR /root/kava
|
WORKDIR /root/0g-chain
|
||||||
# default home directory is /root
|
# default home directory is /root
|
||||||
|
|
||||||
# Copy dependency files first to facilitate dependency caching
|
# 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
|
FROM alpine:3.15
|
||||||
|
|
||||||
RUN apk add bash jq curl
|
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
|
# Set up dependencies
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
@ -19,7 +19,7 @@ RUN git clone https://github.com/facebook/rocksdb.git \
|
|||||||
&& make -j$(nproc) install-shared \
|
&& make -j$(nproc) install-shared \
|
||||||
&& ldconfig
|
&& ldconfig
|
||||||
|
|
||||||
WORKDIR /root/kava
|
WORKDIR /root/0gchain
|
||||||
# Copy dependency files first to facilitate dependency caching
|
# Copy dependency files first to facilitate dependency caching
|
||||||
COPY ./go.mod ./
|
COPY ./go.mod ./
|
||||||
COPY ./go.sum ./
|
COPY ./go.sum ./
|
||||||
@ -32,13 +32,13 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
|
|||||||
# Add source files
|
# Add source files
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
ARG kava_database_backend=rocksdb
|
ARG 0gchain_database_backend=rocksdb
|
||||||
ENV KAVA_DATABASE_BACKEND=$kava_database_backend
|
ENV 0GCHAIN_DATABASE_BACKEND=$0gchain_database_backend
|
||||||
|
|
||||||
# Mount go build and mod caches as container caches, persisted between builder invocations
|
# Mount go build and mod caches as container caches, persisted between builder invocations
|
||||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
--mount=type=cache,target=/go/pkg/mod \
|
--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
|
FROM ubuntu:22.04
|
||||||
@ -48,10 +48,10 @@ RUN apt-get update \
|
|||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# copy rocksdb shared objects
|
# 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
|
RUN ldconfig
|
||||||
|
|
||||||
# copy kava binary
|
# copy 0g-chain binary
|
||||||
COPY --from=kava-builder /go/bin/kava /bin/kava
|
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/staking"
|
||||||
"github.com/cosmos/cosmos-sdk/x/supply"
|
"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"
|
validatorvesting "github.com/0glabs/0g-chain/x/validator-vesting"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
|
|
||||||
abci "github.com/cometbft/cometbft/abci/types"
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
||||||
@ -52,9 +53,9 @@ func (suite *SimulateRequestTestSuite) TearDownTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
||||||
fromAddr, err := sdk.AccAddressFromBech32("kava1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
fromAddr, err := sdk.AccAddressFromBech32("0g1esagqd83rhqdtpy5sxhklaxgn58k2m3s3mnpea")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
toAddr, err := sdk.AccAddressFromBech32("kava1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
toAddr, err := sdk.AccAddressFromBech32("0g1mq9qxlhze029lm0frzw2xr6hem8c3k9ts54w0w")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
simRequest := app.SimulateRequest{
|
simRequest := app.SimulateRequest{
|
||||||
@ -62,11 +63,11 @@ func (suite *SimulateRequestTestSuite) TestSimulateRequest() {
|
|||||||
bank.MsgSend{
|
bank.MsgSend{
|
||||||
FromAddress: fromAddr,
|
FromAddress: fromAddr,
|
||||||
ToAddress: toAddr,
|
ToAddress: toAddr,
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Fee: auth.StdFee{
|
Fee: auth.StdFee{
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(5e4))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(5e4))),
|
||||||
Gas: 1e6,
|
Gas: 1e6,
|
||||||
},
|
},
|
||||||
Memo: "test memo",
|
Memo: "test memo",
|
||||||
|
@ -21,12 +21,13 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
// bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
// bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
||||||
// pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
// pricefeedtypes "github.com/0glabs/0g-chain/x/pricefeed/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
|||||||
App: *app.NewApp(
|
App: *app.NewApp(
|
||||||
log.NewNopLogger(),
|
log.NewNopLogger(),
|
||||||
tmdb.NewMemDB(),
|
tmdb.NewMemDB(),
|
||||||
app.DefaultNodeHome,
|
chaincfg.DefaultNodeHome,
|
||||||
nil,
|
nil,
|
||||||
encodingConfig,
|
encodingConfig,
|
||||||
opts,
|
opts,
|
||||||
@ -65,7 +66,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
|||||||
chainID,
|
chainID,
|
||||||
app.NewFundedGenStateWithSameCoins(
|
app.NewFundedGenStateWithSameCoins(
|
||||||
tApp.AppCodec(),
|
tApp.AppCodec(),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e9)),
|
||||||
testAddresses,
|
testAddresses,
|
||||||
),
|
),
|
||||||
// newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
// newBep3GenStateMulti(tApp.AppCodec(), deputy),
|
||||||
@ -113,7 +114,7 @@ func TestAppAnteHandler_AuthorizedMempool(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
tc.address,
|
tc.address,
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1_000_000)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
var _ sdk.AnteHandler = (&MockAnteHandler{}).AnteHandle
|
||||||
@ -45,7 +46,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_NotCheckTx(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
@ -80,12 +81,12 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Pass(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[2],
|
testAddresses[2],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
@ -121,7 +122,7 @@ func TestAuthenticatedMempoolDecorator_AnteHandle_Reject(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
sdk.NewCoins(), // no fee
|
sdk.NewCoins(), // no fee
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
|
func newMsgGrant(granter sdk.AccAddress, grantee sdk.AccAddress, a authz.Authorization, expiration time.Time) *authz.MsgGrant {
|
||||||
@ -58,7 +59,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[1],
|
testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
checkTx: false,
|
checkTx: false,
|
||||||
@ -128,7 +129,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
[]sdk.Msg{banktypes.NewMsgSend(
|
[]sdk.Msg{banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[3],
|
testAddresses[3],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||||
)}),
|
)}),
|
||||||
},
|
},
|
||||||
checkTx: false,
|
checkTx: false,
|
||||||
@ -161,7 +162,7 @@ func TestAuthzLimiterDecorator(t *testing.T) {
|
|||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0],
|
testAddresses[0],
|
||||||
testAddresses[3],
|
testAddresses[3],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100e6)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100e6)),
|
||||||
),
|
),
|
||||||
&evmtypes.MsgEthereumTx{},
|
&evmtypes.MsgEthereumTx{},
|
||||||
},
|
},
|
||||||
|
@ -34,6 +34,8 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
|
|
||||||
// cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
// cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
||||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
|
evmutiltestutil "github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
@ -158,7 +160,7 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
// Genesis states
|
// Genesis states
|
||||||
evmGs := evmtypes.NewGenesisState(
|
evmGs := evmtypes.NewGenesisState(
|
||||||
evmtypes.NewParams(
|
evmtypes.NewParams(
|
||||||
"akava", // evmDenom
|
chaincfg.BaseDenom, // evmDenom
|
||||||
false, // allowedUnprotectedTxs
|
false, // allowedUnprotectedTxs
|
||||||
true, // enableCreate
|
true, // enableCreate
|
||||||
true, // enableCall
|
true, // enableCall
|
||||||
@ -267,10 +269,10 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
// pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
// pricefeedtypes.ModuleName: cdc.MustMarshalJSON(&pricefeedGenState),
|
||||||
}
|
}
|
||||||
|
|
||||||
// funds our test accounts with some ukava
|
// funds our test accounts with some a0gi
|
||||||
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
coinsGenState := app.NewFundedGenStateWithSameCoins(
|
||||||
tApp.AppCodec(),
|
tApp.AppCodec(),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 1e9)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1e9)),
|
||||||
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
[]sdk.AccAddress{suite.testAddr, suite.testAddr2},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -357,45 +359,17 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
params := evmKeeper.GetParams(suite.ctx)
|
params := evmKeeper.GetParams(suite.ctx)
|
||||||
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
params.EIP712AllowedMsgs = []evmtypes.EIP712AllowedMsg{
|
||||||
{
|
{
|
||||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertERC20ToCoin",
|
||||||
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
MsgValueTypeName: "MsgValueEVMConvertERC20ToCoin",
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||||
{Name: "initiator", Type: "string"},
|
{Name: "initiator", Type: "string"},
|
||||||
{Name: "receiver", Type: "string"},
|
{Name: "receiver", Type: "string"},
|
||||||
{Name: "kava_erc20_address", Type: "string"},
|
{Name: "0gchain_erc20_address", Type: "string"},
|
||||||
{Name: "amount", Type: "string"},
|
{Name: "amount", Type: "string"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgCreateCDP",
|
MsgTypeUrl: "/0g-chain.evmutil.v1beta1.MsgConvertCoinToERC20",
|
||||||
MsgValueTypeName: "MsgValueCDPCreate",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "sender", Type: "string"},
|
|
||||||
{Name: "collateral", Type: "Coin"},
|
|
||||||
{Name: "principal", Type: "Coin"},
|
|
||||||
{Name: "collateral_type", Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgDeposit",
|
|
||||||
MsgValueTypeName: "MsgValueCDPDeposit",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "depositor", Type: "string"},
|
|
||||||
{Name: "owner", Type: "string"},
|
|
||||||
{Name: "collateral", Type: "Coin"},
|
|
||||||
{Name: "collateral_type", Type: "string"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgDeposit",
|
|
||||||
MsgValueTypeName: "MsgValueHardDeposit",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "depositor", Type: "string"},
|
|
||||||
{Name: "amount", Type: "Coin[]"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.evmutil.v1beta1.MsgConvertCoinToERC20",
|
|
||||||
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
MsgValueTypeName: "MsgValueEVMConvertCoinToERC20",
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
||||||
{Name: "initiator", Type: "string"},
|
{Name: "initiator", Type: "string"},
|
||||||
@ -403,23 +377,6 @@ func (suite *EIP712TestSuite) SetupTest() {
|
|||||||
{Name: "amount", Type: "Coin"},
|
{Name: "amount", Type: "Coin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.cdp.v1beta1.MsgRepayDebt",
|
|
||||||
MsgValueTypeName: "MsgValueCDPRepayDebt",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "sender", Type: "string"},
|
|
||||||
{Name: "collateral_type", Type: "string"},
|
|
||||||
{Name: "payment", Type: "Coin"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
MsgTypeUrl: "/kava.hard.v1beta1.MsgWithdraw",
|
|
||||||
MsgValueTypeName: "MsgValueHardWithdraw",
|
|
||||||
ValueTypes: []evmtypes.EIP712MsgAttrType{
|
|
||||||
{Name: "depositor", Type: "string"},
|
|
||||||
{Name: "amount", Type: "Coin[]"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
evmKeeper.SetParams(suite.ctx, params)
|
evmKeeper.SetParams(suite.ctx, params)
|
||||||
|
|
||||||
@ -465,7 +422,7 @@ func (suite *EIP712TestSuite) deployUSDCERC20(app app.TestApp, ctx sdk.Context)
|
|||||||
suite.tApp.FundModuleAccount(
|
suite.tApp.FundModuleAccount(
|
||||||
suite.ctx,
|
suite.ctx,
|
||||||
evmutiltypes.ModuleName,
|
evmutiltypes.ModuleName,
|
||||||
sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(0))),
|
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||||
)
|
)
|
||||||
|
|
||||||
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
contractAddr, err := suite.evmutilKeeper.DeployTestMintableERC20Contract(suite.ctx, "USDC", "USDC", uint8(18))
|
||||||
@ -565,7 +522,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
errMsg: "insufficient funds",
|
errMsg: "insufficient funds",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||||
bk := suite.tApp.GetBankKeeper()
|
bk := suite.tApp.GetBankKeeper()
|
||||||
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, "ukava")
|
gasCoins := bk.GetBalance(suite.ctx, suite.testAddr, chaincfg.DisplayDenom)
|
||||||
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
suite.tApp.GetBankKeeper().SendCoins(suite.ctx, suite.testAddr, suite.testAddr2, sdk.NewCoins(gasCoins))
|
||||||
return txBuilder
|
return txBuilder
|
||||||
},
|
},
|
||||||
@ -577,9 +534,9 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
failCheckTx: true,
|
failCheckTx: true,
|
||||||
errMsg: "invalid chain-id",
|
errMsg: "invalid chain-id",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||||
return suite.createTestEIP712CosmosTxBuilder(
|
return suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, "kavatest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr, suite.testPrivKey, "0gchaintest_12-1", uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -590,7 +547,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
failCheckTx: true,
|
failCheckTx: true,
|
||||||
errMsg: "invalid pubkey",
|
errMsg: "invalid pubkey",
|
||||||
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
updateTx: func(txBuilder client.TxBuilder, msgs []sdk.Msg) client.TxBuilder {
|
||||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||||
return suite.createTestEIP712CosmosTxBuilder(
|
return suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr2, suite.testPrivKey2, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
@ -630,7 +587,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx() {
|
|||||||
msgs = tc.updateMsgs(msgs)
|
msgs = tc.updateMsgs(msgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, msgs,
|
||||||
)
|
)
|
||||||
@ -716,7 +673,7 @@ func (suite *EIP712TestSuite) TestEIP712Tx_DepositAndWithdraw() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deliver deposit msg
|
// deliver deposit msg
|
||||||
gasAmt := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(20)))
|
gasAmt := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(20)))
|
||||||
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
txBuilder := suite.createTestEIP712CosmosTxBuilder(
|
||||||
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
suite.testAddr, suite.testPrivKey, ChainID, uint64(sims.DefaultGenTxGas*10), gasAmt, depositMsgs,
|
||||||
)
|
)
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustParseDecCoins(value string) sdk.DecCoins {
|
func mustParseDecCoins(value string) sdk.DecCoins {
|
||||||
@ -30,7 +31,7 @@ func TestEvmMinGasFilter(t *testing.T) {
|
|||||||
|
|
||||||
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: tmtime.Now()})
|
||||||
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
tApp.GetEvmKeeper().SetParams(ctx, evmtypes.Params{
|
||||||
EvmDenom: "akava",
|
EvmDenom: chaincfg.BaseDenom,
|
||||||
})
|
})
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@ -44,29 +45,29 @@ func TestEvmMinGasFilter(t *testing.T) {
|
|||||||
mustParseDecCoins(""),
|
mustParseDecCoins(""),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price",
|
"zero a0gi gas price",
|
||||||
mustParseDecCoins("0ukava"),
|
mustParseDecCoins("0a0gi"),
|
||||||
mustParseDecCoins("0ukava"),
|
mustParseDecCoins("0a0gi"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non-zero ukava gas price",
|
"non-zero a0gi gas price",
|
||||||
mustParseDecCoins("0.001ukava"),
|
mustParseDecCoins("0.001a0gi"),
|
||||||
mustParseDecCoins("0.001ukava"),
|
mustParseDecCoins("0.001a0gi"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price, min akava price",
|
"zero a0gi gas price, min neuron price",
|
||||||
mustParseDecCoins("0ukava;100000akava"),
|
mustParseDecCoins("0a0gi;100000neuron"),
|
||||||
mustParseDecCoins("0ukava"), // akava is removed
|
mustParseDecCoins("0a0gi"), // neuron is removed
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"zero ukava gas price, min akava price, other token",
|
"zero a0gi gas price, min neuron price, other token",
|
||||||
mustParseDecCoins("0ukava;100000akava;0.001other"),
|
mustParseDecCoins("0a0gi;100000neuron;0.001other"),
|
||||||
mustParseDecCoins("0ukava;0.001other"), // akava is removed
|
mustParseDecCoins("0a0gi;0.001other"), // neuron is removed
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"non-zero ukava gas price, min akava price",
|
"non-zero a0gi gas price, min neuron price",
|
||||||
mustParseDecCoins("0.25ukava;100000akava;0.001other"),
|
mustParseDecCoins("0.25a0gi;100000neuron;0.001other"),
|
||||||
mustParseDecCoins("0.25ukava;0.001other"), // akava is removed
|
mustParseDecCoins("0.25a0gi;0.001other"), // neuron is removed
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing.T) {
|
||||||
@ -33,7 +34,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"MsgCreateVestingAccount",
|
"MsgCreateVestingAccount",
|
||||||
vesting.NewMsgCreateVestingAccount(
|
vesting.NewMsgCreateVestingAccount(
|
||||||
testAddresses[0], testAddresses[1],
|
testAddresses[0], testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
time.Date(1998, 1, 1, 0, 0, 0, 0, time.UTC).Unix(),
|
||||||
false,
|
false,
|
||||||
),
|
),
|
||||||
@ -44,7 +45,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"MsgCreateVestingAccount",
|
"MsgCreateVestingAccount",
|
||||||
vesting.NewMsgCreatePermanentLockedAccount(
|
vesting.NewMsgCreatePermanentLockedAccount(
|
||||||
testAddresses[0], testAddresses[1],
|
testAddresses[0], testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
true,
|
true,
|
||||||
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
"MsgTypeURL /cosmos.vesting.v1beta1.MsgCreatePermanentLockedAccount not supported",
|
||||||
@ -63,7 +64,7 @@ func TestVestingMempoolDecorator_MsgCreateVestingAccount_Unauthorized(t *testing
|
|||||||
"other messages not affected",
|
"other messages not affected",
|
||||||
banktypes.NewMsgSend(
|
banktypes.NewMsgSend(
|
||||||
testAddresses[0], testAddresses[1],
|
testAddresses[0], testAddresses[1],
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 100_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 100_000_000)),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
"",
|
"",
|
||||||
|
62
app/app.go
62
app/app.go
@ -3,10 +3,6 @@ package app
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
stdlog "log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
dbm "github.com/cometbft/cometbft-db"
|
dbm "github.com/cometbft/cometbft-db"
|
||||||
abci "github.com/cometbft/cometbft/abci/types"
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
@ -103,10 +99,10 @@ import (
|
|||||||
"github.com/evmos/ethermint/x/feemarket"
|
"github.com/evmos/ethermint/x/feemarket"
|
||||||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
||||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||||
"github.com/gorilla/mux"
|
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app/ante"
|
"github.com/0glabs/0g-chain/app/ante"
|
||||||
kavaparams "github.com/0glabs/0g-chain/app/params"
|
chainparams "github.com/0glabs/0g-chain/app/params"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
|
|
||||||
evmutil "github.com/0glabs/0g-chain/x/evmutil"
|
evmutil "github.com/0glabs/0g-chain/x/evmutil"
|
||||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
@ -123,14 +119,7 @@ import (
|
|||||||
validatorvestingtypes "github.com/0glabs/0g-chain/x/validator-vesting/types"
|
validatorvestingtypes "github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
appName = "kava"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DefaultNodeHome default home directories for the application daemon
|
|
||||||
DefaultNodeHome string
|
|
||||||
|
|
||||||
// ModuleBasics manages simple versions of full app modules.
|
// ModuleBasics manages simple versions of full app modules.
|
||||||
// It's used for things such as codec registration and genesis file verification.
|
// It's used for things such as codec registration and genesis file verification.
|
||||||
ModuleBasics = module.NewBasicManager(
|
ModuleBasics = module.NewBasicManager(
|
||||||
@ -208,7 +197,7 @@ var DefaultOptions = Options{
|
|||||||
EVMMaxGasWanted: ethermintconfig.DefaultMaxTxGasWanted,
|
EVMMaxGasWanted: ethermintconfig.DefaultMaxTxGasWanted,
|
||||||
}
|
}
|
||||||
|
|
||||||
// App is the Kava ABCI application.
|
// App is the 0gChain ABCI application.
|
||||||
type App struct {
|
type App struct {
|
||||||
*baseapp.BaseApp
|
*baseapp.BaseApp
|
||||||
|
|
||||||
@ -260,22 +249,13 @@ type App struct {
|
|||||||
configurator module.Configurator
|
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.
|
// NewApp returns a reference to an initialized App.
|
||||||
func NewApp(
|
func NewApp(
|
||||||
logger tmlog.Logger,
|
logger tmlog.Logger,
|
||||||
db dbm.DB,
|
db dbm.DB,
|
||||||
homePath string,
|
homePath string,
|
||||||
traceStore io.Writer,
|
traceStore io.Writer,
|
||||||
encodingConfig kavaparams.EncodingConfig,
|
encodingConfig chainparams.EncodingConfig,
|
||||||
options Options,
|
options Options,
|
||||||
baseAppOptions ...func(*baseapp.BaseApp),
|
baseAppOptions ...func(*baseapp.BaseApp),
|
||||||
) *App {
|
) *App {
|
||||||
@ -283,7 +263,7 @@ func NewApp(
|
|||||||
legacyAmino := encodingConfig.Amino
|
legacyAmino := encodingConfig.Amino
|
||||||
interfaceRegistry := encodingConfig.InterfaceRegistry
|
interfaceRegistry := encodingConfig.InterfaceRegistry
|
||||||
|
|
||||||
bApp := baseapp.NewBaseApp(appName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
|
bApp := baseapp.NewBaseApp(chaincfg.AppName, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
|
||||||
bApp.SetCommitMultiStoreTracer(traceStore)
|
bApp.SetCommitMultiStoreTracer(traceStore)
|
||||||
bApp.SetVersion(version.Version)
|
bApp.SetVersion(version.Version)
|
||||||
bApp.SetInterfaceRegistry(interfaceRegistry)
|
bApp.SetInterfaceRegistry(interfaceRegistry)
|
||||||
@ -779,7 +759,7 @@ func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.Res
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store current module versions in kava-10 to setup future in-place upgrades.
|
// Store current module versions in 0gChain-10 to setup future in-place upgrades.
|
||||||
// During in-place migrations, the old module versions in the store will be referenced to determine which migrations to run.
|
// During in-place migrations, the old module versions in the store will be referenced to determine which migrations to run.
|
||||||
app.upgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
|
app.upgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
|
||||||
|
|
||||||
@ -818,9 +798,6 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
|
|||||||
// Register custom REST routes
|
// Register custom REST routes
|
||||||
validatorvestingrest.RegisterRoutes(clientCtx, apiSvr.Router)
|
validatorvestingrest.RegisterRoutes(clientCtx, apiSvr.Router)
|
||||||
|
|
||||||
// Register rewrite routes
|
|
||||||
RegisterAPIRouteRewrites(apiSvr.Router)
|
|
||||||
|
|
||||||
// Register GRPC Gateway routes
|
// Register GRPC Gateway routes
|
||||||
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
|
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
|
||||||
authtx.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
|
// 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.
|
// RegisterTxService implements the Application.RegisterTxService method.
|
||||||
// It registers transaction related endpoints on the app's grpc server.
|
// It registers transaction related endpoints on the app's grpc server.
|
||||||
func (app *App) RegisterTxService(clientCtx client.Context) {
|
func (app *App) RegisterTxService(clientCtx client.Context) {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
db "github.com/cometbft/cometbft-db"
|
db "github.com/cometbft/cometbft-db"
|
||||||
abci "github.com/cometbft/cometbft/abci/types"
|
abci "github.com/cometbft/cometbft/abci/types"
|
||||||
"github.com/cometbft/cometbft/libs/log"
|
"github.com/cometbft/cometbft/libs/log"
|
||||||
@ -25,11 +26,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestNewApp(t *testing.T) {
|
func TestNewApp(t *testing.T) {
|
||||||
SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
NewApp(
|
NewApp(
|
||||||
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
log.NewTMLogger(log.NewSyncWriter(os.Stdout)),
|
||||||
db.NewMemDB(),
|
db.NewMemDB(),
|
||||||
DefaultNodeHome,
|
chaincfg.DefaultNodeHome,
|
||||||
nil,
|
nil,
|
||||||
MakeEncodingConfig(),
|
MakeEncodingConfig(),
|
||||||
DefaultOptions,
|
DefaultOptions,
|
||||||
@ -37,9 +38,9 @@ func TestNewApp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExport(t *testing.T) {
|
func TestExport(t *testing.T) {
|
||||||
SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
db := db.NewMemDB()
|
db := db.NewMemDB()
|
||||||
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
app := NewApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, chaincfg.DefaultNodeHome, nil, MakeEncodingConfig(), DefaultOptions, baseapp.SetChainID(TestChainId))
|
||||||
|
|
||||||
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())
|
genesisState := GenesisStateWithSingleValidator(&TestApp{App: *app}, NewDefaultGenesisState())
|
||||||
|
|
||||||
|
@ -1,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
|
It contains the default weights used for each transaction used on the module's
|
||||||
simulation. These weights define the chance for a transaction to be simulated at
|
simulation. These weights define the chance for a transaction to be simulated at
|
||||||
|
@ -41,6 +41,7 @@ import (
|
|||||||
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
feemarketkeeper "github.com/evmos/ethermint/x/feemarket/keeper"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
evmutilkeeper "github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ var (
|
|||||||
defaultInitialHeight int64 = 1
|
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.
|
// 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.
|
// 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.
|
// Note, it also sets the sdk config with the app's address prefix, coin type, etc.
|
||||||
func NewTestApp() TestApp {
|
func NewTestApp() TestApp {
|
||||||
SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
|
|
||||||
return NewTestAppFromSealed()
|
return NewTestAppFromSealed()
|
||||||
}
|
}
|
||||||
@ -86,7 +87,7 @@ func NewTestAppFromSealed() TestApp {
|
|||||||
encCfg := MakeEncodingConfig()
|
encCfg := MakeEncodingConfig()
|
||||||
|
|
||||||
app := NewApp(
|
app := NewApp(
|
||||||
log.NewNopLogger(), db, DefaultNodeHome, nil,
|
log.NewNopLogger(), db, chaincfg.DefaultNodeHome, nil,
|
||||||
encCfg, DefaultOptions, baseapp.SetChainID(TestChainId),
|
encCfg, DefaultOptions, baseapp.SetChainID(TestChainId),
|
||||||
)
|
)
|
||||||
return TestApp{App: *app}
|
return TestApp{App: *app}
|
||||||
@ -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) GetCrisisKeeper() crisiskeeper.Keeper { return tApp.crisisKeeper }
|
||||||
func (tApp TestApp) GetParamsKeeper() paramskeeper.Keeper { return tApp.paramsKeeper }
|
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) GetEvmutilKeeper() evmutilkeeper.Keeper { return tApp.evmutilKeeper }
|
||||||
func (tApp TestApp) GetEvmKeeper() *evmkeeper.Keeper { return tApp.evmKeeper }
|
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) 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 {
|
func (tApp TestApp) GetKVStoreKey(key string) *storetypes.KVStoreKey {
|
||||||
return tApp.keys[key]
|
return tApp.keys[key]
|
||||||
}
|
}
|
||||||
@ -163,7 +147,7 @@ func GenesisStateWithSingleValidator(
|
|||||||
balances := []banktypes.Balance{
|
balances := []banktypes.Balance{
|
||||||
{
|
{
|
||||||
Address: acc.GetAddress().String(),
|
Address: acc.GetAddress().String(),
|
||||||
Coins: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(100000000000000))),
|
Coins: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(100000000000000))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +210,7 @@ func genesisStateWithValSet(
|
|||||||
}
|
}
|
||||||
// set validators and delegations
|
// set validators and delegations
|
||||||
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
currentStakingGenesis := stakingtypes.GetGenesisStateFromAppState(app.appCodec, genesisState)
|
||||||
currentStakingGenesis.Params.BondDenom = "ukava"
|
currentStakingGenesis.Params.BondDenom = chaincfg.DisplayDenom
|
||||||
|
|
||||||
stakingGenesis := stakingtypes.NewGenesisState(
|
stakingGenesis := stakingtypes.NewGenesisState(
|
||||||
currentStakingGenesis.Params,
|
currentStakingGenesis.Params,
|
||||||
@ -246,13 +230,13 @@ func genesisStateWithValSet(
|
|||||||
|
|
||||||
for range delegations {
|
for range delegations {
|
||||||
// add delegated tokens to total supply
|
// add delegated tokens to total supply
|
||||||
totalSupply = totalSupply.Add(sdk.NewCoin("ukava", bondAmt))
|
totalSupply = totalSupply.Add(sdk.NewCoin(chaincfg.DisplayDenom, bondAmt))
|
||||||
}
|
}
|
||||||
|
|
||||||
// add bonded amount to bonded pool module account
|
// add bonded amount to bonded pool module account
|
||||||
balances = append(balances, banktypes.Balance{
|
balances = append(balances, banktypes.Balance{
|
||||||
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
|
||||||
Coins: sdk.Coins{sdk.NewCoin("ukava", bondAmt)},
|
Coins: sdk.Coins{sdk.NewCoin(chaincfg.DisplayDenom, bondAmt)},
|
||||||
})
|
})
|
||||||
|
|
||||||
bankGenesis := banktypes.NewGenesisState(
|
bankGenesis := banktypes.NewGenesisState(
|
||||||
|
@ -62,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")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
||||||
|
|
||||||
// test old bip44 coin type
|
// test old bip44 coin type
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
require.Equal(t, "0g1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
||||||
|
|
||||||
// Cleanup testing directories
|
// Cleanup testing directories
|
||||||
f.Cleanup()
|
f.Cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
func TestZgChainCLIKeysAddRecoverHDPath(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
f := InitFixtures(t)
|
f := InitFixtures(t)
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
||||||
require.Equal(t, "kava1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
require.Equal(t, "0g1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
||||||
require.Equal(t, "kava1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
require.Equal(t, "0g1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
||||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
||||||
|
|
||||||
// test old bip44 coin type
|
// test old bip44 coin type
|
||||||
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
|
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
|
||||||
require.Equal(t, "kava1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
require.Equal(t, "0g1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
||||||
|
|
||||||
exitSuccess, _, _ := f.KeysAddRecover("test-recover-fail", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path --hd-path 44'/459'/0'/0/0")
|
exitSuccess, _, _ := f.KeysAddRecover("test-recover-fail", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path --hd-path 44'/459'/0'/0/0")
|
||||||
require.False(t, exitSuccess)
|
require.False(t, exitSuccess)
|
||||||
@ -99,11 +99,11 @@ func TestKavaCLIKeysAddRecoverHDPath(t *testing.T) {
|
|||||||
// test -hd-path flag
|
// test -hd-path flag
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH6", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/0'/0/0")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH6", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/0'/0/0")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
|
require.Equal(t, "0g1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverH6").String())
|
||||||
|
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH7", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/2'/0/17")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recoverH7", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--hd-path 44'/459'/2'/0/17")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
|
require.Equal(t, "0g1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH7").String())
|
||||||
|
|
||||||
// Cleanup testing directories
|
// Cleanup testing directories
|
||||||
f.Cleanup()
|
f.Cleanup()
|
||||||
|
@ -92,7 +92,7 @@ type Fixtures struct {
|
|||||||
|
|
||||||
// NewFixtures creates a new instance of Fixtures with many vars set
|
// NewFixtures creates a new instance of Fixtures with many vars set
|
||||||
func NewFixtures(t *testing.T) *Fixtures {
|
func NewFixtures(t *testing.T) *Fixtures {
|
||||||
tmpDir, err := ioutil.TempDir("", "kava_integration_"+t.Name()+"_")
|
tmpDir, err := ioutil.TempDir("", "0gchain_integration_"+t.Name()+"_")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
servAddr, port, err := server.FreeTCPAddr()
|
servAddr, port, err := server.FreeTCPAddr()
|
||||||
@ -201,9 +201,9 @@ func (f *Fixtures) Flags() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
//___________________________________________________________________________________
|
||||||
// kavad
|
// 0gchaind
|
||||||
|
|
||||||
// UnsafeResetAll is kavad unsafe-reset-all
|
// UnsafeResetAll is 0gchaind unsafe-reset-all
|
||||||
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s --home=%s unsafe-reset-all", f.KvdBinary, f.KvdHome)
|
||||||
executeWrite(f.T, addFlags(cmd, flags))
|
executeWrite(f.T, addFlags(cmd, flags))
|
||||||
@ -211,7 +211,7 @@ func (f *Fixtures) UnsafeResetAll(flags ...string) {
|
|||||||
require.NoError(f.T, err)
|
require.NoError(f.T, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// KvInit is kavad init
|
// KvInit is 0gchaind init
|
||||||
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
// NOTE: KvInit sets the ChainID for the Fixtures instance
|
||||||
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
|
cmd := fmt.Sprintf("%s init -o --home=%s %s", f.KvdBinary, f.KvdHome, moniker)
|
||||||
@ -229,25 +229,25 @@ func (f *Fixtures) KvInit(moniker string, flags ...string) {
|
|||||||
f.ChainID = chainID
|
f.ChainID = chainID
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddGenesisAccount is kavad add-genesis-account
|
// AddGenesisAccount is 0gchaind add-genesis-account
|
||||||
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
|
func (f *Fixtures) AddGenesisAccount(address sdk.AccAddress, coins sdk.Coins, flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.KvdBinary, address, coins, f.KvdHome)
|
cmd := fmt.Sprintf("%s add-genesis-account %s %s --home=%s --keyring-backend=test", f.KvdBinary, address, coins, f.KvdHome)
|
||||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenTx is kavad gentx
|
// GenTx is 0gchaind gentx
|
||||||
func (f *Fixtures) GenTx(name string, flags ...string) {
|
func (f *Fixtures) GenTx(name string, flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s --keyring-backend=test", f.KvdBinary, name, f.KvdHome, f.KvcliHome)
|
cmd := fmt.Sprintf("%s gentx --name=%s --home=%s --home-client=%s --keyring-backend=test", f.KvdBinary, name, f.KvdHome, f.KvcliHome)
|
||||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CollectGenTxs is kavad collect-gentxs
|
// CollectGenTxs is 0gchaind collect-gentxs
|
||||||
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
func (f *Fixtures) CollectGenTxs(flags ...string) {
|
||||||
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s collect-gentxs --home=%s", f.KvdBinary, f.KvdHome)
|
||||||
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
executeWriteCheckErr(f.T, addFlags(cmd, flags))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GDStart runs kavad start with the appropriate flags and returns a process
|
// GDStart runs 0gchaind start with the appropriate flags and returns a process
|
||||||
func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
||||||
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v --pruning=everything", f.KvdBinary, f.KvdHome, f.RPCAddr, f.P2PAddr)
|
cmd := fmt.Sprintf("%s start --home=%s --rpc.laddr=%v --p2p.laddr=%v --pruning=everything", f.KvdBinary, f.KvdHome, f.RPCAddr, f.P2PAddr)
|
||||||
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
|
proc := tests.GoExecuteTWithStdout(f.T, addFlags(cmd, flags))
|
||||||
@ -256,7 +256,7 @@ func (f *Fixtures) GDStart(flags ...string) *tests.Process {
|
|||||||
return proc
|
return proc
|
||||||
}
|
}
|
||||||
|
|
||||||
// GDTendermint returns the results of kavad tendermint [query]
|
// GDTendermint returns the results of 0gchaind tendermint [query]
|
||||||
func (f *Fixtures) GDTendermint(query string) string {
|
func (f *Fixtures) GDTendermint(query string) string {
|
||||||
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
cmd := fmt.Sprintf("%s tendermint %s --home=%s", f.KvdBinary, query, f.KvdHome)
|
||||||
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
success, stdout, stderr := executeWriteRetStdStreams(f.T, cmd)
|
||||||
@ -265,7 +265,7 @@ func (f *Fixtures) GDTendermint(query string) string {
|
|||||||
return strings.TrimSpace(stdout)
|
return strings.TrimSpace(stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateGenesis runs kavad validate-genesis
|
// ValidateGenesis runs 0gchaind validate-genesis
|
||||||
func (f *Fixtures) ValidateGenesis() {
|
func (f *Fixtures) ValidateGenesis() {
|
||||||
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
cmd := fmt.Sprintf("%s validate-genesis --home=%s", f.KvdBinary, f.KvdHome)
|
||||||
executeWriteCheckErr(f.T, cmd)
|
executeWriteCheckErr(f.T, cmd)
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
swagger: "2.0"
|
swagger: "2.0"
|
||||||
info:
|
info:
|
||||||
version: "3.0"
|
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.
|
description: A REST interface for state queries, transaction generation and broadcasting.
|
||||||
tags:
|
tags:
|
||||||
- name: Vesting
|
- name: Vesting
|
||||||
description: Validator vesting module APIs
|
description: Validator vesting module APIs
|
||||||
schemes:
|
schemes:
|
||||||
- https
|
- https
|
||||||
host: api.data.kava.io
|
host: api.data.0g-chain.io
|
||||||
securityDefinitions:
|
securityDefinitions:
|
||||||
kms:
|
kms:
|
||||||
type: basic
|
type: basic
|
||||||
@ -17,14 +17,14 @@ paths:
|
|||||||
/vesting/circulatingsupply:
|
/vesting/circulatingsupply:
|
||||||
get:
|
get:
|
||||||
deprecated: true
|
deprecated: true
|
||||||
summary: Get the current circulating supply of KAVA
|
summary: Get the current circulating supply of 0g-chain
|
||||||
tags:
|
tags:
|
||||||
- Vesting
|
- Vesting
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: KAVA circulating supply
|
description: 0g-chain circulating supply
|
||||||
schema:
|
schema:
|
||||||
properties:
|
properties:
|
||||||
height:
|
height:
|
||||||
@ -38,14 +38,14 @@ paths:
|
|||||||
/vesting/totalsupply:
|
/vesting/totalsupply:
|
||||||
get:
|
get:
|
||||||
deprecated: true
|
deprecated: true
|
||||||
summary: Get the total supply of KAVA
|
summary: Get the total supply of 0g-chain
|
||||||
tags:
|
tags:
|
||||||
- Vesting
|
- Vesting
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: KAVA total supply
|
description: 0g-chain total supply
|
||||||
schema:
|
schema:
|
||||||
properties:
|
properties:
|
||||||
height:
|
height:
|
||||||
|
@ -7,29 +7,29 @@ import (
|
|||||||
"github.com/0glabs/0g-chain/client/grpc/util"
|
"github.com/0glabs/0g-chain/client/grpc/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KavaGrpcClient enables the usage of kava grpc query clients and query utils
|
// ZgChainGrpcClient enables the usage of 0gChain grpc query clients and query utils
|
||||||
type KavaGrpcClient struct {
|
type ZgChainGrpcClient struct {
|
||||||
config KavaGrpcClientConfig
|
config ZgChainGrpcClientConfig
|
||||||
|
|
||||||
// Query clients for cosmos and kava modules
|
// Query clients for cosmos and 0gChain modules
|
||||||
Query *query.QueryClient
|
Query *query.QueryClient
|
||||||
|
|
||||||
// Utils for common queries (ie fetch an unpacked BaseAccount)
|
// Utils for common queries (ie fetch an unpacked BaseAccount)
|
||||||
*util.Util
|
*util.Util
|
||||||
}
|
}
|
||||||
|
|
||||||
// KavaGrpcClientConfig is a configuration struct for a KavaGrpcClient
|
// ZgChainGrpcClientConfig is a configuration struct for a ZgChainGrpcClient
|
||||||
type KavaGrpcClientConfig struct {
|
type ZgChainGrpcClientConfig struct {
|
||||||
// note: add future config options here
|
// note: add future config options here
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new KavaGrpcClient via a grpc url
|
// NewClient creates a new ZgChainGrpcClient via a grpc url
|
||||||
func NewClient(grpcUrl string) (*KavaGrpcClient, error) {
|
func NewClient(grpcUrl string) (*ZgChainGrpcClient, error) {
|
||||||
return NewClientWithConfig(grpcUrl, NewDefaultConfig())
|
return NewClientWithConfig(grpcUrl, NewDefaultConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClientWithConfig creates a new KavaGrpcClient via a grpc url and config
|
// NewClientWithConfig creates a new ZgChainGrpcClient via a grpc url and config
|
||||||
func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpcClient, error) {
|
func NewClientWithConfig(grpcUrl string, config ZgChainGrpcClientConfig) (*ZgChainGrpcClient, error) {
|
||||||
if grpcUrl == "" {
|
if grpcUrl == "" {
|
||||||
return nil, errors.New("grpc url cannot be empty")
|
return nil, errors.New("grpc url cannot be empty")
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
|
|||||||
if error != nil {
|
if error != nil {
|
||||||
return nil, error
|
return nil, error
|
||||||
}
|
}
|
||||||
client := &KavaGrpcClient{
|
client := &ZgChainGrpcClient{
|
||||||
Query: query,
|
Query: query,
|
||||||
Util: util.NewUtil(query),
|
Util: util.NewUtil(query),
|
||||||
config: config,
|
config: config,
|
||||||
@ -45,6 +45,6 @@ func NewClientWithConfig(grpcUrl string, config KavaGrpcClientConfig) (*KavaGrpc
|
|||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultConfig() KavaGrpcClientConfig {
|
func NewDefaultConfig() ZgChainGrpcClientConfig {
|
||||||
return KavaGrpcClientConfig{}
|
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 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
|
package query
|
||||||
|
@ -24,24 +24,12 @@ import (
|
|||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
|
||||||
|
|
||||||
// auctiontypes "github.com/0glabs/0g-chain/x/auction/types"
|
committeetypes "github.com/0glabs/0g-chain/x/committee/v1/types"
|
||||||
// bep3types "github.com/0glabs/0g-chain/x/bep3/types"
|
dastypes "github.com/0glabs/0g-chain/x/das/v1/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"
|
|
||||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/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 {
|
type QueryClient struct {
|
||||||
// cosmos-sdk query clients
|
// cosmos-sdk query clients
|
||||||
|
|
||||||
@ -68,23 +56,11 @@ type QueryClient struct {
|
|||||||
IbcClient ibcclienttypes.QueryClient
|
IbcClient ibcclienttypes.QueryClient
|
||||||
IbcTransfer ibctransfertypes.QueryClient
|
IbcTransfer ibctransfertypes.QueryClient
|
||||||
|
|
||||||
// kava module query clients
|
// 0g-chain module query clients
|
||||||
|
|
||||||
// Auction auctiontypes.QueryClient
|
Committee committeetypes.QueryClient
|
||||||
// Bep3 bep3types.QueryClient
|
Das dastypes.QueryClient
|
||||||
// Cdp cdptypes.QueryClient
|
Evmutil evmutiltypes.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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewQueryClient creates a new QueryClient and initializes all the module query clients
|
// 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),
|
IbcClient: ibcclienttypes.NewQueryClient(conn),
|
||||||
IbcTransfer: ibctransfertypes.NewQueryClient(conn),
|
IbcTransfer: ibctransfertypes.NewQueryClient(conn),
|
||||||
|
|
||||||
// Auction: auctiontypes.NewQueryClient(conn),
|
Committee: committeetypes.NewQueryClient(conn),
|
||||||
// Bep3: bep3types.NewQueryClient(conn),
|
Das: dastypes.NewQueryClient(conn),
|
||||||
// Cdp: cdptypes.NewQueryClient(conn),
|
Evmutil: evmutiltypes.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),
|
|
||||||
}
|
}
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
@ -54,21 +54,9 @@ func TestNewQueryClient_ValidClient(t *testing.T) {
|
|||||||
require.NotNil(t, client.IbcClient)
|
require.NotNil(t, client.IbcClient)
|
||||||
require.NotNil(t, client.IbcTransfer)
|
require.NotNil(t, client.IbcTransfer)
|
||||||
|
|
||||||
// validate kava clients
|
// validate 0gChain 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)
|
|
||||||
require.NotNil(t, client.Evmutil)
|
require.NotNil(t, client.Evmutil)
|
||||||
// require.NotNil(t, client.Hard)
|
require.NotNil(t, client.Committee)
|
||||||
// require.NotNil(t, client.Incentive)
|
require.NotNil(t, client.Das)
|
||||||
// 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)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -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.
|
For example, `account.go` includes account-related query helpers.
|
||||||
In this file, utilities such as `client.Util.BaseAccount(addr)` is exposed to
|
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"
|
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 {
|
type Util struct {
|
||||||
query *query.QueryClient
|
query *query.QueryClient
|
||||||
encodingConfig params.EncodingConfig
|
encodingConfig params.EncodingConfig
|
||||||
|
@ -33,7 +33,7 @@ const (
|
|||||||
flagSkipLoadLatest = "skip-load-latest"
|
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
|
// The methods implement types in cosmos-sdk/server/types
|
||||||
type appCreator struct {
|
type appCreator struct {
|
||||||
encodingConfig params.EncodingConfig
|
encodingConfig params.EncodingConfig
|
||||||
|
@ -39,7 +39,7 @@ func newShardCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
|||||||
cmd := &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>]",
|
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",
|
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.
|
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.
|
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.`,
|
WARNING: this is a destructive action.`,
|
||||||
Example: `Create a 1M block data shard (keeps blocks kava 1,000,000 to 2,000,000)
|
Example: `Create a 1M block data shard (keeps blocks a0gi 1,000,000 to 2,000,000)
|
||||||
$ kava shard --home path/to/.kava --start 1000000 --end 2000000
|
$ 0gchaind shard --home path/to/.0gchain --start 1000000 --end 2000000
|
||||||
|
|
||||||
Prune all blocks up to 5,000,000:
|
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:
|
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 {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
//////////////////////////
|
//////////////////////////
|
||||||
// parse & validate flags
|
// parse & validate flags
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//go:build rocksdb
|
//go:build rocksdb
|
||||||
// +build rocksdb
|
// +build rocksdb
|
||||||
|
|
||||||
// Copyright 2023 Kava Labs, Inc.
|
// Copyright 2024 0glabs Labs, Inc.
|
||||||
// Copyright 2023 Cronos Labs, Inc.
|
// Copyright 2023 Cronos Labs, Inc.
|
||||||
//
|
//
|
||||||
// Derived from https://github.com/crypto-org-chain/cronos@496ce7e
|
// 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/token/ERC20/ERC20.sol";
|
||||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||||
|
|
||||||
/// @title An ERC20 token contract owned and deployed by the evmutil module of Kava.
|
/// @title An ERC20 token contract owned and deployed by the evmutil module of 0g-chain.
|
||||||
/// Tokens are backed one-for-one by cosmos-sdk coins held in the module account.
|
/// Tokens are backed one-for-one by cosmos-sdk coins held in the module account.
|
||||||
/// @author Kava Labs, LLC
|
/// @author 0g Labs, LLC
|
||||||
/// @custom:security-contact security@kava.io
|
/// @custom:security-contact security@0g.ai
|
||||||
contract ERC20KavaWrappedCosmosCoin is ERC20, Ownable {
|
contract ERC200gChainWrappedCosmosCoin is ERC20, Ownable {
|
||||||
/// @notice The decimals places of the token. For display purposes only.
|
/// @notice The decimals places of the token. For display purposes only.
|
||||||
uint8 private immutable _decimals;
|
uint8 private immutable _decimals;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ const config: HardhatUserConfig = {
|
|||||||
solidity: {
|
solidity: {
|
||||||
version: "0.8.18",
|
version: "0.8.18",
|
||||||
settings: {
|
settings: {
|
||||||
// istanbul upgrade occurred before the london hardfork, so is compatible with kava's evm
|
// istanbul upgrade occurred before the london hardfork, so is compatible with 0g-chain's evm
|
||||||
evmVersion: "istanbul",
|
evmVersion: "istanbul",
|
||||||
// optimize build for deployment to mainnet!
|
// optimize build for deployment to mainnet!
|
||||||
optimizer: {
|
optimizer: {
|
||||||
@ -16,21 +16,21 @@ const config: HardhatUserConfig = {
|
|||||||
},
|
},
|
||||||
networks: {
|
networks: {
|
||||||
// kvtool's local network
|
// kvtool's local network
|
||||||
kava: {
|
chain: {
|
||||||
url: "http://127.0.0.1:8545",
|
url: "http://127.0.0.1:8545",
|
||||||
accounts: [
|
accounts: [
|
||||||
// kava keys unsafe-export-eth-key whale2
|
// 0g-chain keys unsafe-export-eth-key whale2
|
||||||
"AA50F4C6C15190D9E18BF8B14FC09BFBA0E7306331A4F232D10A77C2879E7966",
|
"AA50F4C6C15190D9E18BF8B14FC09BFBA0E7306331A4F232D10A77C2879E7966",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
protonet: {
|
protonet: {
|
||||||
url: "https://evm.app.protonet.us-east.production.kava.io:443",
|
url: "https://evm.app.protonet.us-east.production.0g-chain.io:443",
|
||||||
accounts: [
|
accounts: [
|
||||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
internal_testnet: {
|
internal_testnet: {
|
||||||
url: "https://evm.data.internal.testnet.us-east.production.kava.io:443",
|
url: "https://evm.data.internal.testnet.us-east.production.0g-chain.io:443",
|
||||||
accounts: [
|
accounts: [
|
||||||
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
"247069F0BC3A5914CB2FD41E4133BBDAA6DBED9F47A01B9F110B5602C6E4CDD9",
|
||||||
],
|
],
|
||||||
|
4
contracts/package-lock.json
generated
4
contracts/package-lock.json
generated
@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"name": "kava-contracts",
|
"name": "0g-chain-contracts",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "kava-contracts",
|
"name": "0g-chain-contracts",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "kava-contracts",
|
"name": "0g-chain-contracts",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"author": "Kava Labs",
|
"author": "0g Labs",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Solidity contracts for Kava Blockchain",
|
"description": "Solidity contracts for 0g Blockchain",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
},
|
},
|
||||||
@ -12,7 +12,7 @@
|
|||||||
"clean": "hardhat clean",
|
"clean": "hardhat clean",
|
||||||
"compile": "hardhat compile",
|
"compile": "hardhat compile",
|
||||||
"coverage": "hardhat coverage",
|
"coverage": "hardhat coverage",
|
||||||
"ethermint-json": "jq '{ abi: .abi | tostring, bin: .bytecode | ltrimstr(\"0x\")}' artifacts/contracts/ERC20KavaWrappedCosmosCoin.sol/ERC20KavaWrappedCosmosCoin.json > ../x/evmutil/types/ethermint_json/ERC20KavaWrappedCosmosCoin.json",
|
"ethermint-json": "jq '{ abi: .abi | tostring, bin: .bytecode | ltrimstr(\"0x\")}' artifacts/contracts/ERC200gChainWrappedCosmosCoin.sol/ERC200gChainWrappedCosmosCoin.json > ../x/evmutil/types/ethermint_json/ERC200gChainWrappedCosmosCoin.json",
|
||||||
"gen-ts-types": "hardhat typechain",
|
"gen-ts-types": "hardhat typechain",
|
||||||
"lint": "eslint '**/*.{js,ts}'",
|
"lint": "eslint '**/*.{js,ts}'",
|
||||||
"lint-fix": "eslint '**/*.{js,ts}' --fix",
|
"lint-fix": "eslint '**/*.{js,ts}' --fix",
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import { ethers } from "hardhat";
|
import { ethers } from "hardhat";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const tokenName = "Kava-wrapped ATOM";
|
const tokenName = "0g-chain-wrapped ATOM";
|
||||||
const tokenSymbol = "kATOM";
|
const tokenSymbol = "kATOM";
|
||||||
const tokenDecimals = 6;
|
const tokenDecimals = 6;
|
||||||
|
|
||||||
const ERC20KavaWrappedCosmosCoin = await ethers.getContractFactory(
|
const ERC200gChainWrappedCosmosCoin = await ethers.getContractFactory(
|
||||||
"ERC20KavaWrappedCosmosCoin"
|
"ERC200gChainWrappedCosmosCoin"
|
||||||
);
|
);
|
||||||
const token = await ERC20KavaWrappedCosmosCoin.deploy(
|
const token = await ERC200gChainWrappedCosmosCoin.deploy(
|
||||||
tokenName,
|
tokenName,
|
||||||
tokenSymbol,
|
tokenSymbol,
|
||||||
tokenDecimals
|
tokenDecimals
|
||||||
|
@ -2,21 +2,21 @@ import { expect } from "chai";
|
|||||||
import { Signer } from "ethers";
|
import { Signer } from "ethers";
|
||||||
import { ethers } from "hardhat";
|
import { ethers } from "hardhat";
|
||||||
import {
|
import {
|
||||||
ERC20KavaWrappedCosmosCoin,
|
ERC200gChainWrappedCosmosCoin,
|
||||||
ERC20KavaWrappedCosmosCoin__factory as ERC20KavaWrappedCosmosCoinFactory,
|
ERC200gChainWrappedCosmosCoin__factory as ERC200gChainWrappedCosmosCoinFactory,
|
||||||
} from "../typechain-types";
|
} from "../typechain-types";
|
||||||
|
|
||||||
const decimals = 6n;
|
const decimals = 6n;
|
||||||
|
|
||||||
describe("ERC20KavaWrappedCosmosCoin", function () {
|
describe("ERC200gChainWrappedCosmosCoin", function () {
|
||||||
let erc20: ERC20KavaWrappedCosmosCoin;
|
let erc20: ERC200gChainWrappedCosmosCoin;
|
||||||
let erc20Factory: ERC20KavaWrappedCosmosCoinFactory;
|
let erc20Factory: ERC200gChainWrappedCosmosCoinFactory;
|
||||||
let owner: Signer;
|
let owner: Signer;
|
||||||
let sender: Signer;
|
let sender: Signer;
|
||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
erc20Factory = await ethers.getContractFactory(
|
erc20Factory = await ethers.getContractFactory(
|
||||||
"ERC20KavaWrappedCosmosCoin"
|
"ERC200gChainWrappedCosmosCoin"
|
||||||
);
|
);
|
||||||
erc20 = await erc20Factory.deploy("Wrapped ATOM", "ATOM", decimals);
|
erc20 = await erc20Factory.deploy("Wrapped ATOM", "ATOM", decimals);
|
||||||
[owner, sender] = await ethers.getSigners();
|
[owner, sender] = await ethers.getSigners();
|
||||||
|
@ -3,7 +3,7 @@ version: '3'
|
|||||||
services:
|
services:
|
||||||
kvdnode0:
|
kvdnode0:
|
||||||
container_name: kvdnode0
|
container_name: kvdnode0
|
||||||
image: "kava/kavanode"
|
image: "0glabs/0g-chain-node"
|
||||||
ports:
|
ports:
|
||||||
- "26656-26657:26656-26657"
|
- "26656-26657:26656-26657"
|
||||||
environment:
|
environment:
|
||||||
@ -17,7 +17,7 @@ services:
|
|||||||
|
|
||||||
kvdnode1:
|
kvdnode1:
|
||||||
container_name: kvdnode1
|
container_name: kvdnode1
|
||||||
image: "kava/kavanode"
|
image: "0glabs/0g-chain-node"
|
||||||
ports:
|
ports:
|
||||||
- "26659-26660:26656-26657"
|
- "26659-26660:26656-26657"
|
||||||
environment:
|
environment:
|
||||||
@ -31,7 +31,7 @@ services:
|
|||||||
|
|
||||||
kvdnode2:
|
kvdnode2:
|
||||||
container_name: kvdnode2
|
container_name: kvdnode2
|
||||||
image: "kava/kavanode"
|
image: "0glabs/0g-chain-node"
|
||||||
environment:
|
environment:
|
||||||
- ID=2
|
- ID=2
|
||||||
- LOG=${LOG:-kvd.log}
|
- LOG=${LOG:-kvd.log}
|
||||||
@ -45,7 +45,7 @@ services:
|
|||||||
|
|
||||||
kvdnode3:
|
kvdnode3:
|
||||||
container_name: kvdnode3
|
container_name: kvdnode3
|
||||||
image: "kava/kavanode"
|
image: "0glabs/0g-chain-node"
|
||||||
environment:
|
environment:
|
||||||
- ID=3
|
- ID=3
|
||||||
- LOG=${LOG:-kvd.log}
|
- 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.
|
Genesis migration starts a whole new blockchain (with new chain-id) for the new software version.
|
||||||
In-Place upgrade keeps the blockchain (and chain-id) the same for the new software version.
|
In-Place upgrade keeps the blockchain (and chain-id) the same for the new software version.
|
||||||
|
|
||||||
We only support migrations between mainnet kava releases.
|
We only support migrations between mainnet 0g-chain releases.
|
||||||
We only support migrations from the previous mainnet kava version to the current. We don't support migrating between two old versions, use the old software version for this.
|
We only support migrations from the previous mainnet 0g-chain version to the current. We don't support migrating between two old versions, use the old software version for this.
|
||||||
We only support migrations from old to new versions, not the other way around.
|
We only support migrations from old to new versions, not the other way around.
|
||||||
|
|
||||||
Genesis Migration
|
Genesis Migration
|
||||||
@ -22,7 +22,7 @@ The process is:
|
|||||||
- marshal it to json (using current codec)
|
- marshal it to json (using current codec)
|
||||||
|
|
||||||
On each release we can delete the previous releases migration and old GenesisState type.
|
On each release we can delete the previous releases migration and old GenesisState type.
|
||||||
eg kava-3 migrates `auth.GenesisState` from kava-2 to `auth.GenesisState` from kava-3,
|
eg 0g-chain-3 migrates `auth.GenesisState` from 0g-chain-2 to `auth.GenesisState` from 0g-chain-3,
|
||||||
but for kava-4 we don't need to keep around kava-2's `auth.GenesisState` type.
|
but for 0g-chain-4 we don't need to keep around 0g-chain-2's `auth.GenesisState` type.
|
||||||
*/
|
*/
|
||||||
package migrate
|
package migrate
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
@ -41,7 +42,7 @@ func TestResetPeriodVestingAccount_NoVestingPeriods(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
||||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
@ -64,7 +65,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vested(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
||||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
@ -97,7 +98,7 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_Vesting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
|
func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing.T) {
|
||||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6)))
|
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6)))
|
||||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
@ -125,25 +126,25 @@ func TestResetPeriodVestingAccount_SingleVestingPeriod_ExactStartTime(t *testing
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
||||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(4e6)))
|
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(4e6)))
|
||||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // +30 days - vesting
|
Length: 15 * 24 * 60 * 60, // +30 days - vesting
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,36 +160,36 @@ func TestResetPeriodVestingAccount_MultiplePeriods(t *testing.T) {
|
|||||||
expectedPeriods := []vestingtypes.Period{
|
expectedPeriods := []vestingtypes.Period{
|
||||||
{
|
{
|
||||||
Length: 15 * 24 * 60 * 60, // 15 days
|
Length: 15 * 24 * 60 * 60, // 15 days
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Length: 15 * 24 * 60 * 60, // 15 days
|
Length: 15 * 24 * 60 * 60, // 15 days
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2e6))), vacc.OriginalVesting, "expected original vesting to be updated")
|
||||||
assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated")
|
assert.Equal(t, newVestingStartTime.Unix(), vacc.StartTime, "expected vesting start time to be updated")
|
||||||
assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period")
|
assert.Equal(t, expectedEndtime, vacc.EndTime, "expected vesting end time end at last period")
|
||||||
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
|
assert.Equal(t, expectedPeriods, vacc.VestingPeriods, "expected vesting periods to be updated")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) {
|
func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testing.T) {
|
||||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(3e6)))
|
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3e6)))
|
||||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,35 +199,35 @@ func TestResetPeriodVestingAccount_DelegatedVesting_GreaterThanVesting(t *testin
|
|||||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||||
|
|
||||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2e6))), vacc.DelegatedFree, "expected delegated free to be updated")
|
||||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be updated")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
|
func TestResetPeriodVestingAccount_DelegatedVesting_LessThanVested(t *testing.T) {
|
||||||
balance := sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(3e6)))
|
balance := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(3e6)))
|
||||||
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
vestingStartTime := time.Now().Add(-30 * 24 * time.Hour) // 30 days in past
|
||||||
|
|
||||||
periods := vestingtypes.Periods{
|
periods := vestingtypes.Periods{
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
Length: 15 * 24 * 60 * 60, // -15 days - vested
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
Length: 15 * 24 * 60 * 60, // 0 days - exact on the start time
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
vestingtypes.Period{
|
vestingtypes.Period{
|
||||||
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
Length: 15 * 24 * 60 * 60, // +15 days - vesting
|
||||||
Amount: sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))),
|
Amount: sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
vacc := createVestingAccount(balance, vestingStartTime, periods)
|
vacc := createVestingAccount(balance, vestingStartTime, periods)
|
||||||
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))))
|
vacc.TrackDelegation(vestingStartTime, balance, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))))
|
||||||
|
|
||||||
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
newVestingStartTime := vestingStartTime.Add(30 * 24 * time.Hour)
|
||||||
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
ResetPeriodicVestingAccount(vacc, newVestingStartTime)
|
||||||
|
|
||||||
assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified")
|
assert.Equal(t, sdk.Coins(nil), vacc.DelegatedFree, "expected delegrated free to be unmodified")
|
||||||
assert.Equal(t, sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
assert.Equal(t, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(1e6))), vacc.DelegatedVesting, "expected delegated vesting to be unmodified")
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
all:
|
all:
|
||||||
docker build --tag kava/kavanode kavanode
|
docker build --tag 0glabs/0g-chain-node 0g-chain-node
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
|
@ -10,29 +10,29 @@ import (
|
|||||||
|
|
||||||
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_NonAuthority() {
|
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_NonAuthority() {
|
||||||
// // ARRANGE
|
// // ARRANGE
|
||||||
// // setup kava account
|
// // setup 0g account
|
||||||
// funds := ukava(1e5) // .1 KAVA
|
// funds := a0gi(1e5) // .1 A0GI
|
||||||
// kavaAcc := suite.Kava.NewFundedAccount("community-non-authority", sdk.NewCoins(funds))
|
// zgChainAcc := suite.ZgChain.NewFundedAccount("community-non-authority", sdk.NewCoins(funds))
|
||||||
|
|
||||||
// gasLimit := int64(2e5)
|
// gasLimit := int64(2e5)
|
||||||
// fee := ukava(200)
|
// fee := a0gi(200)
|
||||||
|
|
||||||
// msg := communitytypes.NewMsgUpdateParams(
|
// msg := communitytypes.NewMsgUpdateParams(
|
||||||
// kavaAcc.SdkAddress,
|
// zgChainAcc.SdkAddress,
|
||||||
// communitytypes.DefaultParams(),
|
// communitytypes.DefaultParams(),
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// // ACT
|
// // ACT
|
||||||
// req := util.KavaMsgRequest{
|
// req := util.ZgChainMsgRequest{
|
||||||
// Msgs: []sdk.Msg{&msg},
|
// Msgs: []sdk.Msg{&msg},
|
||||||
// GasLimit: uint64(gasLimit),
|
// GasLimit: uint64(gasLimit),
|
||||||
// FeeAmount: sdk.NewCoins(fee),
|
// FeeAmount: sdk.NewCoins(fee),
|
||||||
// Memo: "this is a failure!",
|
// Memo: "this is a failure!",
|
||||||
// }
|
// }
|
||||||
// res := kavaAcc.SignAndBroadcastKavaTx(req)
|
// res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||||
|
|
||||||
// // ASSERT
|
// // 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().Error(err)
|
||||||
// suite.Require().ErrorContains(
|
// suite.Require().ErrorContains(
|
||||||
// err,
|
// err,
|
||||||
@ -43,32 +43,32 @@ import (
|
|||||||
|
|
||||||
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_Authority() {
|
// func (suite *IntegrationTestSuite) TestCommunityUpdateParams_Authority() {
|
||||||
// // ARRANGE
|
// // 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,
|
// ParamsType: govv1.ParamDeposit,
|
||||||
// })
|
// })
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
|
|
||||||
// // Check initial params
|
// // Check initial params
|
||||||
// communityParamsResInitial, err := suite.Kava.Grpc.Query.Community.Params(
|
// communityParamsResInitial, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &communitytypes.QueryParamsRequest{},
|
// &communitytypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
// // setup kava account
|
// // setup 0g account
|
||||||
// // .1 KAVA + min deposit amount for proposal
|
// // .1 A0GI + min deposit amount for proposal
|
||||||
// funds := sdk.NewCoins(ukava(1e5)).Add(govParamsRes.DepositParams.MinDeposit...)
|
// funds := sdk.NewCoins(a0gi(1e5)).Add(govParamsRes.DepositParams.MinDeposit...)
|
||||||
// kavaAcc := suite.Kava.NewFundedAccount("community-update-params", funds)
|
// zgChainAcc := suite.ZgChain.NewFundedAccount("community-update-params", funds)
|
||||||
|
|
||||||
// gasLimit := int64(2e5)
|
// gasLimit := int64(2e5)
|
||||||
// fee := ukava(200)
|
// fee := a0gi(200)
|
||||||
|
|
||||||
// // Wait until switchover actually happens - When testing without the upgrade
|
// // Wait until switchover actually happens - When testing without the upgrade
|
||||||
// // handler that sets a relative switchover time, the switchover time in
|
// // handler that sets a relative switchover time, the switchover time in
|
||||||
// // genesis should be set in the past so it runs immediately.
|
// // genesis should be set in the past so it runs immediately.
|
||||||
// suite.Require().Eventually(
|
// suite.Require().Eventually(
|
||||||
// func() bool {
|
// func() bool {
|
||||||
// params, err := suite.Kava.Grpc.Query.Community.Params(
|
// params, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &communitytypes.QueryParamsRequest{},
|
// &communitytypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -108,24 +108,24 @@ import (
|
|||||||
// proposalMsg, err := govv1.NewMsgSubmitProposal(
|
// proposalMsg, err := govv1.NewMsgSubmitProposal(
|
||||||
// []sdk.Msg{&updateParamsMsg},
|
// []sdk.Msg{&updateParamsMsg},
|
||||||
// govParamsRes.Params.MinDeposit,
|
// govParamsRes.Params.MinDeposit,
|
||||||
// kavaAcc.SdkAddress.String(),
|
// zgChainAcc.SdkAddress.String(),
|
||||||
// "community-update-params",
|
// "community-update-params",
|
||||||
// "title",
|
// "title",
|
||||||
// "summary",
|
// "summary",
|
||||||
// )
|
// )
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
|
|
||||||
// req := util.KavaMsgRequest{
|
// req := util.ZgChainMsgRequest{
|
||||||
// Msgs: []sdk.Msg{proposalMsg},
|
// Msgs: []sdk.Msg{proposalMsg},
|
||||||
// GasLimit: uint64(gasLimit),
|
// GasLimit: uint64(gasLimit),
|
||||||
// FeeAmount: sdk.NewCoins(fee),
|
// FeeAmount: sdk.NewCoins(fee),
|
||||||
// Memo: "this is a proposal please accept me",
|
// Memo: "this is a proposal please accept me",
|
||||||
// }
|
// }
|
||||||
// res := kavaAcc.SignAndBroadcastKavaTx(req)
|
// res := zgChainAcc.SignAndBroadcastZgChainTx(req)
|
||||||
// suite.Require().NoError(res.Err)
|
// suite.Require().NoError(res.Err)
|
||||||
|
|
||||||
// // Wait for proposal to be submitted
|
// // Wait for proposal to be submitted
|
||||||
// txRes, err := util.WaitForSdkTxCommit(suite.Kava.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)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
// // Parse tx response to get proposal id
|
// // Parse tx response to get proposal id
|
||||||
@ -133,7 +133,7 @@ import (
|
|||||||
// suite.decodeTxMsgResponse(txRes, &govRes)
|
// suite.decodeTxMsgResponse(txRes, &govRes)
|
||||||
|
|
||||||
// // 2. Vote for proposal from whale account
|
// // 2. Vote for proposal from whale account
|
||||||
// whale := suite.Kava.GetAccount(testutil.FundedAccountName)
|
// whale := suite.ZgChain.GetAccount(testutil.FundedAccountName)
|
||||||
// voteMsg := govv1.NewMsgVote(
|
// voteMsg := govv1.NewMsgVote(
|
||||||
// whale.SdkAddress,
|
// whale.SdkAddress,
|
||||||
// govRes.ProposalId,
|
// govRes.ProposalId,
|
||||||
@ -141,21 +141,21 @@ import (
|
|||||||
// "",
|
// "",
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// voteReq := util.KavaMsgRequest{
|
// voteReq := util.ZgChainMsgRequest{
|
||||||
// Msgs: []sdk.Msg{voteMsg},
|
// Msgs: []sdk.Msg{voteMsg},
|
||||||
// GasLimit: uint64(gasLimit),
|
// GasLimit: uint64(gasLimit),
|
||||||
// FeeAmount: sdk.NewCoins(fee),
|
// FeeAmount: sdk.NewCoins(fee),
|
||||||
// Memo: "voting",
|
// Memo: "voting",
|
||||||
// }
|
// }
|
||||||
// voteRes := whale.SignAndBroadcastKavaTx(voteReq)
|
// voteRes := whale.SignAndBroadcastZgChainTx(voteReq)
|
||||||
// suite.Require().NoError(voteRes.Err)
|
// suite.Require().NoError(voteRes.Err)
|
||||||
|
|
||||||
// _, err = util.WaitForSdkTxCommit(suite.Kava.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)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
// // 3. Wait until proposal passes
|
// // 3. Wait until proposal passes
|
||||||
// suite.Require().Eventually(func() bool {
|
// suite.Require().Eventually(func() bool {
|
||||||
// proposalRes, err := suite.Kava.Grpc.Query.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
// proposalRes, err := suite.ZgChain.Grpc.Query.Gov.Proposal(context.Background(), &govv1.QueryProposalRequest{
|
||||||
// ProposalId: govRes.ProposalId,
|
// ProposalId: govRes.ProposalId,
|
||||||
// })
|
// })
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
@ -164,7 +164,7 @@ import (
|
|||||||
// }, 60*time.Second, 1*time.Second)
|
// }, 60*time.Second, 1*time.Second)
|
||||||
|
|
||||||
// // Check parameters are updated
|
// // Check parameters are updated
|
||||||
// communityParamsRes, err := suite.Kava.Grpc.Query.Community.Params(
|
// communityParamsRes, err := suite.ZgChain.Grpc.Query.Community.Params(
|
||||||
// context.Background(),
|
// context.Background(),
|
||||||
// &communitytypes.QueryParamsRequest{},
|
// &communitytypes.QueryParamsRequest{},
|
||||||
// )
|
// )
|
||||||
@ -180,10 +180,10 @@ func (suite *IntegrationTestSuite) decodeTxMsgResponse(txRes *sdk.TxResponse, pt
|
|||||||
|
|
||||||
// Unmarshal data to TxMsgData
|
// Unmarshal data to TxMsgData
|
||||||
var txMsgData sdk.TxMsgData
|
var txMsgData sdk.TxMsgData
|
||||||
suite.Kava.EncodingConfig.Marshaler.MustUnmarshal(txResBytes, &txMsgData)
|
suite.ZgChain.EncodingConfig.Marshaler.MustUnmarshal(txResBytes, &txMsgData)
|
||||||
suite.T().Logf("txData.MsgResponses: %v", txMsgData.MsgResponses)
|
suite.T().Logf("txData.MsgResponses: %v", txMsgData.MsgResponses)
|
||||||
|
|
||||||
// Parse MsgResponse
|
// Parse MsgResponse
|
||||||
suite.Kava.EncodingConfig.Marshaler.MustUnmarshal(txMsgData.MsgResponses[0].Value, ptr)
|
suite.ZgChain.EncodingConfig.Marshaler.MustUnmarshal(txMsgData.MsgResponses[0].Value, ptr)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
@ -24,24 +24,24 @@ func setupConvertToCoinTest(
|
|||||||
) (denom string, initialFunds sdk.Coins, user *testutil.SigningAccount) {
|
) (denom string, initialFunds sdk.Coins, user *testutil.SigningAccount) {
|
||||||
// we expect a denom to be registered to the allowed denoms param
|
// we expect a denom to be registered to the allowed denoms param
|
||||||
// and for the funded account to have a balance for that denom
|
// and for the funded account to have a balance for that denom
|
||||||
params, err := suite.Kava.Grpc.Query.Evmutil.Params(
|
params, err := suite.ZgChain.Grpc.Query.Evmutil.Params(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&evmutiltypes.QueryParamsRequest{},
|
&evmutiltypes.QueryParamsRequest{},
|
||||||
)
|
)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.GreaterOrEqual(
|
suite.GreaterOrEqual(
|
||||||
len(params.Params.AllowedCosmosDenoms), 1,
|
len(params.Params.AllowedCosmosDenoms), 1,
|
||||||
"kava chain expected to have at least one AllowedCosmosDenom for ERC20 conversion",
|
"0g-chain expected to have at least one AllowedCosmosDenom for ERC20 conversion",
|
||||||
)
|
)
|
||||||
|
|
||||||
tokenInfo := params.Params.AllowedCosmosDenoms[0]
|
tokenInfo := params.Params.AllowedCosmosDenoms[0]
|
||||||
denom = tokenInfo.CosmosDenom
|
denom = tokenInfo.CosmosDenom
|
||||||
initialFunds = sdk.NewCoins(
|
initialFunds = sdk.NewCoins(
|
||||||
sdk.NewInt64Coin(suite.Kava.StakingDenom, 1e5), // gas money
|
sdk.NewInt64Coin(suite.ZgChain.StakingDenom, 1e5), // gas money
|
||||||
sdk.NewInt64Coin(denom, initialCosmosCoinConversionDenomFunds), // conversion-enabled cosmos coin
|
sdk.NewInt64Coin(denom, initialCosmosCoinConversionDenomFunds), // conversion-enabled cosmos coin
|
||||||
)
|
)
|
||||||
|
|
||||||
user = suite.Kava.NewFundedAccount(accountName, initialFunds)
|
user = suite.ZgChain.NewFundedAccount(accountName, initialFunds)
|
||||||
|
|
||||||
return denom, initialFunds, user
|
return denom, initialFunds, user
|
||||||
}
|
}
|
||||||
@ -63,20 +63,20 @@ func (suite *IntegrationTestSuite) setupAccountWithCosmosCoinERC20Balance(
|
|||||||
user.EvmAddress.Hex(),
|
user.EvmAddress.Hex(),
|
||||||
convertAmount,
|
convertAmount,
|
||||||
)
|
)
|
||||||
tx := util.KavaMsgRequest{
|
tx := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{&msg},
|
Msgs: []sdk.Msg{&msg},
|
||||||
GasLimit: 4e5,
|
GasLimit: 4e5,
|
||||||
FeeAmount: sdk.NewCoins(ukava(400)),
|
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(400))),
|
||||||
Data: "converting sdk coin to erc20",
|
Data: "converting sdk coin to erc20",
|
||||||
}
|
}
|
||||||
res := user.SignAndBroadcastKavaTx(tx)
|
res := user.SignAndBroadcastZgChainTx(tx)
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// adjust sdk balance
|
// adjust sdk balance
|
||||||
sdkBalance = sdkBalance.Sub(convertAmount)
|
sdkBalance = sdkBalance.Sub(convertAmount)
|
||||||
|
|
||||||
// query for the deployed contract
|
// query for the deployed contract
|
||||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||||
)
|
)
|
||||||
@ -92,7 +92,7 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
|||||||
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter")
|
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter")
|
||||||
|
|
||||||
convertAmount := int64(5e3)
|
convertAmount := int64(5e3)
|
||||||
initialModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
initialModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
// CONVERT COSMOS COIN -> ERC20
|
// CONVERT COSMOS COIN -> ERC20
|
||||||
@ -102,17 +102,17 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
|||||||
user.EvmAddress.Hex(),
|
user.EvmAddress.Hex(),
|
||||||
sdk.NewInt64Coin(denom, convertAmount),
|
sdk.NewInt64Coin(denom, convertAmount),
|
||||||
)
|
)
|
||||||
tx := util.KavaMsgRequest{
|
tx := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{&convertToErc20Msg},
|
Msgs: []sdk.Msg{&convertToErc20Msg},
|
||||||
GasLimit: 2e6,
|
GasLimit: 2e6,
|
||||||
FeeAmount: sdk.NewCoins(ukava(2000)),
|
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(2000))),
|
||||||
Data: "converting sdk coin to erc20",
|
Data: "converting sdk coin to erc20",
|
||||||
}
|
}
|
||||||
res := user.SignAndBroadcastKavaTx(tx)
|
res := user.SignAndBroadcastZgChainTx(tx)
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// query for the deployed contract
|
// query for the deployed contract
|
||||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||||
)
|
)
|
||||||
@ -122,17 +122,17 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
|||||||
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
||||||
|
|
||||||
// check erc20 balance
|
// check erc20 balance
|
||||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||||
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
||||||
|
|
||||||
// check cosmos coin is deducted from account
|
// check cosmos coin is deducted from account
|
||||||
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
||||||
balance := suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
balance := suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||||
suite.Equal(expectedFunds, balance)
|
suite.Equal(expectedFunds, balance)
|
||||||
|
|
||||||
// check that module account has sdk coins
|
// check that module account has sdk coins
|
||||||
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
||||||
actualModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
actualModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
@ -144,26 +144,26 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoinsToFromERC20() {
|
|||||||
sdk.NewInt64Coin(denom, convertAmount),
|
sdk.NewInt64Coin(denom, convertAmount),
|
||||||
)
|
)
|
||||||
|
|
||||||
tx = util.KavaMsgRequest{
|
tx = util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{&convertFromErc20Msg},
|
Msgs: []sdk.Msg{&convertFromErc20Msg},
|
||||||
GasLimit: 2e5,
|
GasLimit: 2e5,
|
||||||
FeeAmount: sdk.NewCoins(ukava(200)),
|
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||||
Data: "converting erc20 to cosmos coin",
|
Data: "converting erc20 to cosmos coin",
|
||||||
}
|
}
|
||||||
res = user.SignAndBroadcastKavaTx(tx)
|
res = user.SignAndBroadcastZgChainTx(tx)
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// check erc20 balance
|
// check erc20 balance
|
||||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
||||||
|
|
||||||
// check cosmos coin is added back to account
|
// check cosmos coin is added back to account
|
||||||
expectedFunds = initialFunds.AmountOf(denom)
|
expectedFunds = initialFunds.AmountOf(denom)
|
||||||
balance = suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
balance = suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||||
suite.Equal(expectedFunds, balance)
|
suite.Equal(expectedFunds, balance)
|
||||||
|
|
||||||
// check that module account has sdk coins deducted
|
// check that module account has sdk coins deducted
|
||||||
actualModuleBalance = suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
actualModuleBalance = suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
suite.Equal(initialModuleBalance, actualModuleBalance)
|
suite.Equal(initialModuleBalance, actualModuleBalance)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
|||||||
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter-eip712")
|
denom, initialFunds, user := setupConvertToCoinTest(suite, "cosmo-coin-converter-eip712")
|
||||||
|
|
||||||
convertAmount := int64(5e3)
|
convertAmount := int64(5e3)
|
||||||
initialModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
initialModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
// CONVERT COSMOS COIN -> ERC20
|
// CONVERT COSMOS COIN -> ERC20
|
||||||
@ -184,28 +184,28 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
|||||||
)
|
)
|
||||||
tx := suite.NewEip712TxBuilder(
|
tx := suite.NewEip712TxBuilder(
|
||||||
user,
|
user,
|
||||||
suite.Kava,
|
suite.ZgChain,
|
||||||
2e6,
|
2e6,
|
||||||
sdk.NewCoins(ukava(1e4)),
|
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||||
[]sdk.Msg{&convertToErc20Msg},
|
[]sdk.Msg{&convertToErc20Msg},
|
||||||
"this is a memo",
|
"this is a memo",
|
||||||
).GetTx()
|
).GetTx()
|
||||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// submit the eip712 message to the chain.
|
// submit the eip712 message to the chain.
|
||||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||||
TxBytes: txBytes,
|
TxBytes: txBytes,
|
||||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||||
|
|
||||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 12*time.Second)
|
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 12*time.Second)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
// query for the deployed contract
|
// query for the deployed contract
|
||||||
deployedContracts, err := suite.Kava.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
deployedContracts, err := suite.ZgChain.Grpc.Query.Evmutil.DeployedCosmosCoinContracts(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
&evmutiltypes.QueryDeployedCosmosCoinContractsRequest{CosmosDenoms: []string{denom}},
|
||||||
)
|
)
|
||||||
@ -215,17 +215,17 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
|||||||
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
contractAddress := deployedContracts.DeployedCosmosCoinContracts[0].Address
|
||||||
|
|
||||||
// check erc20 balance
|
// check erc20 balance
|
||||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||||
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
suite.BigIntsEqual(big.NewInt(convertAmount), erc20Balance, "unexpected erc20 balance post-convert")
|
||||||
|
|
||||||
// check cosmos coin is deducted from account
|
// check cosmos coin is deducted from account
|
||||||
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
expectedFunds := initialFunds.AmountOf(denom).SubRaw(convertAmount)
|
||||||
balance := suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
balance := suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||||
suite.Equal(expectedFunds, balance)
|
suite.Equal(expectedFunds, balance)
|
||||||
|
|
||||||
// check that module account has sdk coins
|
// check that module account has sdk coins
|
||||||
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
expectedModuleBalance := initialModuleBalance.AddRaw(convertAmount)
|
||||||
actualModuleBalance := suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
actualModuleBalance := suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
suite.Equal(expectedModuleBalance, actualModuleBalance)
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
@ -238,37 +238,37 @@ func (suite *IntegrationTestSuite) TestEIP712ConvertCosmosCoinsToFromERC20() {
|
|||||||
)
|
)
|
||||||
tx = suite.NewEip712TxBuilder(
|
tx = suite.NewEip712TxBuilder(
|
||||||
user,
|
user,
|
||||||
suite.Kava,
|
suite.ZgChain,
|
||||||
2e5,
|
2e5,
|
||||||
sdk.NewCoins(ukava(200)),
|
sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||||
[]sdk.Msg{&convertFromErc20Msg},
|
[]sdk.Msg{&convertFromErc20Msg},
|
||||||
"",
|
"",
|
||||||
).GetTx()
|
).GetTx()
|
||||||
txBytes, err = suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
txBytes, err = suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// submit the eip712 message to the chain
|
// submit the eip712 message to the chain
|
||||||
res, err = suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
res, err = suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||||
TxBytes: txBytes,
|
TxBytes: txBytes,
|
||||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||||
|
|
||||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// check erc20 balance
|
// check erc20 balance
|
||||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, user.EvmAddress)
|
||||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected all erc20 to be converted back")
|
||||||
|
|
||||||
// check cosmos coin is added back to account
|
// check cosmos coin is added back to account
|
||||||
expectedFunds = initialFunds.AmountOf(denom)
|
expectedFunds = initialFunds.AmountOf(denom)
|
||||||
balance = suite.Kava.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
balance = suite.ZgChain.QuerySdkForBalances(user.SdkAddress).AmountOf(denom)
|
||||||
suite.Equal(expectedFunds, balance)
|
suite.Equal(expectedFunds, balance)
|
||||||
|
|
||||||
// check that module account has sdk coins deducted
|
// check that module account has sdk coins deducted
|
||||||
actualModuleBalance = suite.Kava.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
actualModuleBalance = suite.ZgChain.GetModuleBalances(evmutiltypes.ModuleName).AmountOf(denom)
|
||||||
suite.Equal(initialModuleBalance, actualModuleBalance)
|
suite.Equal(initialModuleBalance, actualModuleBalance)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,8 +334,8 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
|||||||
"cosmo-coin-converter-complex-alice", initialAliceAmount,
|
"cosmo-coin-converter-complex-alice", initialAliceAmount,
|
||||||
)
|
)
|
||||||
|
|
||||||
gasMoney := sdk.NewCoins(ukava(1e5))
|
gasMoney := sdk.NewCoins(a0gi(big.NewInt(1e5)))
|
||||||
bob := suite.Kava.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
bob := suite.ZgChain.NewFundedAccount("cosmo-coin-converter-complex-bob", gasMoney)
|
||||||
amount := big.NewInt(1e3) // test assumes this is half of alice's balance.
|
amount := big.NewInt(1e3) // test assumes this is half of alice's balance.
|
||||||
|
|
||||||
// bob can't move alice's funds
|
// bob can't move alice's funds
|
||||||
@ -400,10 +400,10 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
|||||||
suite.Require().NoError(res.Err)
|
suite.Require().NoError(res.Err)
|
||||||
|
|
||||||
// alice should have amount deducted
|
// alice should have amount deducted
|
||||||
erc20Balance := suite.Kava.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
erc20Balance := suite.ZgChain.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||||
suite.BigIntsEqual(big.NewInt(initialAliceAmount-amount.Int64()), erc20Balance, "alice has unexpected erc20 balance")
|
suite.BigIntsEqual(big.NewInt(initialAliceAmount-amount.Int64()), erc20Balance, "alice has unexpected erc20 balance")
|
||||||
// bob should have amount added
|
// bob should have amount added
|
||||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||||
suite.BigIntsEqual(amount, erc20Balance, "bob has unexpected erc20 balance")
|
suite.BigIntsEqual(amount, erc20Balance, "bob has unexpected erc20 balance")
|
||||||
|
|
||||||
// convert bob's new funds back to an sdk.Coin
|
// convert bob's new funds back to an sdk.Coin
|
||||||
@ -412,24 +412,24 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
|||||||
bob.SdkAddress.String(),
|
bob.SdkAddress.String(),
|
||||||
sdk.NewInt64Coin(denom, amount.Int64()),
|
sdk.NewInt64Coin(denom, amount.Int64()),
|
||||||
)
|
)
|
||||||
convertTx := util.KavaMsgRequest{
|
convertTx := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{&convertMsg},
|
Msgs: []sdk.Msg{&convertMsg},
|
||||||
GasLimit: 2e5,
|
GasLimit: 2e5,
|
||||||
FeeAmount: sdk.NewCoins(ukava(200)),
|
FeeAmount: sdk.NewCoins(a0gi(big.NewInt(200))),
|
||||||
Data: "bob converts his new erc20 to an sdk.Coin",
|
Data: "bob converts his new erc20 to an sdk.Coin",
|
||||||
}
|
}
|
||||||
convertRes := bob.SignAndBroadcastKavaTx(convertTx)
|
convertRes := bob.SignAndBroadcastZgChainTx(convertTx)
|
||||||
suite.NoError(convertRes.Err)
|
suite.NoError(convertRes.Err)
|
||||||
|
|
||||||
// bob should have no more erc20 balance
|
// bob should have no more erc20 balance
|
||||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, bob.EvmAddress)
|
||||||
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected no erc20 balance for bob")
|
suite.BigIntsEqual(big.NewInt(0), erc20Balance, "expected no erc20 balance for bob")
|
||||||
// bob should have sdk balance
|
// bob should have sdk balance
|
||||||
balance := suite.Kava.QuerySdkForBalances(bob.SdkAddress).AmountOf(denom)
|
balance := suite.ZgChain.QuerySdkForBalances(bob.SdkAddress).AmountOf(denom)
|
||||||
suite.Equal(sdk.NewIntFromBigInt(amount), balance)
|
suite.Equal(sdk.NewIntFromBigInt(amount), balance)
|
||||||
|
|
||||||
// alice should have the remaining balance
|
// alice should have the remaining balance
|
||||||
erc20Balance = suite.Kava.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
erc20Balance = suite.ZgChain.GetErc20Balance(contractAddress.Address, alice.EvmAddress)
|
||||||
suite.BigIntsEqual(amount, erc20Balance, "expected alice to have half initial funds remaining")
|
suite.BigIntsEqual(amount, erc20Balance, "expected alice to have half initial funds remaining")
|
||||||
|
|
||||||
// convert alice's remaining balance back to sdk coins
|
// convert alice's remaining balance back to sdk coins
|
||||||
@ -438,6 +438,6 @@ func (suite *IntegrationTestSuite) TestConvertCosmosCoins_ERC20Magic() {
|
|||||||
alice.SdkAddress.String(),
|
alice.SdkAddress.String(),
|
||||||
sdk.NewInt64Coin(denom, amount.Int64()),
|
sdk.NewInt64Coin(denom, amount.Int64()),
|
||||||
)
|
)
|
||||||
convertRes = alice.SignAndBroadcastKavaTx(convertTx)
|
convertRes = alice.SignAndBroadcastZgChainTx(convertTx)
|
||||||
suite.NoError(convertRes.Err)
|
suite.NoError(convertRes.Err)
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ import (
|
|||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
|
|
||||||
// cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
// cdptypes "github.com/0glabs/0g-chain/x/cdp/types"
|
||||||
// evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/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.
|
// this test manipulates state of the Greeter contract which means other tests shouldn't use it.
|
||||||
|
|
||||||
// setup funded account to interact with contract
|
// setup funded account to interact with contract
|
||||||
user := suite.Kava.NewFundedAccount("greeter-contract-user", sdk.NewCoins(ukava(1e6)))
|
user := suite.ZgChain.NewFundedAccount("greeter-contract-user", sdk.NewCoins(a0gi(big.NewInt(1e6))))
|
||||||
|
|
||||||
greeterAddr := suite.Kava.ContractAddrs["greeter"]
|
greeterAddr := suite.ZgChain.ContractAddrs["greeter"]
|
||||||
contract, err := greeter.NewGreeter(greeterAddr, suite.Kava.EvmClient)
|
contract, err := greeter.NewGreeter(greeterAddr, suite.ZgChain.EvmClient)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
beforeGreeting, err := contract.Greet(nil)
|
beforeGreeting, err := contract.Greet(nil)
|
||||||
@ -35,7 +37,7 @@ func (suite *IntegrationTestSuite) TestEthCallToGreeterContract() {
|
|||||||
tx, err := contract.SetGreeting(user.EvmAuth, updatedGreeting)
|
tx, err := contract.SetGreeting(user.EvmAuth, updatedGreeting)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
_, err = util.WaitForEvmTxReceipt(suite.Kava.EvmClient, tx.Hash(), 10*time.Second)
|
_, err = util.WaitForEvmTxReceipt(suite.ZgChain.EvmClient, tx.Hash(), 10*time.Second)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
afterGreeting, err := contract.Greet(nil)
|
afterGreeting, err := contract.Greet(nil)
|
||||||
@ -50,14 +52,14 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
|||||||
amount := big.NewInt(1)
|
amount := big.NewInt(1)
|
||||||
|
|
||||||
// make unauthenticated eth_call query to check balance
|
// make unauthenticated eth_call query to check balance
|
||||||
beforeBalance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
beforeBalance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||||
|
|
||||||
// make authenticate eth_call to transfer tokens
|
// make authenticate eth_call to transfer tokens
|
||||||
res := suite.FundKavaErc20Balance(randoReceiver, amount)
|
res := suite.FundZgChainErc20Balance(randoReceiver, amount)
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// make another unauthenticated eth_call query to check new balance
|
// make another unauthenticated eth_call query to check new balance
|
||||||
afterBalance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
afterBalance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, randoReceiver)
|
||||||
|
|
||||||
suite.BigIntsEqual(big.NewInt(0), beforeBalance, "expected before balance to be zero")
|
suite.BigIntsEqual(big.NewInt(0), beforeBalance, "expected before balance to be zero")
|
||||||
suite.BigIntsEqual(amount, afterBalance, "unexpected post-transfer balance")
|
suite.BigIntsEqual(amount, afterBalance, "unexpected post-transfer balance")
|
||||||
@ -65,42 +67,42 @@ func (suite *IntegrationTestSuite) TestEthCallToErc20() {
|
|||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
||||||
// create new funded account
|
// create new funded account
|
||||||
sender := suite.Kava.NewFundedAccount("eip712-msgSend", sdk.NewCoins(ukava(2e4)))
|
sender := suite.ZgChain.NewFundedAccount("eip712-msgSend", sdk.NewCoins(a0gi(big.NewInt(2e4))))
|
||||||
receiver := app.RandomAddress()
|
receiver := app.RandomAddress()
|
||||||
|
|
||||||
// setup message for sending some kava to random receiver
|
// setup message for sending some a0gi to random receiver
|
||||||
msgs := []sdk.Msg{
|
msgs := []sdk.Msg{
|
||||||
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(ukava(1e3))),
|
banktypes.NewMsgSend(sender.SdkAddress, receiver, sdk.NewCoins(a0gi(big.NewInt(1e3)))),
|
||||||
}
|
}
|
||||||
|
|
||||||
// create tx
|
// create tx
|
||||||
tx := suite.NewEip712TxBuilder(
|
tx := suite.NewEip712TxBuilder(
|
||||||
sender,
|
sender,
|
||||||
suite.Kava,
|
suite.ZgChain,
|
||||||
1e6,
|
1e6,
|
||||||
sdk.NewCoins(ukava(1e4)),
|
sdk.NewCoins(a0gi(big.NewInt(1e4))),
|
||||||
msgs,
|
msgs,
|
||||||
"this is a memo",
|
"this is a memo",
|
||||||
).GetTx()
|
).GetTx()
|
||||||
|
|
||||||
txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// broadcast tx
|
// broadcast tx
|
||||||
res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||||
TxBytes: txBytes,
|
TxBytes: txBytes,
|
||||||
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||||
|
|
||||||
_, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
_, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// check that the message was processed & the kava is transferred.
|
// check that the message was processed & the a0gi is transferred.
|
||||||
balRes, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
balRes, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||||
Address: receiver.String(),
|
Address: receiver.String(),
|
||||||
Denom: "ukava",
|
Denom: chaincfg.DisplayDenom,
|
||||||
})
|
})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(sdk.NewInt(1e3), balRes.Balance.Amount)
|
suite.Equal(sdk.NewInt(1e3), balRes.Balance.Amount)
|
||||||
@ -115,9 +117,9 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
|||||||
// sdkDenom := suite.DeployedErc20.CosmosDenom
|
// sdkDenom := suite.DeployedErc20.CosmosDenom
|
||||||
|
|
||||||
// // create new funded account
|
// // 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
|
// // give them erc20 balance to deposit
|
||||||
// fundRes := suite.FundKavaErc20Balance(depositor.EvmAddress, amount.BigInt())
|
// fundRes := suite.FundZgChainErc20Balance(depositor.EvmAddress, amount.BigInt())
|
||||||
// suite.NoError(fundRes.Err)
|
// suite.NoError(fundRes.Err)
|
||||||
|
|
||||||
// // setup messages for convert to coin & deposit into earn
|
// // setup messages for convert to coin & deposit into earn
|
||||||
@ -143,33 +145,33 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
|||||||
// // create tx
|
// // create tx
|
||||||
// tx := suite.NewEip712TxBuilder(
|
// tx := suite.NewEip712TxBuilder(
|
||||||
// depositor,
|
// depositor,
|
||||||
// suite.Kava,
|
// suite.ZgChain,
|
||||||
// 1e6,
|
// 1e6,
|
||||||
// sdk.NewCoins(ukava(1e4)),
|
// sdk.NewCoins(a0gi(big.NewInt(1e4)),
|
||||||
// msgs,
|
// msgs,
|
||||||
// "doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit",
|
// "doing the USDT Earn workflow! erc20 -> sdk.Coin -> USDX hard deposit",
|
||||||
// ).GetTx()
|
// ).GetTx()
|
||||||
|
|
||||||
// txBytes, err := suite.Kava.EncodingConfig.TxConfig.TxEncoder()(tx)
|
// txBytes, err := suite.ZgChain.EncodingConfig.TxConfig.TxEncoder()(tx)
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
|
|
||||||
// // broadcast tx
|
// // broadcast tx
|
||||||
// res, err := suite.Kava.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
// res, err := suite.ZgChain.Grpc.Query.Tx.BroadcastTx(context.Background(), &txtypes.BroadcastTxRequest{
|
||||||
// TxBytes: txBytes,
|
// TxBytes: txBytes,
|
||||||
// Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
// Mode: txtypes.BroadcastMode_BROADCAST_MODE_SYNC,
|
||||||
// })
|
// })
|
||||||
// suite.NoError(err)
|
// suite.NoError(err)
|
||||||
// suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
// suite.Equal(sdkerrors.SuccessABCICode, res.TxResponse.Code)
|
||||||
|
|
||||||
// _, err = util.WaitForSdkTxCommit(suite.Kava.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
// _, err = util.WaitForSdkTxCommit(suite.ZgChain.Grpc.Query.Tx, res.TxResponse.TxHash, 6*time.Second)
|
||||||
// suite.Require().NoError(err)
|
// suite.Require().NoError(err)
|
||||||
|
|
||||||
// // check that depositor no longer has erc20 balance
|
// // 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")
|
// suite.BigIntsEqual(big.NewInt(0), balance, "expected no erc20 balance")
|
||||||
|
|
||||||
// // check that account has cdp
|
// // 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,
|
// // CollateralType: suite.DeployedErc20.CdpCollateralType,
|
||||||
// // Owner: depositor.SdkAddress.String(),
|
// // Owner: depositor.SdkAddress.String(),
|
||||||
// // })
|
// // })
|
||||||
@ -188,15 +190,15 @@ func (suite *IntegrationTestSuite) TestEip712BasicMessageAuthorization() {
|
|||||||
// depositor.EvmAddress.Hex(),
|
// depositor.EvmAddress.Hex(),
|
||||||
// sdk.NewCoin(sdkDenom, amount),
|
// sdk.NewCoin(sdkDenom, amount),
|
||||||
// )
|
// )
|
||||||
// withdrawAndConvertBack := util.KavaMsgRequest{
|
// withdrawAndConvertBack := util.ZgChainMsgRequest{
|
||||||
// Msgs: []sdk.Msg{&withdraw, &convertBack},
|
// Msgs: []sdk.Msg{&withdraw, &convertBack},
|
||||||
// GasLimit: 1e6,
|
// GasLimit: 1e6,
|
||||||
// FeeAmount: sdk.NewCoins(ukava(1000)),
|
// FeeAmount: sdk.NewCoins(a0gi(big.NewInt(1000)),
|
||||||
// Data: "withdrawing from mint & converting back to erc20",
|
// Data: "withdrawing from mint & converting back to erc20",
|
||||||
// }
|
// }
|
||||||
// lastRes := depositor.SignAndBroadcastKavaTx(withdrawAndConvertBack)
|
// lastRes := depositor.SignAndBroadcastZgChainTx(withdrawAndConvertBack)
|
||||||
// suite.NoError(lastRes.Err)
|
// 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")
|
// suite.BigIntsEqual(amount.BigInt(), balance, "expected returned erc20 balance")
|
||||||
// }
|
// }
|
||||||
|
@ -2,6 +2,7 @@ package e2e_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
@ -11,13 +12,13 @@ import (
|
|||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
|
func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
// setup kava account
|
// setup 0g account
|
||||||
funds := ukava(1e5) // .1 KAVA
|
funds := a0gi(big.NewInt(1e5)) // .1 A0GI
|
||||||
kavaAcc := suite.Kava.NewFundedAccount("balance-test", sdk.NewCoins(funds))
|
zgChainAcc := suite.ZgChain.NewFundedAccount("balance-test", sdk.NewCoins(funds))
|
||||||
|
|
||||||
// ACT
|
// ACT
|
||||||
rsp, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
rsp, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), &banktypes.QueryBalanceRequest{
|
||||||
Address: kavaAcc.SdkAddress.String(),
|
Address: zgChainAcc.SdkAddress.String(),
|
||||||
Denom: funds.Denom,
|
Denom: funds.Denom,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -26,9 +27,9 @@ func (suite *IntegrationTestSuite) TestGrpcClientQueryCosmosModule_Balance() {
|
|||||||
suite.Require().Equal(funds.Amount, rsp.Balance.Amount)
|
suite.Require().Equal(funds.Amount, rsp.Balance.Amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestGrpcClientQueryKavaModule_EvmParams() {
|
func (suite *IntegrationTestSuite) TestGrpcClientQueryZgChainModule_EvmParams() {
|
||||||
// ACT
|
// ACT
|
||||||
rsp, err := suite.Kava.Grpc.Query.Evmutil.Params(
|
rsp, err := suite.ZgChain.Grpc.Query.Evmutil.Params(
|
||||||
context.Background(), &evmutiltypes.QueryParamsRequest{},
|
context.Background(), &evmutiltypes.QueryParamsRequest{},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
package e2e_test
|
package e2e_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/big"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestGrpcClientUtil_Account() {
|
func (suite *IntegrationTestSuite) TestGrpcClientUtil_Account() {
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
// setup kava account
|
// setup 0g account
|
||||||
kavaAcc := suite.Kava.NewFundedAccount("account-test", sdk.NewCoins(ukava(1e5)))
|
zgChainAcc := suite.ZgChain.NewFundedAccount("account-test", sdk.NewCoins(a0gi(big.NewInt(1e5))))
|
||||||
|
|
||||||
// ACT
|
// ACT
|
||||||
rsp, err := suite.Kava.Grpc.BaseAccount(kavaAcc.SdkAddress.String())
|
rsp, err := suite.ZgChain.Grpc.BaseAccount(zgChainAcc.SdkAddress.String())
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
suite.Require().NoError(err)
|
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.Greater(rsp.AccountNumber, uint64(1))
|
||||||
suite.Equal(uint64(0), rsp.Sequence)
|
suite.Equal(uint64(0), rsp.Sequence)
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
ethtypes "github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,14 +21,14 @@ func (suite *IntegrationTestSuite) TestEthGasPriceReturnsMinFee() {
|
|||||||
suite.SkipIfKvtoolDisabled()
|
suite.SkipIfKvtoolDisabled()
|
||||||
|
|
||||||
// read expected min fee from app.toml
|
// read expected min fee from app.toml
|
||||||
minGasPrices, err := getMinFeeFromAppToml(util.KavaHomePath())
|
minGasPrices, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||||
suite.NoError(err, "failed to read min fee from app.toml")
|
suite.NoError(err, "failed to read min fee from app.toml")
|
||||||
|
|
||||||
// evm uses akava, get akava min fee
|
// evm uses neuron, get neuron min fee
|
||||||
evmMinGas := minGasPrices.AmountOf("akava").TruncateInt().BigInt()
|
evmMinGas := minGasPrices.AmountOf(chaincfg.BaseDenom).TruncateInt().BigInt()
|
||||||
|
|
||||||
// returns eth_gasPrice, units in kava
|
// returns eth_gasPrice, units in a0gi
|
||||||
gasPrice, err := suite.Kava.EvmClient.SuggestGasPrice(context.Background())
|
gasPrice, err := suite.ZgChain.EvmClient.SuggestGasPrice(context.Background())
|
||||||
suite.NoError(err, "failed to get gas price")
|
suite.NoError(err, "failed to get gas price")
|
||||||
|
|
||||||
suite.Equal(evmMinGas, gasPrice, "gas price should be equal to min fee")
|
suite.Equal(evmMinGas, gasPrice, "gas price should be equal to min fee")
|
||||||
@ -37,13 +38,13 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
|||||||
suite.SkipIfKvtoolDisabled()
|
suite.SkipIfKvtoolDisabled()
|
||||||
|
|
||||||
// setup sender & receiver
|
// setup sender & receiver
|
||||||
sender := suite.Kava.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(ukava(1e3)))
|
sender := suite.ZgChain.NewFundedAccount("evm-min-fee-test-sender", sdk.NewCoins(a0gi(big.NewInt(1e3))))
|
||||||
randoReceiver := util.SdkToEvmAddress(app.RandomAddress())
|
randoReceiver := util.SdkToEvmAddress(app.RandomAddress())
|
||||||
|
|
||||||
// get min gas price for evm (from app.toml)
|
// get min gas price for evm (from app.toml)
|
||||||
minFees, err := getMinFeeFromAppToml(util.KavaHomePath())
|
minFees, err := getMinFeeFromAppToml(util.ZgChainHomePath())
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
minGasPrice := minFees.AmountOf("akava").TruncateInt()
|
minGasPrice := minFees.AmountOf(chaincfg.BaseDenom).TruncateInt()
|
||||||
|
|
||||||
// attempt tx with less than min gas price (min fee - 1)
|
// attempt tx with less than min gas price (min fee - 1)
|
||||||
tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt()
|
tooLowGasPrice := minGasPrice.Sub(sdk.OneInt()).BigInt()
|
||||||
@ -58,12 +59,12 @@ func (suite *IntegrationTestSuite) TestEvmRespectsMinFee() {
|
|||||||
suite.ErrorContains(res.Err, "insufficient fee")
|
suite.ErrorContains(res.Err, "insufficient fee")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMinFeeFromAppToml(kavaHome string) (sdk.DecCoins, error) {
|
func getMinFeeFromAppToml(zgChainHome string) (sdk.DecCoins, error) {
|
||||||
// read the expected min gas price from app.toml
|
// read the expected min gas price from app.toml
|
||||||
parsed := struct {
|
parsed := struct {
|
||||||
MinGasPrices string `toml:"minimum-gas-prices"`
|
MinGasPrices string `toml:"minimum-gas-prices"`
|
||||||
}{}
|
}{}
|
||||||
appToml, err := os.ReadFile(filepath.Join(kavaHome, "config", "app.toml"))
|
appToml, err := os.ReadFile(filepath.Join(zgChainHome, "config", "app.toml"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,16 +19,17 @@ import (
|
|||||||
emtypes "github.com/evmos/ethermint/types"
|
emtypes "github.com/evmos/ethermint/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/tests/e2e/testutil"
|
"github.com/0glabs/0g-chain/tests/e2e/testutil"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
minEvmGasPrice = big.NewInt(1e10) // akava
|
minEvmGasPrice = big.NewInt(1e10) // neuron
|
||||||
)
|
)
|
||||||
|
|
||||||
func ukava(amt int64) sdk.Coin {
|
func a0gi(amt *big.Int) sdk.Coin {
|
||||||
return sdk.NewCoin("ukava", sdkmath.NewInt(amt))
|
return sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewIntFromBigInt(amt))
|
||||||
}
|
}
|
||||||
|
|
||||||
type IntegrationTestSuite struct {
|
type IntegrationTestSuite struct {
|
||||||
@ -39,63 +40,63 @@ func TestIntegrationTestSuite(t *testing.T) {
|
|||||||
suite.Run(t, new(IntegrationTestSuite))
|
suite.Run(t, new(IntegrationTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
// example test that queries kava via SDK and EVM
|
// example test that queries 0gchain via SDK and EVM
|
||||||
func (suite *IntegrationTestSuite) TestChainID() {
|
func (suite *IntegrationTestSuite) TestChainID() {
|
||||||
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.Kava.ChainID)
|
expectedEvmNetworkId, err := emtypes.ParseChainID(suite.ZgChain.ChainID)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
// EVM query
|
// EVM query
|
||||||
evmNetworkId, err := suite.Kava.EvmClient.NetworkID(context.Background())
|
evmNetworkId, err := suite.ZgChain.EvmClient.NetworkID(context.Background())
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(expectedEvmNetworkId, evmNetworkId)
|
suite.Equal(expectedEvmNetworkId, evmNetworkId)
|
||||||
|
|
||||||
// SDK query
|
// SDK query
|
||||||
nodeInfo, err := suite.Kava.Grpc.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
nodeInfo, err := suite.ZgChain.Grpc.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(suite.Kava.ChainID, nodeInfo.DefaultNodeInfo.Network)
|
suite.Equal(suite.ZgChain.ChainID, nodeInfo.DefaultNodeInfo.Network)
|
||||||
}
|
}
|
||||||
|
|
||||||
// example test that funds a new account & queries its balance
|
// example test that funds a new account & queries its balance
|
||||||
func (suite *IntegrationTestSuite) TestFundedAccount() {
|
func (suite *IntegrationTestSuite) TestFundedAccount() {
|
||||||
funds := ukava(1e3)
|
funds := a0gi(big.NewInt(1e3))
|
||||||
acc := suite.Kava.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
acc := suite.ZgChain.NewFundedAccount("example-acc", sdk.NewCoins(funds))
|
||||||
|
|
||||||
// check that the sdk & evm signers are for the same account
|
// check that the sdk & evm signers are for the same account
|
||||||
suite.Equal(acc.SdkAddress.String(), util.EvmToSdkAddress(acc.EvmAddress).String())
|
suite.Equal(acc.SdkAddress.String(), util.EvmToSdkAddress(acc.EvmAddress).String())
|
||||||
suite.Equal(acc.EvmAddress.Hex(), util.SdkToEvmAddress(acc.SdkAddress).Hex())
|
suite.Equal(acc.EvmAddress.Hex(), util.SdkToEvmAddress(acc.SdkAddress).Hex())
|
||||||
|
|
||||||
// check balance via SDK query
|
// check balance via SDK query
|
||||||
res, err := suite.Kava.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
res, err := suite.ZgChain.Grpc.Query.Bank.Balance(context.Background(), banktypes.NewQueryBalanceRequest(
|
||||||
acc.SdkAddress, "ukava",
|
acc.SdkAddress, chaincfg.DisplayDenom,
|
||||||
))
|
))
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(funds, *res.Balance)
|
suite.Equal(funds, *res.Balance)
|
||||||
|
|
||||||
// check balance via EVM query
|
// check balance via EVM query
|
||||||
akavaBal, err := suite.Kava.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
|
neuronBal, err := suite.ZgChain.EvmClient.BalanceAt(context.Background(), acc.EvmAddress, nil)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), akavaBal)
|
suite.Equal(funds.Amount.MulRaw(1e12).BigInt(), neuronBal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// example test that signs & broadcasts an EVM tx
|
// example test that signs & broadcasts an EVM tx
|
||||||
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
||||||
// fund an account that can perform the transfer
|
// fund an account that can perform the transfer
|
||||||
initialFunds := ukava(1e6) // 1 KAVA
|
initialFunds := a0gi(big.NewInt(1e6)) // 1 A0GI
|
||||||
acc := suite.Kava.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
|
acc := suite.ZgChain.NewFundedAccount("evm-test-transfer", sdk.NewCoins(initialFunds))
|
||||||
|
|
||||||
// get a rando account to send kava to
|
// get a rando account to send 0gchain to
|
||||||
randomAddr := app.RandomAddress()
|
randomAddr := app.RandomAddress()
|
||||||
to := util.SdkToEvmAddress(randomAddr)
|
to := util.SdkToEvmAddress(randomAddr)
|
||||||
|
|
||||||
// example fetching of nonce (account sequence)
|
// example fetching of nonce (account sequence)
|
||||||
nonce, err := suite.Kava.EvmClient.PendingNonceAt(context.Background(), acc.EvmAddress)
|
nonce, err := suite.ZgChain.EvmClient.PendingNonceAt(context.Background(), acc.EvmAddress)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs
|
suite.Equal(uint64(0), nonce) // sanity check. the account should have no prior txs
|
||||||
|
|
||||||
// transfer kava over EVM
|
// transfer a0gi over EVM
|
||||||
kavaToTransfer := big.NewInt(1e17) // .1 KAVA; akava has 18 decimals.
|
a0giToTransfer := big.NewInt(1e17) // .1 A0GI; neuron has 18 decimals.
|
||||||
req := util.EvmTxRequest{
|
req := util.EvmTxRequest{
|
||||||
Tx: ethtypes.NewTransaction(nonce, to, kavaToTransfer, 1e5, minEvmGasPrice, nil),
|
Tx: ethtypes.NewTransaction(nonce, to, a0giToTransfer, 1e5, minEvmGasPrice, nil),
|
||||||
Data: "any ol' data to track this through the system",
|
Data: "any ol' data to track this through the system",
|
||||||
}
|
}
|
||||||
res := acc.SignAndBroadcastEvmTx(req)
|
res := acc.SignAndBroadcastEvmTx(req)
|
||||||
@ -103,36 +104,36 @@ func (suite *IntegrationTestSuite) TestTransferOverEVM() {
|
|||||||
suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status)
|
suite.Equal(ethtypes.ReceiptStatusSuccessful, res.Receipt.Status)
|
||||||
|
|
||||||
// evm txs refund unused gas. so to know the expected balance we need to know how much gas was used.
|
// evm txs refund unused gas. so to know the expected balance we need to know how much gas was used.
|
||||||
ukavaUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
|
a0giUsedForGas := sdkmath.NewIntFromBigInt(minEvmGasPrice).
|
||||||
Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)).
|
Mul(sdkmath.NewIntFromUint64(res.Receipt.GasUsed)).
|
||||||
QuoRaw(1e12) // convert akava to ukava
|
QuoRaw(1e12) // convert neuron to a0gi
|
||||||
|
|
||||||
// expect (9 - gas used) KAVA remaining in account.
|
// expect (9 - gas used) A0GI remaining in account.
|
||||||
balance := suite.Kava.QuerySdkForBalances(acc.SdkAddress)
|
balance := suite.ZgChain.QuerySdkForBalances(acc.SdkAddress)
|
||||||
suite.Equal(sdkmath.NewInt(9e5).Sub(ukavaUsedForGas), balance.AmountOf("ukava"))
|
suite.Equal(sdkmath.NewInt(9e5).Sub(a0giUsedForGas), balance.AmountOf(chaincfg.DisplayDenom))
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestIbcTransfer transfers KAVA from the primary kava chain (suite.Kava) to the ibc chain (suite.Ibc).
|
// TestIbcTransfer transfers A0GI from the primary 0g-chain (suite.ZgChain) to the ibc chain (suite.Ibc).
|
||||||
// Note that because the IBC chain also runs kava's binary, this tests both the sending & receiving.
|
// Note that because the IBC chain also runs 0g-chain's binary, this tests both the sending & receiving.
|
||||||
func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
||||||
suite.SkipIfIbcDisabled()
|
suite.SkipIfIbcDisabled()
|
||||||
|
|
||||||
// ARRANGE
|
// ARRANGE
|
||||||
// setup kava account
|
// setup 0g-chain account
|
||||||
funds := ukava(1e5) // .1 KAVA
|
funds := a0gi(big.NewInt(1e5)) // .1 A0GI
|
||||||
kavaAcc := suite.Kava.NewFundedAccount("ibc-transfer-kava-side", sdk.NewCoins(funds))
|
zgChainAcc := suite.ZgChain.NewFundedAccount("ibc-transfer-0g-side", sdk.NewCoins(funds))
|
||||||
// setup ibc account
|
// setup ibc account
|
||||||
ibcAcc := suite.Ibc.NewFundedAccount("ibc-transfer-ibc-side", sdk.NewCoins())
|
ibcAcc := suite.Ibc.NewFundedAccount("ibc-transfer-ibc-side", sdk.NewCoins())
|
||||||
|
|
||||||
gasLimit := int64(2e5)
|
gasLimit := int64(2e5)
|
||||||
fee := ukava(200)
|
fee := a0gi(big.NewInt(200))
|
||||||
|
|
||||||
fundsToSend := ukava(5e4) // .005 KAVA
|
fundsToSend := a0gi(big.NewInt(5e4)) // .005 A0GI
|
||||||
transferMsg := ibctypes.NewMsgTransfer(
|
transferMsg := ibctypes.NewMsgTransfer(
|
||||||
testutil.IbcPort,
|
testutil.IbcPort,
|
||||||
testutil.IbcChannel,
|
testutil.IbcChannel,
|
||||||
fundsToSend,
|
fundsToSend,
|
||||||
kavaAcc.SdkAddress.String(),
|
zgChainAcc.SdkAddress.String(),
|
||||||
ibcAcc.SdkAddress.String(),
|
ibcAcc.SdkAddress.String(),
|
||||||
ibcclienttypes.NewHeight(0, 0), // timeout height disabled when 0
|
ibcclienttypes.NewHeight(0, 0), // timeout height disabled when 0
|
||||||
uint64(time.Now().Add(30*time.Second).UnixNano()),
|
uint64(time.Now().Add(30*time.Second).UnixNano()),
|
||||||
@ -142,22 +143,22 @@ func (suite *IntegrationTestSuite) TestIbcTransfer() {
|
|||||||
expectedSrcBalance := funds.Sub(fundsToSend).Sub(fee)
|
expectedSrcBalance := funds.Sub(fundsToSend).Sub(fee)
|
||||||
|
|
||||||
// ACT
|
// ACT
|
||||||
// IBC transfer from kava -> ibc
|
// IBC transfer from 0g-chain -> ibc
|
||||||
transferTo := util.KavaMsgRequest{
|
transferTo := util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{transferMsg},
|
Msgs: []sdk.Msg{transferMsg},
|
||||||
GasLimit: uint64(gasLimit),
|
GasLimit: uint64(gasLimit),
|
||||||
FeeAmount: sdk.NewCoins(fee),
|
FeeAmount: sdk.NewCoins(fee),
|
||||||
Memo: "sent from Kava!",
|
Memo: "sent from ZgChain!",
|
||||||
}
|
}
|
||||||
res := kavaAcc.SignAndBroadcastKavaTx(transferTo)
|
res := zgChainAcc.SignAndBroadcastZgChainTx(transferTo)
|
||||||
|
|
||||||
// ASSERT
|
// ASSERT
|
||||||
suite.NoError(res.Err)
|
suite.NoError(res.Err)
|
||||||
|
|
||||||
// the balance should be deducted from kava account
|
// the balance should be deducted from 0g-chain account
|
||||||
suite.Eventually(func() bool {
|
suite.Eventually(func() bool {
|
||||||
balance := suite.Kava.QuerySdkForBalances(kavaAcc.SdkAddress)
|
balance := suite.ZgChain.QuerySdkForBalances(zgChainAcc.SdkAddress)
|
||||||
return balance.AmountOf("ukava").Equal(expectedSrcBalance.Amount)
|
return balance.AmountOf(chaincfg.DisplayDenom).Equal(expectedSrcBalance.Amount)
|
||||||
}, 10*time.Second, 1*time.Second)
|
}, 10*time.Second, 1*time.Second)
|
||||||
|
|
||||||
// expect the balance to be transferred to the ibc chain!
|
// expect the balance to be transferred to the ibc chain!
|
||||||
|
@ -13,6 +13,6 @@ func (suite *IntegrationTestSuite) TestUpgradeHandler() {
|
|||||||
suite.True(true)
|
suite.True(true)
|
||||||
|
|
||||||
// Uncomment & use these contexts to compare chain state before & after the upgrade occurs.
|
// Uncomment & use these contexts to compare chain state before & after the upgrade occurs.
|
||||||
// beforeUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
|
// beforeUpgradeCtx := suite.ZgChain.Grpc.CtxAtHeight(suite.UpgradeHeight - 1)
|
||||||
// afterUpgradeCtx := suite.Kava.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
// afterUpgradeCtx := suite.ZgChain.Grpc.CtxAtHeight(suite.UpgradeHeight)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
rpchttpclient "github.com/cometbft/cometbft/rpc/client/http"
|
rpchttpclient "github.com/cometbft/cometbft/rpc/client/http"
|
||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
)
|
)
|
||||||
@ -67,20 +68,20 @@ func (c *Chains) Register(name string, chain *ChainDetails) error {
|
|||||||
// the Chain details are all hardcoded because they are currently fixed by kvtool.
|
// the Chain details are all hardcoded because they are currently fixed by kvtool.
|
||||||
// someday they may be accepted as configurable parameters.
|
// someday they may be accepted as configurable parameters.
|
||||||
var (
|
var (
|
||||||
kvtoolKavaChain = ChainDetails{
|
kvtoolZgChainChain = ChainDetails{
|
||||||
RpcUrl: "http://localhost:26657",
|
RpcUrl: "http://localhost:26657",
|
||||||
GrpcUrl: "http://localhost:9090",
|
GrpcUrl: "http://localhost:9090",
|
||||||
EvmRpcUrl: "http://localhost:8545",
|
EvmRpcUrl: "http://localhost:8545",
|
||||||
|
|
||||||
ChainId: "kavalocalnet_8888-1",
|
ChainId: "0gchainlocalnet_8888-1",
|
||||||
StakingDenom: "ukava",
|
StakingDenom: chaincfg.DisplayDenom,
|
||||||
}
|
}
|
||||||
kvtoolIbcChain = ChainDetails{
|
kvtoolIbcChain = ChainDetails{
|
||||||
RpcUrl: "http://localhost:26658",
|
RpcUrl: "http://localhost:26658",
|
||||||
GrpcUrl: "http://localhost:9092",
|
GrpcUrl: "http://localhost:9092",
|
||||||
EvmRpcUrl: "http://localhost:8547",
|
EvmRpcUrl: "http://localhost:8547",
|
||||||
|
|
||||||
ChainId: "kavalocalnet_8889-2",
|
ChainId: "0gchainlocalnet_8889-2",
|
||||||
StakingDenom: "uatom",
|
StakingDenom: "uatom",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -8,24 +8,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type KvtoolRunnerConfig struct {
|
type KvtoolRunnerConfig struct {
|
||||||
KavaConfigTemplate string
|
ZgChainConfigTemplate string
|
||||||
|
|
||||||
ImageTag string
|
ImageTag string
|
||||||
IncludeIBC bool
|
IncludeIBC bool
|
||||||
|
|
||||||
EnableAutomatedUpgrade bool
|
EnableAutomatedUpgrade bool
|
||||||
KavaUpgradeName string
|
ZgChainUpgradeName string
|
||||||
KavaUpgradeHeight int64
|
ZgChainUpgradeHeight int64
|
||||||
KavaUpgradeBaseImageTag string
|
ZgChainUpgradeBaseImageTag string
|
||||||
|
|
||||||
SkipShutdown bool
|
SkipShutdown bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// KvtoolRunner implements a NodeRunner that spins up local chains with kvtool.
|
// KvtoolRunner implements a NodeRunner that spins up local chains with kvtool.
|
||||||
// It has support for the following:
|
// It has support for the following:
|
||||||
// - running a Kava node
|
// - running a ZgChain node
|
||||||
// - optionally, running an IBC node with a channel opened to the Kava node
|
// - optionally, running an IBC node with a channel opened to the ZgChain node
|
||||||
// - optionally, start the Kava node on one version and upgrade to another
|
// - optionally, start the ZgChain node on one version and upgrade to another
|
||||||
type KvtoolRunner struct {
|
type KvtoolRunner struct {
|
||||||
config KvtoolRunnerConfig
|
config KvtoolRunnerConfig
|
||||||
}
|
}
|
||||||
@ -51,8 +51,8 @@ func (k *KvtoolRunner) StartChains() Chains {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// start local test network with kvtool
|
// start local test network with kvtool
|
||||||
log.Println("starting kava node")
|
log.Println("starting 0gchain node")
|
||||||
kvtoolArgs := []string{"testnet", "bootstrap", "--kava.configTemplate", k.config.KavaConfigTemplate}
|
kvtoolArgs := []string{"testnet", "bootstrap", "--0gchain.configTemplate", k.config.ZgChainConfigTemplate}
|
||||||
// include an ibc chain if desired
|
// include an ibc chain if desired
|
||||||
if k.config.IncludeIBC {
|
if k.config.IncludeIBC {
|
||||||
kvtoolArgs = append(kvtoolArgs, "--ibc")
|
kvtoolArgs = append(kvtoolArgs, "--ibc")
|
||||||
@ -60,32 +60,32 @@ func (k *KvtoolRunner) StartChains() Chains {
|
|||||||
// handle automated upgrade functionality, if defined
|
// handle automated upgrade functionality, if defined
|
||||||
if k.config.EnableAutomatedUpgrade {
|
if k.config.EnableAutomatedUpgrade {
|
||||||
kvtoolArgs = append(kvtoolArgs,
|
kvtoolArgs = append(kvtoolArgs,
|
||||||
"--upgrade-name", k.config.KavaUpgradeName,
|
"--upgrade-name", k.config.ZgChainUpgradeName,
|
||||||
"--upgrade-height", fmt.Sprint(k.config.KavaUpgradeHeight),
|
"--upgrade-height", fmt.Sprint(k.config.ZgChainUpgradeHeight),
|
||||||
"--upgrade-base-image-tag", k.config.KavaUpgradeBaseImageTag,
|
"--upgrade-base-image-tag", k.config.ZgChainUpgradeBaseImageTag,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// start the chain
|
// start the chain
|
||||||
startKavaCmd := exec.Command("kvtool", kvtoolArgs...)
|
startZgChainCmd := exec.Command("kvtool", kvtoolArgs...)
|
||||||
startKavaCmd.Env = os.Environ()
|
startZgChainCmd.Env = os.Environ()
|
||||||
startKavaCmd.Env = append(startKavaCmd.Env, fmt.Sprintf("KAVA_TAG=%s", k.config.ImageTag))
|
startZgChainCmd.Env = append(startZgChainCmd.Env, fmt.Sprintf("0GCHAIN_TAG=%s", k.config.ImageTag))
|
||||||
startKavaCmd.Stdout = os.Stdout
|
startZgChainCmd.Stdout = os.Stdout
|
||||||
startKavaCmd.Stderr = os.Stderr
|
startZgChainCmd.Stderr = os.Stderr
|
||||||
log.Println(startKavaCmd.String())
|
log.Println(startZgChainCmd.String())
|
||||||
if err := startKavaCmd.Run(); err != nil {
|
if err := startZgChainCmd.Run(); err != nil {
|
||||||
panic(fmt.Sprintf("failed to start kava: %s", err.Error()))
|
panic(fmt.Sprintf("failed to start 0gchain: %s", err.Error()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for chain to be live.
|
// wait for chain to be live.
|
||||||
// if an upgrade is defined, this waits for the upgrade to be completed.
|
// if an upgrade is defined, this waits for the upgrade to be completed.
|
||||||
if err := waitForChainStart(kvtoolKavaChain); err != nil {
|
if err := waitForChainStart(kvtoolZgChainChain); err != nil {
|
||||||
k.Shutdown()
|
k.Shutdown()
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Println("kava is started!")
|
log.Println("0gchain is started!")
|
||||||
|
|
||||||
chains := NewChains()
|
chains := NewChains()
|
||||||
chains.Register("kava", &kvtoolKavaChain)
|
chains.Register("0gchain", &kvtoolZgChainChain)
|
||||||
if k.config.IncludeIBC {
|
if k.config.IncludeIBC {
|
||||||
chains.Register("ibc", &kvtoolIbcChain)
|
chains.Register("ibc", &kvtoolIbcChain)
|
||||||
}
|
}
|
||||||
@ -101,11 +101,11 @@ func (k *KvtoolRunner) Shutdown() {
|
|||||||
log.Printf("would shut down but SkipShutdown is true")
|
log.Printf("would shut down but SkipShutdown is true")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Println("shutting down kava node")
|
log.Println("shutting down 0gchain node")
|
||||||
shutdownKavaCmd := exec.Command("kvtool", "testnet", "down")
|
shutdownZgChainCmd := exec.Command("kvtool", "testnet", "down")
|
||||||
shutdownKavaCmd.Stdout = os.Stdout
|
shutdownZgChainCmd.Stdout = os.Stdout
|
||||||
shutdownKavaCmd.Stderr = os.Stderr
|
shutdownZgChainCmd.Stderr = os.Stderr
|
||||||
if err := shutdownKavaCmd.Run(); err != nil {
|
if err := shutdownZgChainCmd.Run(); err != nil {
|
||||||
panic(fmt.Sprintf("failed to shutdown kvtool: %s", err.Error()))
|
panic(fmt.Sprintf("failed to shutdown kvtool: %s", err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ import (
|
|||||||
// LiveNodeRunnerConfig implements NodeRunner.
|
// LiveNodeRunnerConfig implements NodeRunner.
|
||||||
// It connects to a running network via the RPC, GRPC, and EVM urls.
|
// It connects to a running network via the RPC, GRPC, and EVM urls.
|
||||||
type LiveNodeRunnerConfig struct {
|
type LiveNodeRunnerConfig struct {
|
||||||
KavaRpcUrl string
|
ZgChainRpcUrl string
|
||||||
KavaGrpcUrl string
|
ZgChainGrpcUrl string
|
||||||
KavaEvmRpcUrl string
|
ZgChainEvmRpcUrl string
|
||||||
|
|
||||||
UpgradeHeight int64
|
UpgradeHeight int64
|
||||||
}
|
}
|
||||||
@ -37,41 +37,41 @@ func NewLiveNodeRunner(config LiveNodeRunnerConfig) *LiveNodeRunner {
|
|||||||
// It initializes connections to the chain based on parameters.
|
// It initializes connections to the chain based on parameters.
|
||||||
// It attempts to ping the necessary endpoints and panics if they cannot be reached.
|
// It attempts to ping the necessary endpoints and panics if they cannot be reached.
|
||||||
func (r LiveNodeRunner) StartChains() Chains {
|
func (r LiveNodeRunner) StartChains() Chains {
|
||||||
fmt.Println("establishing connection to live kava network")
|
fmt.Println("establishing connection to live 0g-chain network")
|
||||||
chains := NewChains()
|
chains := NewChains()
|
||||||
|
|
||||||
kavaChain := ChainDetails{
|
zgChain := ChainDetails{
|
||||||
RpcUrl: r.config.KavaRpcUrl,
|
RpcUrl: r.config.ZgChainRpcUrl,
|
||||||
GrpcUrl: r.config.KavaGrpcUrl,
|
GrpcUrl: r.config.ZgChainGrpcUrl,
|
||||||
EvmRpcUrl: r.config.KavaEvmRpcUrl,
|
EvmRpcUrl: r.config.ZgChainEvmRpcUrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := waitForChainStart(kavaChain); err != nil {
|
if err := waitForChainStart(zgChain); err != nil {
|
||||||
panic(fmt.Sprintf("failed to ping chain: %s", err))
|
panic(fmt.Sprintf("failed to ping chain: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine chain id
|
// determine chain id
|
||||||
client, err := grpc.NewClient(kavaChain.GrpcUrl)
|
client, err := grpc.NewClient(zgChain.GrpcUrl)
|
||||||
if err != nil {
|
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{})
|
nodeInfo, err := client.Query.Tm.GetNodeInfo(context.Background(), &tmservice.GetNodeInfoRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to fetch kava node info: %s", err))
|
panic(fmt.Sprintf("failed to fetch 0gchain node info: %s", err))
|
||||||
}
|
}
|
||||||
kavaChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
zgChain.ChainId = nodeInfo.DefaultNodeInfo.Network
|
||||||
|
|
||||||
// determine staking denom
|
// determine staking denom
|
||||||
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
|
stakingParams, err := client.Query.Staking.Params(context.Background(), &stakingtypes.QueryParamsRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to fetch kava staking params: %s", err))
|
panic(fmt.Sprintf("failed to fetch 0gchain staking params: %s", err))
|
||||||
}
|
}
|
||||||
kavaChain.StakingDenom = stakingParams.Params.BondDenom
|
zgChain.StakingDenom = stakingParams.Params.BondDenom
|
||||||
|
|
||||||
chains.Register("kava", &kavaChain)
|
chains.Register("0gchain", &zgChain)
|
||||||
|
|
||||||
fmt.Printf("successfully connected to live network %+v\n", kavaChain)
|
fmt.Printf("successfully connected to live network %+v\n", zgChain)
|
||||||
|
|
||||||
return chains
|
return chains
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ func waitForChainStart(chainDetails ChainDetails) error {
|
|||||||
b := backoff.NewExponentialBackOff()
|
b := backoff.NewExponentialBackOff()
|
||||||
b.MaxInterval = 5 * time.Second
|
b.MaxInterval = 5 * time.Second
|
||||||
b.MaxElapsedTime = 30 * time.Second
|
b.MaxElapsedTime = 30 * time.Second
|
||||||
if err := backoff.Retry(func() error { return pingKava(chainDetails.RpcUrl) }, b); err != nil {
|
if err := backoff.Retry(func() error { return pingZgChain(chainDetails.RpcUrl) }, b); err != nil {
|
||||||
return fmt.Errorf("failed connect to chain: %s", err)
|
return fmt.Errorf("failed connect to chain: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,9 +34,9 @@ func waitForChainStart(chainDetails ChainDetails) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func pingKava(rpcUrl string) error {
|
func pingZgChain(rpcUrl string) error {
|
||||||
statusUrl := fmt.Sprintf("%s/status", rpcUrl)
|
statusUrl := fmt.Sprintf("%s/status", rpcUrl)
|
||||||
log.Printf("pinging kava chain: %s\n", statusUrl)
|
log.Printf("pinging 0g-chain: %s\n", statusUrl)
|
||||||
res, err := http.Get(statusUrl)
|
res, err := http.Get(statusUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -45,7 +45,7 @@ func pingKava(rpcUrl string) error {
|
|||||||
if res.StatusCode >= 400 {
|
if res.StatusCode >= 400 {
|
||||||
return fmt.Errorf("ping to status failed: %d", res.StatusCode)
|
return fmt.Errorf("ping to status failed: %d", res.StatusCode)
|
||||||
}
|
}
|
||||||
log.Println("successfully started Kava!")
|
log.Println("successfully started ZgChain!")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
emtests "github.com/evmos/ethermint/tests"
|
emtests "github.com/evmos/ethermint/tests"
|
||||||
emtypes "github.com/evmos/ethermint/types"
|
emtypes "github.com/evmos/ethermint/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,9 +43,9 @@ type SigningAccount struct {
|
|||||||
evmReqChan chan<- util.EvmTxRequest
|
evmReqChan chan<- util.EvmTxRequest
|
||||||
evmResChan <-chan util.EvmTxResponse
|
evmResChan <-chan util.EvmTxResponse
|
||||||
|
|
||||||
kavaSigner *util.KavaSigner
|
zgChainSigner *util.ZgChainSigner
|
||||||
sdkReqChan chan<- util.KavaMsgRequest
|
sdkReqChan chan<- util.ZgChainMsgRequest
|
||||||
sdkResChan <-chan util.KavaMsgResponse
|
sdkResChan <-chan util.ZgChainMsgResponse
|
||||||
|
|
||||||
EvmAuth *bind.TransactOpts
|
EvmAuth *bind.TransactOpts
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ func (chain *Chain) AddNewSigningAccount(name string, hdPath *hd.BIP44Params, ch
|
|||||||
chain.t.Fatalf("account with name %s already exists", name)
|
chain.t.Fatalf("account with name %s already exists", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kava signing account for SDK side
|
// 0gChain signing account for SDK side
|
||||||
privKeyBytes, err := hd.Secp256k1.Derive()(mnemonic, "", hdPath.String())
|
privKeyBytes, err := hd.Secp256k1.Derive()(mnemonic, "", hdPath.String())
|
||||||
require.NoErrorf(chain.t, err, "failed to derive private key from mnemonic for %s: %s", name, err)
|
require.NoErrorf(chain.t, err, "failed to derive private key from mnemonic for %s: %s", name, err)
|
||||||
privKey := ðsecp256k1.PrivKey{Key: privKeyBytes}
|
privKey := ðsecp256k1.PrivKey{Key: privKeyBytes}
|
||||||
@ -97,8 +97,8 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
|||||||
chain.t.Fatalf("account with name %s already exists", name)
|
chain.t.Fatalf("account with name %s already exists", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kava signing account for SDK side
|
// 0gChain signing account for SDK side
|
||||||
kavaSigner := util.NewKavaSigner(
|
zgChainSigner := util.NewZgChainSigner(
|
||||||
chainId,
|
chainId,
|
||||||
chain.EncodingConfig,
|
chain.EncodingConfig,
|
||||||
chain.Grpc.Query.Auth,
|
chain.Grpc.Query.Auth,
|
||||||
@ -107,11 +107,11 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
|||||||
100,
|
100,
|
||||||
)
|
)
|
||||||
|
|
||||||
sdkReqChan := make(chan util.KavaMsgRequest)
|
sdkReqChan := make(chan util.ZgChainMsgRequest)
|
||||||
sdkResChan, err := kavaSigner.Run(sdkReqChan)
|
sdkResChan, err := zgChainSigner.Run(sdkReqChan)
|
||||||
require.NoErrorf(chain.t, err, "failed to start signer for account %s: %s", name, err)
|
require.NoErrorf(chain.t, err, "failed to start signer for account %s: %s", name, err)
|
||||||
|
|
||||||
// Kava signing account for EVM side
|
// 0gChain signing account for EVM side
|
||||||
evmChainId, err := emtypes.ParseChainID(chainId)
|
evmChainId, err := emtypes.ParseChainID(chainId)
|
||||||
require.NoErrorf(chain.t, err, "unable to parse ethermint-compatible chain id from %s", chainId)
|
require.NoErrorf(chain.t, err, "unable to parse ethermint-compatible chain id from %s", chainId)
|
||||||
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes()))
|
ecdsaPrivKey, err := crypto.HexToECDSA(hex.EncodeToString(privKey.Bytes()))
|
||||||
@ -141,21 +141,21 @@ func (chain *Chain) AddNewSigningAccountFromPrivKey(
|
|||||||
evmReqChan: evmReqChan,
|
evmReqChan: evmReqChan,
|
||||||
evmResChan: evmResChan,
|
evmResChan: evmResChan,
|
||||||
|
|
||||||
kavaSigner: kavaSigner,
|
zgChainSigner: zgChainSigner,
|
||||||
sdkReqChan: sdkReqChan,
|
sdkReqChan: sdkReqChan,
|
||||||
sdkResChan: sdkResChan,
|
sdkResChan: sdkResChan,
|
||||||
|
|
||||||
EvmAuth: evmSigner.Auth,
|
EvmAuth: evmSigner.Auth,
|
||||||
|
|
||||||
EvmAddress: evmSigner.Address(),
|
EvmAddress: evmSigner.Address(),
|
||||||
SdkAddress: kavaSigner.Address(),
|
SdkAddress: zgChainSigner.Address(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return chain.accounts[name]
|
return chain.accounts[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignAndBroadcastKavaTx sends a request to the signer and awaits its response.
|
// SignAndBroadcastZgChainTx sends a request to the signer and awaits its response.
|
||||||
func (a *SigningAccount) SignAndBroadcastKavaTx(req util.KavaMsgRequest) util.KavaMsgResponse {
|
func (a *SigningAccount) SignAndBroadcastZgChainTx(req util.ZgChainMsgRequest) util.ZgChainMsgResponse {
|
||||||
a.l.Printf("broadcasting sdk tx. has data = %+v\n", req.Data)
|
a.l.Printf("broadcasting sdk tx. has data = %+v\n", req.Data)
|
||||||
// send the request to signer
|
// send the request to signer
|
||||||
a.sdkReqChan <- req
|
a.sdkReqChan <- req
|
||||||
@ -222,7 +222,7 @@ func (chain *Chain) NewFundedAccount(name string, funds sdk.Coins) *SigningAccou
|
|||||||
|
|
||||||
acc := chain.AddNewSigningAccount(
|
acc := chain.AddNewSigningAccount(
|
||||||
name,
|
name,
|
||||||
hd.CreateHDPath(app.Bip44CoinType, 0, 0),
|
hd.CreateHDPath(chaincfg.Bip44CoinType, 0, 0),
|
||||||
chain.ChainID,
|
chain.ChainID,
|
||||||
mnemonic,
|
mnemonic,
|
||||||
)
|
)
|
||||||
@ -257,12 +257,12 @@ func (a *SigningAccount) NextNonce() (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BankSend is a helper method for sending funds via x/bank's MsgSend
|
// BankSend is a helper method for sending funds via x/bank's MsgSend
|
||||||
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.KavaMsgResponse {
|
func (a *SigningAccount) BankSend(to sdk.AccAddress, amount sdk.Coins) util.ZgChainMsgResponse {
|
||||||
return a.SignAndBroadcastKavaTx(
|
return a.SignAndBroadcastZgChainTx(
|
||||||
util.KavaMsgRequest{
|
util.ZgChainMsgRequest{
|
||||||
Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)},
|
Msgs: []sdk.Msg{banktypes.NewMsgSend(a.SdkAddress, to, amount)},
|
||||||
GasLimit: 2e5, // 200,000 gas
|
GasLimit: 2e5, // 200,000 gas
|
||||||
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001ukava
|
FeeAmount: sdk.NewCoins(sdk.NewCoin(a.gasDenom, sdkmath.NewInt(200))), // assume min gas price of .001a0gi
|
||||||
Data: fmt.Sprintf("sending %s to %s", amount, to),
|
Data: fmt.Sprintf("sending %s to %s", amount, to),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/ethclient"
|
"github.com/ethereum/go-ethereum/ethclient"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
kavaparams "github.com/0glabs/0g-chain/app/params"
|
chainparams "github.com/0glabs/0g-chain/app/params"
|
||||||
"github.com/0glabs/0g-chain/client/grpc"
|
"github.com/0glabs/0g-chain/client/grpc"
|
||||||
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
@ -41,11 +41,11 @@ type Chain struct {
|
|||||||
ContractAddrs map[string]common.Address
|
ContractAddrs map[string]common.Address
|
||||||
erc20s map[common.Address]struct{}
|
erc20s map[common.Address]struct{}
|
||||||
|
|
||||||
EncodingConfig kavaparams.EncodingConfig
|
EncodingConfig chainparams.EncodingConfig
|
||||||
|
|
||||||
TmSignClient tmclient.SignClient
|
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.
|
// 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(
|
kr, err := keyring.New(
|
||||||
sdk.KeyringServiceName(),
|
sdk.KeyringServiceName(),
|
||||||
keyring.BackendTest,
|
keyring.BackendTest,
|
||||||
util.KavaHomePath(),
|
util.ZgChainHomePath(),
|
||||||
nil,
|
nil,
|
||||||
chain.EncodingConfig.Marshaler,
|
chain.EncodingConfig.Marshaler,
|
||||||
evmhd.EthSecp256k1Option(),
|
evmhd.EthSecp256k1Option(),
|
||||||
@ -77,7 +77,7 @@ func NewChain(t *testing.T, details *runner.ChainDetails, fundedAccountMnemonic
|
|||||||
|
|
||||||
client, err := grpc.NewClient(details.GrpcUrl)
|
client, err := grpc.NewClient(details.GrpcUrl)
|
||||||
if err != nil {
|
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
|
chain.Grpc = client
|
||||||
|
|
||||||
|
@ -36,26 +36,26 @@ type SuiteConfig struct {
|
|||||||
// KvtoolConfig wraps configuration options for running the end-to-end test suite against
|
// KvtoolConfig wraps configuration options for running the end-to-end test suite against
|
||||||
// a locally running chain. This config must be defined if E2E_RUN_KVTOOL_NETWORKS is true.
|
// a locally running chain. This config must be defined if E2E_RUN_KVTOOL_NETWORKS is true.
|
||||||
type KvtoolConfig struct {
|
type KvtoolConfig struct {
|
||||||
// The kava.configTemplate flag to be passed to kvtool, usually "master".
|
// The 0gchain.configTemplate flag to be passed to kvtool, usually "master".
|
||||||
// This allows one to change the base genesis used to start the chain.
|
// This allows one to change the base genesis used to start the chain.
|
||||||
KavaConfigTemplate string
|
ZgChainConfigTemplate string
|
||||||
|
|
||||||
// Whether or not to run a chain upgrade & run post-upgrade tests. Use `suite.SkipIfUpgradeDisabled()` in post-upgrade tests.
|
// Whether or not to run a chain upgrade & run post-upgrade tests. Use `suite.SkipIfUpgradeDisabled()` in post-upgrade tests.
|
||||||
IncludeAutomatedUpgrade bool
|
IncludeAutomatedUpgrade bool
|
||||||
// Name of the upgrade, if upgrade is enabled.
|
// Name of the upgrade, if upgrade is enabled.
|
||||||
KavaUpgradeName string
|
ZgChainUpgradeName string
|
||||||
// Height upgrade will be applied to the test chain, if upgrade is enabled.
|
// Height upgrade will be applied to the test chain, if upgrade is enabled.
|
||||||
KavaUpgradeHeight int64
|
ZgChainUpgradeHeight int64
|
||||||
// Tag of kava docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
|
// Tag of 0gchain docker image that will be upgraded to the current image before tests are run, if upgrade is enabled.
|
||||||
KavaUpgradeBaseImageTag string
|
ZgChainUpgradeBaseImageTag string
|
||||||
}
|
}
|
||||||
|
|
||||||
// LiveNetworkConfig wraps configuration options for running the end-to-end test suite
|
// LiveNetworkConfig wraps configuration options for running the end-to-end test suite
|
||||||
// against a live network. It must be defined if E2E_RUN_KVTOOL_NETWORKS is false.
|
// against a live network. It must be defined if E2E_RUN_KVTOOL_NETWORKS is false.
|
||||||
type LiveNetworkConfig struct {
|
type LiveNetworkConfig struct {
|
||||||
KavaRpcUrl string
|
ZgChainRpcUrl string
|
||||||
KavaGrpcUrl string
|
ZgChainGrpcUrl string
|
||||||
KavaEvmRpcUrl string
|
ZgChainEvmRpcUrl string
|
||||||
|
|
||||||
UpgradeHeight int64
|
UpgradeHeight int64
|
||||||
}
|
}
|
||||||
@ -65,8 +65,8 @@ func ParseSuiteConfig() SuiteConfig {
|
|||||||
config := SuiteConfig{
|
config := SuiteConfig{
|
||||||
// this mnemonic is expected to be a funded account that can seed the funds for all
|
// this mnemonic is expected to be a funded account that can seed the funds for all
|
||||||
// new accounts created during tests. it will be available under Accounts["whale"]
|
// new accounts created during tests. it will be available under Accounts["whale"]
|
||||||
FundedAccountMnemonic: nonemptyStringEnv("E2E_KAVA_FUNDED_ACCOUNT_MNEMONIC"),
|
FundedAccountMnemonic: nonemptyStringEnv("E2E_0GCHAIN_FUNDED_ACCOUNT_MNEMONIC"),
|
||||||
ZgchainERC20Address: nonemptyStringEnv("E2E_KAVA_ERC20_ADDRESS"),
|
ZgchainERC20Address: nonemptyStringEnv("E2E_0GCHAIN_ERC20_ADDRESS"),
|
||||||
IncludeIbcTests: mustParseBool("E2E_INCLUDE_IBC_TESTS"),
|
IncludeIbcTests: mustParseBool("E2E_INCLUDE_IBC_TESTS"),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,18 +90,18 @@ func ParseSuiteConfig() SuiteConfig {
|
|||||||
// ParseKvtoolConfig builds a KvtoolConfig from environment variables.
|
// ParseKvtoolConfig builds a KvtoolConfig from environment variables.
|
||||||
func ParseKvtoolConfig() KvtoolConfig {
|
func ParseKvtoolConfig() KvtoolConfig {
|
||||||
config := KvtoolConfig{
|
config := KvtoolConfig{
|
||||||
KavaConfigTemplate: nonemptyStringEnv("E2E_KVTOOL_KAVA_CONFIG_TEMPLATE"),
|
ZgChainConfigTemplate: nonemptyStringEnv("E2E_KVTOOL_0GCHAIN_CONFIG_TEMPLATE"),
|
||||||
IncludeAutomatedUpgrade: mustParseBool("E2E_INCLUDE_AUTOMATED_UPGRADE"),
|
IncludeAutomatedUpgrade: mustParseBool("E2E_INCLUDE_AUTOMATED_UPGRADE"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.IncludeAutomatedUpgrade {
|
if config.IncludeAutomatedUpgrade {
|
||||||
config.KavaUpgradeName = nonemptyStringEnv("E2E_KAVA_UPGRADE_NAME")
|
config.ZgChainUpgradeName = nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_NAME")
|
||||||
config.KavaUpgradeBaseImageTag = nonemptyStringEnv("E2E_KAVA_UPGRADE_BASE_IMAGE_TAG")
|
config.ZgChainUpgradeBaseImageTag = nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_BASE_IMAGE_TAG")
|
||||||
upgradeHeight, err := strconv.ParseInt(nonemptyStringEnv("E2E_KAVA_UPGRADE_HEIGHT"), 10, 64)
|
upgradeHeight, err := strconv.ParseInt(nonemptyStringEnv("E2E_0GCHAIN_UPGRADE_HEIGHT"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("E2E_KAVA_UPGRADE_HEIGHT must be a number: %s", err))
|
panic(fmt.Sprintf("E2E_0GCHAIN_UPGRADE_HEIGHT must be a number: %s", err))
|
||||||
}
|
}
|
||||||
config.KavaUpgradeHeight = upgradeHeight
|
config.ZgChainUpgradeHeight = upgradeHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
@ -110,16 +110,16 @@ func ParseKvtoolConfig() KvtoolConfig {
|
|||||||
// ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.
|
// ParseLiveNetworkConfig builds a LiveNetworkConfig from environment variables.
|
||||||
func ParseLiveNetworkConfig() LiveNetworkConfig {
|
func ParseLiveNetworkConfig() LiveNetworkConfig {
|
||||||
config := LiveNetworkConfig{
|
config := LiveNetworkConfig{
|
||||||
KavaRpcUrl: nonemptyStringEnv("E2E_KAVA_RPC_URL"),
|
ZgChainRpcUrl: nonemptyStringEnv("E2E_0GCHAIN_RPC_URL"),
|
||||||
KavaGrpcUrl: nonemptyStringEnv("E2E_KAVA_GRPC_URL"),
|
ZgChainGrpcUrl: nonemptyStringEnv("E2E_0GCHAIN_GRPC_URL"),
|
||||||
KavaEvmRpcUrl: nonemptyStringEnv("E2E_KAVA_EVM_RPC_URL"),
|
ZgChainEvmRpcUrl: nonemptyStringEnv("E2E_0GCHAIN_EVM_RPC_URL"),
|
||||||
}
|
}
|
||||||
|
|
||||||
upgradeHeight := os.Getenv("E2E_KAVA_UPGRADE_HEIGHT")
|
upgradeHeight := os.Getenv("E2E_0GCHAIN_UPGRADE_HEIGHT")
|
||||||
if upgradeHeight != "" {
|
if upgradeHeight != "" {
|
||||||
parsedHeight, err := strconv.ParseInt(upgradeHeight, 10, 64)
|
parsedHeight, err := strconv.ParseInt(upgradeHeight, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("E2E_KAVA_UPGRADE_HEIGHT must be a number: %s", err))
|
panic(fmt.Sprintf("E2E_0GCHAIN_UPGRADE_HEIGHT must be a number: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
config.UpgradeHeight = parsedHeight
|
config.UpgradeHeight = parsedHeight
|
||||||
|
@ -12,13 +12,13 @@ import (
|
|||||||
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
evmutiltypes "github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitKavaEvmData is run after the chain is running, but before the tests are run.
|
// InitZgChainEvmData is run after the chain is running, but before the tests are run.
|
||||||
// It is used to initialize some EVM state, such as deploying contracts.
|
// It is used to initialize some EVM state, such as deploying contracts.
|
||||||
func (suite *E2eTestSuite) InitKavaEvmData() {
|
func (suite *E2eTestSuite) InitZgChainEvmData() {
|
||||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||||
|
|
||||||
// ensure funded account has nonzero erc20 balance
|
// ensure funded account has nonzero erc20 balance
|
||||||
balance := suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
balance := suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||||
if balance.Cmp(big.NewInt(0)) != 1 {
|
if balance.Cmp(big.NewInt(0)) != 1 {
|
||||||
panic(fmt.Sprintf(
|
panic(fmt.Sprintf(
|
||||||
"expected funded account (%s) to have erc20 balance of token %s",
|
"expected funded account (%s) to have erc20 balance of token %s",
|
||||||
@ -28,7 +28,7 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// expect the erc20 to be enabled for conversion to sdk.Coin
|
// expect the erc20 to be enabled for conversion to sdk.Coin
|
||||||
params, err := suite.Kava.Grpc.Query.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
|
params, err := suite.ZgChain.Grpc.Query.Evmutil.Params(context.Background(), &evmutiltypes.QueryParamsRequest{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to fetch evmutil params during init: %s", err))
|
panic(fmt.Sprintf("failed to fetch evmutil params during init: %s", err))
|
||||||
}
|
}
|
||||||
@ -43,10 +43,10 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
|||||||
if !found {
|
if !found {
|
||||||
panic(fmt.Sprintf("erc20 %s must be enabled for conversion to cosmos coin", erc20Addr))
|
panic(fmt.Sprintf("erc20 %s must be enabled for conversion to cosmos coin", erc20Addr))
|
||||||
}
|
}
|
||||||
suite.Kava.RegisterErc20(suite.DeployedErc20.Address)
|
suite.ZgChain.RegisterErc20(suite.DeployedErc20.Address)
|
||||||
|
|
||||||
// expect the erc20's cosmos denom to be a supported cdp collateral type
|
// 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)
|
// suite.Require().NoError(err)
|
||||||
// found = false
|
// found = false
|
||||||
// for _, cp := range cdpParams.Params.CollateralParams {
|
// for _, cp := range cdpParams.Params.CollateralParams {
|
||||||
@ -69,13 +69,13 @@ func (suite *E2eTestSuite) InitKavaEvmData() {
|
|||||||
"what's up!",
|
"what's up!",
|
||||||
)
|
)
|
||||||
suite.NoError(err, "failed to deploy a contract to the EVM")
|
suite.NoError(err, "failed to deploy a contract to the EVM")
|
||||||
suite.Kava.ContractAddrs["greeter"] = greeterAddr
|
suite.ZgChain.ContractAddrs["greeter"] = greeterAddr
|
||||||
}
|
}
|
||||||
|
|
||||||
// FundKavaErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.
|
// FundZgChainErc20Balance sends the pre-deployed ERC20 token to the `toAddress`.
|
||||||
func (suite *E2eTestSuite) FundKavaErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
|
func (suite *E2eTestSuite) FundZgChainErc20Balance(toAddress common.Address, amount *big.Int) EvmTxResponse {
|
||||||
// funded account should have erc20 balance
|
// funded account should have erc20 balance
|
||||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||||
res, err := whale.TransferErc20(suite.DeployedErc20.Address, toAddress, amount)
|
res, err := whale.TransferErc20(suite.DeployedErc20.Address, toAddress, amount)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
return res
|
return res
|
||||||
|
@ -10,14 +10,14 @@ import (
|
|||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
"github.com/0glabs/0g-chain/tests/e2e/runner"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
FundedAccountName = "whale"
|
FundedAccountName = "whale"
|
||||||
// use coin type 60 so we are compatible with accounts from `kava add keys --eth <name>`
|
// use coin type 60 so we are compatible with accounts from `0gchaind add keys --eth <name>`
|
||||||
// these accounts use the ethsecp256k1 signing algorithm that allows the signing client
|
// these accounts use the ethsecp256k1 signing algorithm that allows the signing client
|
||||||
// to manage both sdk & evm txs.
|
// to manage both sdk & evm txs.
|
||||||
Bip44CoinType = 60
|
Bip44CoinType = 60
|
||||||
@ -33,7 +33,7 @@ const (
|
|||||||
// - the funded account has a nonzero balance of the erc20
|
// - the funded account has a nonzero balance of the erc20
|
||||||
// - the erc20 is enabled for conversion to sdk.Coin
|
// - the erc20 is enabled for conversion to sdk.Coin
|
||||||
// - the corresponding sdk.Coin is enabled as a cdp collateral type
|
// - the corresponding sdk.Coin is enabled as a cdp collateral type
|
||||||
// These requirements are checked in InitKavaEvmData().
|
// These requirements are checked in InitZgChainEvmData().
|
||||||
type DeployedErc20 struct {
|
type DeployedErc20 struct {
|
||||||
Address common.Address
|
Address common.Address
|
||||||
CosmosDenom string
|
CosmosDenom string
|
||||||
@ -41,15 +41,15 @@ type DeployedErc20 struct {
|
|||||||
CdpCollateralType string
|
CdpCollateralType string
|
||||||
}
|
}
|
||||||
|
|
||||||
// E2eTestSuite is a testify test suite for running end-to-end integration tests on Kava.
|
// E2eTestSuite is a testify test suite for running end-to-end integration tests on ZgChain.
|
||||||
type E2eTestSuite struct {
|
type E2eTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
config SuiteConfig
|
config SuiteConfig
|
||||||
runner runner.NodeRunner
|
runner runner.NodeRunner
|
||||||
|
|
||||||
Kava *Chain
|
ZgChain *Chain
|
||||||
Ibc *Chain
|
Ibc *Chain
|
||||||
|
|
||||||
UpgradeHeight int64
|
UpgradeHeight int64
|
||||||
DeployedErc20 DeployedErc20
|
DeployedErc20 DeployedErc20
|
||||||
@ -85,13 +85,13 @@ func (s costSummary) String() string {
|
|||||||
func (suite *E2eTestSuite) SetupSuite() {
|
func (suite *E2eTestSuite) SetupSuite() {
|
||||||
var err error
|
var err error
|
||||||
fmt.Println("setting up test suite.")
|
fmt.Println("setting up test suite.")
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
|
|
||||||
suiteConfig := ParseSuiteConfig()
|
suiteConfig := ParseSuiteConfig()
|
||||||
suite.config = suiteConfig
|
suite.config = suiteConfig
|
||||||
suite.DeployedErc20 = DeployedErc20{
|
suite.DeployedErc20 = DeployedErc20{
|
||||||
Address: common.HexToAddress(suiteConfig.ZgchainERC20Address),
|
Address: common.HexToAddress(suiteConfig.ZgchainERC20Address),
|
||||||
// Denom & CdpCollateralType are fetched in InitKavaEvmData()
|
// Denom & CdpCollateralType are fetched in InitZgChainEvmData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup the correct NodeRunner for the given config
|
// setup the correct NodeRunner for the given config
|
||||||
@ -104,11 +104,11 @@ func (suite *E2eTestSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
chains := suite.runner.StartChains()
|
chains := suite.runner.StartChains()
|
||||||
kavachain := chains.MustGetChain("kava")
|
zgchain := chains.MustGetChain("0gchain")
|
||||||
suite.Kava, err = NewChain(suite.T(), kavachain, suiteConfig.FundedAccountMnemonic)
|
suite.ZgChain, err = NewChain(suite.T(), zgchain, suiteConfig.FundedAccountMnemonic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
suite.runner.Shutdown()
|
suite.runner.Shutdown()
|
||||||
suite.T().Fatalf("failed to create kava chain querier: %s", err)
|
suite.T().Fatalf("failed to create 0g-chain querier: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if suiteConfig.IncludeIbcTests {
|
if suiteConfig.IncludeIbcTests {
|
||||||
@ -120,14 +120,14 @@ func (suite *E2eTestSuite) SetupSuite() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.InitKavaEvmData()
|
suite.InitZgChainEvmData()
|
||||||
|
|
||||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||||
suite.cost = costSummary{
|
suite.cost = costSummary{
|
||||||
sdkAddress: whale.SdkAddress.String(),
|
sdkAddress: whale.SdkAddress.String(),
|
||||||
evmAddress: whale.EvmAddress.Hex(),
|
evmAddress: whale.EvmAddress.Hex(),
|
||||||
sdkBalanceBefore: suite.Kava.QuerySdkForBalances(whale.SdkAddress),
|
sdkBalanceBefore: suite.ZgChain.QuerySdkForBalances(whale.SdkAddress),
|
||||||
erc20BalanceBefore: suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress),
|
erc20BalanceBefore: suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,27 +136,27 @@ func (suite *E2eTestSuite) SetupSuite() {
|
|||||||
func (suite *E2eTestSuite) TearDownSuite() {
|
func (suite *E2eTestSuite) TearDownSuite() {
|
||||||
fmt.Println("tearing down test suite.")
|
fmt.Println("tearing down test suite.")
|
||||||
|
|
||||||
whale := suite.Kava.GetAccount(FundedAccountName)
|
whale := suite.ZgChain.GetAccount(FundedAccountName)
|
||||||
|
|
||||||
if suite.enableRefunds {
|
if suite.enableRefunds {
|
||||||
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
|
suite.cost.sdkBalanceAfter = suite.ZgChain.QuerySdkForBalances(whale.SdkAddress)
|
||||||
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
suite.cost.erc20BalanceAfter = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||||
fmt.Println("==BEFORE REFUNDS==")
|
fmt.Println("==BEFORE REFUNDS==")
|
||||||
fmt.Println(suite.cost)
|
fmt.Println(suite.cost)
|
||||||
|
|
||||||
fmt.Println("attempting to return all unused funds")
|
fmt.Println("attempting to return all unused funds")
|
||||||
suite.Kava.ReturnAllFunds()
|
suite.ZgChain.ReturnAllFunds()
|
||||||
|
|
||||||
fmt.Println("==AFTER REFUNDS==")
|
fmt.Println("==AFTER REFUNDS==")
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate & output cost summary for funded account
|
// calculate & output cost summary for funded account
|
||||||
suite.cost.sdkBalanceAfter = suite.Kava.QuerySdkForBalances(whale.SdkAddress)
|
suite.cost.sdkBalanceAfter = suite.ZgChain.QuerySdkForBalances(whale.SdkAddress)
|
||||||
suite.cost.erc20BalanceAfter = suite.Kava.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
suite.cost.erc20BalanceAfter = suite.ZgChain.GetErc20Balance(suite.DeployedErc20.Address, whale.EvmAddress)
|
||||||
fmt.Println(suite.cost)
|
fmt.Println(suite.cost)
|
||||||
|
|
||||||
// close all account request channels
|
// close all account request channels
|
||||||
suite.Kava.Shutdown()
|
suite.ZgChain.Shutdown()
|
||||||
if suite.Ibc != nil {
|
if suite.Ibc != nil {
|
||||||
suite.Ibc.Shutdown()
|
suite.Ibc.Shutdown()
|
||||||
}
|
}
|
||||||
@ -167,19 +167,19 @@ func (suite *E2eTestSuite) TearDownSuite() {
|
|||||||
// SetupKvtoolNodeRunner is a helper method for building a KvtoolRunnerConfig from the suite config.
|
// SetupKvtoolNodeRunner is a helper method for building a KvtoolRunnerConfig from the suite config.
|
||||||
func (suite *E2eTestSuite) SetupKvtoolNodeRunner() *runner.KvtoolRunner {
|
func (suite *E2eTestSuite) SetupKvtoolNodeRunner() *runner.KvtoolRunner {
|
||||||
// upgrade tests are only supported on kvtool networks
|
// upgrade tests are only supported on kvtool networks
|
||||||
suite.UpgradeHeight = suite.config.Kvtool.KavaUpgradeHeight
|
suite.UpgradeHeight = suite.config.Kvtool.ZgChainUpgradeHeight
|
||||||
suite.enableRefunds = false
|
suite.enableRefunds = false
|
||||||
|
|
||||||
runnerConfig := runner.KvtoolRunnerConfig{
|
runnerConfig := runner.KvtoolRunnerConfig{
|
||||||
KavaConfigTemplate: suite.config.Kvtool.KavaConfigTemplate,
|
ZgChainConfigTemplate: suite.config.Kvtool.ZgChainConfigTemplate,
|
||||||
|
|
||||||
IncludeIBC: suite.config.IncludeIbcTests,
|
IncludeIBC: suite.config.IncludeIbcTests,
|
||||||
ImageTag: "local",
|
ImageTag: "local",
|
||||||
|
|
||||||
EnableAutomatedUpgrade: suite.config.Kvtool.IncludeAutomatedUpgrade,
|
EnableAutomatedUpgrade: suite.config.Kvtool.IncludeAutomatedUpgrade,
|
||||||
KavaUpgradeName: suite.config.Kvtool.KavaUpgradeName,
|
ZgChainUpgradeName: suite.config.Kvtool.ZgChainUpgradeName,
|
||||||
KavaUpgradeHeight: suite.config.Kvtool.KavaUpgradeHeight,
|
ZgChainUpgradeHeight: suite.config.Kvtool.ZgChainUpgradeHeight,
|
||||||
KavaUpgradeBaseImageTag: suite.config.Kvtool.KavaUpgradeBaseImageTag,
|
ZgChainUpgradeBaseImageTag: suite.config.Kvtool.ZgChainUpgradeBaseImageTag,
|
||||||
|
|
||||||
SkipShutdown: suite.config.SkipShutdown,
|
SkipShutdown: suite.config.SkipShutdown,
|
||||||
}
|
}
|
||||||
@ -199,10 +199,10 @@ func (suite *E2eTestSuite) SetupLiveNetworkNodeRunner() *runner.LiveNodeRunner {
|
|||||||
suite.enableRefunds = true
|
suite.enableRefunds = true
|
||||||
|
|
||||||
runnerConfig := runner.LiveNodeRunnerConfig{
|
runnerConfig := runner.LiveNodeRunnerConfig{
|
||||||
KavaRpcUrl: suite.config.LiveNetwork.KavaRpcUrl,
|
ZgChainRpcUrl: suite.config.LiveNetwork.ZgChainRpcUrl,
|
||||||
KavaGrpcUrl: suite.config.LiveNetwork.KavaGrpcUrl,
|
ZgChainGrpcUrl: suite.config.LiveNetwork.ZgChainGrpcUrl,
|
||||||
KavaEvmRpcUrl: suite.config.LiveNetwork.KavaEvmRpcUrl,
|
ZgChainEvmRpcUrl: suite.config.LiveNetwork.ZgChainEvmRpcUrl,
|
||||||
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
UpgradeHeight: suite.config.LiveNetwork.UpgradeHeight,
|
||||||
}
|
}
|
||||||
|
|
||||||
return runner.NewLiveNodeRunner(runnerConfig)
|
return runner.NewLiveNodeRunner(runnerConfig)
|
||||||
|
@ -8,13 +8,13 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/tests/util"
|
"github.com/0glabs/0g-chain/tests/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAddressConversion(t *testing.T) {
|
func TestAddressConversion(t *testing.T) {
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
bech32Addr := sdk.MustAccAddressFromBech32("kava17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5")
|
bech32Addr := sdk.MustAccAddressFromBech32("0g17d2wax0zhjrrecvaszuyxdf5wcu5a0p4qlx3t5")
|
||||||
hexAddr := common.HexToAddress("0xf354ee99e2bc863cE19d80b843353476394EbC35")
|
hexAddr := common.HexToAddress("0xf354ee99e2bc863cE19d80b843353476394EbC35")
|
||||||
require.Equal(t, bech32Addr, util.EvmToSdkAddress(hexAddr))
|
require.Equal(t, bech32Addr, util.EvmToSdkAddress(hexAddr))
|
||||||
require.Equal(t, hexAddr, util.SdkToEvmAddress(bech32Addr))
|
require.Equal(t, hexAddr, util.SdkToEvmAddress(bech32Addr))
|
||||||
|
@ -4,8 +4,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KavaHomePath returns the OS-specific filepath for the kava home directory
|
// ZgChainHomePath returns the OS-specific filepath for the 0g-chain home directory
|
||||||
// Assumes network is running with kvtool installed from the sub-repository in tests/e2e/kvtool
|
// Assumes network is running with kvtool installed from the sub-repository in tests/e2e/kvtool
|
||||||
func KavaHomePath() string {
|
func ZgChainHomePath() string {
|
||||||
return filepath.Join("kvtool", "full_configs", "generated", "kava", "initstate", ".kava")
|
return filepath.Join("kvtool", "full_configs", "generated", "0gchaind", "initstate", ".0gchain")
|
||||||
}
|
}
|
||||||
|
@ -27,18 +27,18 @@ var (
|
|||||||
ErrUnsuccessfulTx = errors.New("tx committed but returned nonzero code")
|
ErrUnsuccessfulTx = errors.New("tx committed but returned nonzero code")
|
||||||
)
|
)
|
||||||
|
|
||||||
type KavaMsgRequest struct {
|
type ZgChainMsgRequest struct {
|
||||||
Msgs []sdk.Msg
|
Msgs []sdk.Msg
|
||||||
GasLimit uint64
|
GasLimit uint64
|
||||||
FeeAmount sdk.Coins
|
FeeAmount sdk.Coins
|
||||||
Memo string
|
Memo string
|
||||||
// Arbitrary data to be referenced in the corresponding KavaMsgResponse, unused
|
// Arbitrary data to be referenced in the corresponding ZgChainMsgResponse, unused
|
||||||
// in signing. This is mostly useful to match KavaMsgResponses with KavaMsgRequests.
|
// in signing. This is mostly useful to match ZgChainMsgResponses with ZgChainMsgRequests.
|
||||||
Data interface{}
|
Data interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type KavaMsgResponse struct {
|
type ZgChainMsgResponse struct {
|
||||||
Request KavaMsgRequest
|
Request ZgChainMsgRequest
|
||||||
Tx authsigning.Tx
|
Tx authsigning.Tx
|
||||||
TxBytes []byte
|
TxBytes []byte
|
||||||
Result sdk.TxResponse
|
Result sdk.TxResponse
|
||||||
@ -55,8 +55,8 @@ const (
|
|||||||
txResetSequence
|
txResetSequence
|
||||||
)
|
)
|
||||||
|
|
||||||
// KavaSigner broadcasts msgs to a single kava node
|
// ZgChainSigner broadcasts msgs to a single 0g-chain node
|
||||||
type KavaSigner struct {
|
type ZgChainSigner struct {
|
||||||
chainID string
|
chainID string
|
||||||
encodingConfig params.EncodingConfig
|
encodingConfig params.EncodingConfig
|
||||||
authClient authtypes.QueryClient
|
authClient authtypes.QueryClient
|
||||||
@ -65,15 +65,15 @@ type KavaSigner struct {
|
|||||||
inflightTxLimit uint64
|
inflightTxLimit uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKavaSigner(
|
func NewZgChainSigner(
|
||||||
chainID string,
|
chainID string,
|
||||||
encodingConfig params.EncodingConfig,
|
encodingConfig params.EncodingConfig,
|
||||||
authClient authtypes.QueryClient,
|
authClient authtypes.QueryClient,
|
||||||
txClient txtypes.ServiceClient,
|
txClient txtypes.ServiceClient,
|
||||||
privKey cryptotypes.PrivKey,
|
privKey cryptotypes.PrivKey,
|
||||||
inflightTxLimit uint64) *KavaSigner {
|
inflightTxLimit uint64) *ZgChainSigner {
|
||||||
|
|
||||||
return &KavaSigner{
|
return &ZgChainSigner{
|
||||||
chainID: chainID,
|
chainID: chainID,
|
||||||
encodingConfig: encodingConfig,
|
encodingConfig: encodingConfig,
|
||||||
authClient: authClient,
|
authClient: authClient,
|
||||||
@ -83,7 +83,7 @@ func NewKavaSigner(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *KavaSigner) pollAccountState() <-chan authtypes.AccountI {
|
func (s *ZgChainSigner) pollAccountState() <-chan authtypes.AccountI {
|
||||||
accountState := make(chan authtypes.AccountI)
|
accountState := make(chan authtypes.AccountI)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -109,7 +109,7 @@ func (s *KavaSigner) pollAccountState() <-chan authtypes.AccountI {
|
|||||||
return accountState
|
return accountState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse, error) {
|
func (s *ZgChainSigner) Run(requests <-chan ZgChainMsgRequest) (<-chan ZgChainMsgResponse, error) {
|
||||||
// poll account state in it's own goroutine
|
// poll account state in it's own goroutine
|
||||||
// and send status updates to the signing goroutine
|
// and send status updates to the signing goroutine
|
||||||
//
|
//
|
||||||
@ -117,15 +117,15 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
|||||||
// websocket events with a fallback to polling
|
// websocket events with a fallback to polling
|
||||||
accountState := s.pollAccountState()
|
accountState := s.pollAccountState()
|
||||||
|
|
||||||
responses := make(chan KavaMsgResponse)
|
responses := make(chan ZgChainMsgResponse)
|
||||||
go func() {
|
go func() {
|
||||||
// wait until account is loaded to start signing
|
// wait until account is loaded to start signing
|
||||||
account := <-accountState
|
account := <-accountState
|
||||||
// store current request waiting to be broadcasted
|
// store current request waiting to be broadcasted
|
||||||
var currentRequest *KavaMsgRequest
|
var currentRequest *ZgChainMsgRequest
|
||||||
// keep track of all successfully broadcasted txs
|
// keep track of all successfully broadcasted txs
|
||||||
// index is sequence % inflightTxLimit
|
// index is sequence % inflightTxLimit
|
||||||
inflight := make([]*KavaMsgResponse, s.inflightTxLimit)
|
inflight := make([]*ZgChainMsgResponse, s.inflightTxLimit)
|
||||||
// used for confirming sent txs only
|
// used for confirming sent txs only
|
||||||
prevDeliverTxSeq := account.GetSequence()
|
prevDeliverTxSeq := account.GetSequence()
|
||||||
// tx sequence of already signed messages
|
// tx sequence of already signed messages
|
||||||
@ -252,7 +252,7 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
|||||||
|
|
||||||
tx, txBytes, err := Sign(s.encodingConfig.TxConfig, s.privKey, txBuilder, signerData)
|
tx, txBytes, err := Sign(s.encodingConfig.TxConfig, s.privKey, txBuilder, signerData)
|
||||||
|
|
||||||
response = &KavaMsgResponse{
|
response = &ZgChainMsgResponse{
|
||||||
Request: *currentRequest,
|
Request: *currentRequest,
|
||||||
Tx: tx,
|
Tx: tx,
|
||||||
TxBytes: txBytes,
|
TxBytes: txBytes,
|
||||||
@ -376,7 +376,7 @@ func (s *KavaSigner) Run(requests <-chan KavaMsgRequest) (<-chan KavaMsgResponse
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Address returns the address of the Signer
|
// Address returns the address of the Signer
|
||||||
func (s *KavaSigner) Address() sdk.AccAddress {
|
func (s *ZgChainSigner) Address() sdk.AccAddress {
|
||||||
return GetAccAddress(s.privKey)
|
return GetAccAddress(s.privKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,12 +46,12 @@ func ParseOrQueryConversionPairAddress(
|
|||||||
|
|
||||||
if err := sdk.ValidateDenom(addrOrDenom); err != nil {
|
if err := sdk.ValidateDenom(addrOrDenom); err != nil {
|
||||||
return common.Address{}, fmt.Errorf(
|
return common.Address{}, fmt.Errorf(
|
||||||
"Kava ERC20 '%s' is not a valid hex address or denom",
|
"0gChain ERC20 '%s' is not a valid hex address or denom",
|
||||||
addrOrDenom,
|
addrOrDenom,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Valid denom, try looking up as denom to get corresponding Kava ERC20 address
|
// Valid denom, try looking up as denom to get corresponding 0gChain ERC20 address
|
||||||
paramsRes, err := queryClient.Params(
|
paramsRes, err := queryClient.Params(
|
||||||
context.Background(),
|
context.Background(),
|
||||||
&types.QueryParamsRequest{},
|
&types.QueryParamsRequest{},
|
||||||
@ -67,7 +67,7 @@ func ParseOrQueryConversionPairAddress(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return common.Address{}, fmt.Errorf(
|
return common.Address{}, fmt.Errorf(
|
||||||
"Kava ERC20 '%s' is not a valid hex address or denom (did not match any denoms in queried enabled conversion pairs)",
|
"0gChain ERC20 '%s' is not a valid hex address or denom (did not match any denoms in queried enabled conversion pairs)",
|
||||||
addrOrDenom,
|
addrOrDenom,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ func GetTxCmd() *cobra.Command {
|
|||||||
|
|
||||||
func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "convert-evm-erc20-from-coin [Kava EVM address] [coin]",
|
Use: "convert-evm-erc20-from-coin [0gChain EVM address] [coin]",
|
||||||
Short: "EVM-native asset: converts a coin on Cosmos co-chain to an ERC20 on EVM co-chain",
|
Short: "EVM-native asset: converts a coin on Cosmos co-chain to an ERC20 on EVM co-chain",
|
||||||
Example: fmt.Sprintf(
|
Example: fmt.Sprintf(
|
||||||
`%s tx %s convert-evm-erc20-from-coin 0x7Bbf300890857b8c241b219C6a489431669b3aFA 500000000erc20/usdc --from <key> --gas 2000000`,
|
`%s tx %s convert-evm-erc20-from-coin 0x7Bbf300890857b8c241b219C6a489431669b3aFA 500000000erc20/usdc --from <key> --gas 2000000`,
|
||||||
@ -81,10 +81,10 @@ func getCmdConvertEvmERC20FromCoin() *cobra.Command {
|
|||||||
|
|
||||||
func getCmdConvertEvmERC20ToCoin() *cobra.Command {
|
func getCmdConvertEvmERC20ToCoin() *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "convert-evm-erc20-to-coin [Kava receiver address] [Kava ERC20 address] [amount]",
|
Use: "convert-evm-erc20-to-coin [0gChain receiver address] [0gChain ERC20 address] [amount]",
|
||||||
Short: "EVM-native asset: converts an ERC20 on EVM co-chain to a coin on Cosmos co-chain",
|
Short: "EVM-native asset: converts an ERC20 on EVM co-chain to a coin on Cosmos co-chain",
|
||||||
Example: fmt.Sprintf(`
|
Example: fmt.Sprintf(`
|
||||||
%[1]s tx %[2]s convert-evm-erc20-to-coin kava10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t 0xeA7100edA2f805356291B0E55DaD448599a72C6d 1000000000000000 --from <key> --gas 1000000
|
%[1]s tx %[2]s convert-evm-erc20-to-coin 0g10wlnqzyss4accfqmyxwx5jy5x9nfkwh6qm7n4t 0xeA7100edA2f805356291B0E55DaD448599a72C6d 1000000000000000 --from <key> --gas 1000000
|
||||||
`, version.AppName, types.ModuleName,
|
`, version.AppName, types.ModuleName,
|
||||||
),
|
),
|
||||||
Args: cobra.ExactArgs(3),
|
Args: cobra.ExactArgs(3),
|
||||||
@ -163,11 +163,11 @@ func getCmdMsgConvertCosmosCoinToERC20() *cobra.Command {
|
|||||||
|
|
||||||
func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "convert-cosmos-coin-from-erc20 [receiver_kava_address] [amount] [flags]",
|
Use: "convert-cosmos-coin-from-erc20 [receiver_0g_address] [amount] [flags]",
|
||||||
Short: "Cosmos-native asset: converts an ERC20 on EVM co-chain back to a coin on Cosmos co-chain",
|
Short: "Cosmos-native asset: converts an ERC20 on EVM co-chain back to a coin on Cosmos co-chain",
|
||||||
Example: fmt.Sprintf(
|
Example: fmt.Sprintf(
|
||||||
`Convert ERC20 representation of 500 ATOM back to a Cosmos coin, sending to kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a:
|
`Convert ERC20 representation of 500 ATOM back to a Cosmos coin, sending to 0g1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a:
|
||||||
%s tx %s convert-cosmos-coin-from-erc20 kava1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a 500000000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 --from <key> --gas 2000000`,
|
%s tx %s convert-cosmos-coin-from-erc20 0g1q0dkky0505r555etn6u2nz4h4kjcg5y8dg863a 500000000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 --from <key> --gas 2000000`,
|
||||||
version.AppName, types.ModuleName,
|
version.AppName, types.ModuleName,
|
||||||
),
|
),
|
||||||
Args: cobra.ExactArgs(2),
|
Args: cobra.ExactArgs(2),
|
||||||
@ -179,7 +179,7 @@ func getCmdMsgConvertCosmosCoinFromERC20() *cobra.Command {
|
|||||||
|
|
||||||
receiver, err := sdk.AccAddressFromBech32(args[0])
|
receiver, err := sdk.AccAddressFromBech32(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("receiver '%s' is an invalid kava address", args[0])
|
return fmt.Errorf("receiver '%s' is an invalid 0g-chain address", args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
amount, err := sdk.ParseCoinNormalized(args[1])
|
amount, err := sdk.ParseCoinNormalized(args[1])
|
||||||
|
@ -98,7 +98,7 @@ func (s *genesisTestSuite) TestExportGenesis() {
|
|||||||
params.AllowedCosmosDenoms = []types.AllowedCosmosCoinERC20Token{
|
params.AllowedCosmosDenoms = []types.AllowedCosmosCoinERC20Token{
|
||||||
{
|
{
|
||||||
CosmosDenom: "hard",
|
CosmosDenom: "hard",
|
||||||
Name: "Kava EVM HARD",
|
Name: "0gChain EVM HARD",
|
||||||
Symbol: "HARD",
|
Symbol: "HARD",
|
||||||
Decimals: 6,
|
Decimals: 6,
|
||||||
},
|
},
|
||||||
|
@ -9,56 +9,49 @@ import (
|
|||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
// ConversionMultiplier is the conversion multiplier between neuron and a0gi
|
||||||
// EvmDenom is the gas denom used by the evm
|
var ConversionMultiplier = sdkmath.NewInt(chaincfg.ConversionMultiplier)
|
||||||
EvmDenom = "akava"
|
|
||||||
|
|
||||||
// CosmosDenom is the gas denom used by the kava app
|
|
||||||
CosmosDenom = "ukava"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ConversionMultiplier is the conversion multiplier between akava and ukava
|
|
||||||
var ConversionMultiplier = sdkmath.NewInt(1_000_000_000_000)
|
|
||||||
|
|
||||||
var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
var _ evmtypes.BankKeeper = EvmBankKeeper{}
|
||||||
|
|
||||||
// EvmBankKeeper is a BankKeeper wrapper for the x/evm module to allow the use
|
// EvmBankKeeper is a BankKeeper wrapper for the x/evm module to allow the use
|
||||||
// of the 18 decimal akava coin on the evm.
|
// of the 18 decimal neuron coin on the evm.
|
||||||
// x/evm consumes gas and send coins by minting and burning akava coins in its module
|
// x/evm consumes gas and send coins by minting and burning neuron coins in its module
|
||||||
// account and then sending the funds to the target account.
|
// account and then sending the funds to the target account.
|
||||||
// This keeper uses both the ukava coin and a separate akava balance to manage the
|
// This keeper uses both the a0gi coin and a separate neuron balance to manage the
|
||||||
// extra percision needed by the evm.
|
// extra percision needed by the evm.
|
||||||
type EvmBankKeeper struct {
|
type EvmBankKeeper struct {
|
||||||
akavaKeeper Keeper
|
baseKeeper Keeper
|
||||||
bk types.BankKeeper
|
bk types.BankKeeper
|
||||||
ak types.AccountKeeper
|
ak types.AccountKeeper
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEvmBankKeeper(akavaKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
func NewEvmBankKeeper(baseKeeper Keeper, bk types.BankKeeper, ak types.AccountKeeper) EvmBankKeeper {
|
||||||
return EvmBankKeeper{
|
return EvmBankKeeper{
|
||||||
akavaKeeper: akavaKeeper,
|
baseKeeper: baseKeeper,
|
||||||
bk: bk,
|
bk: bk,
|
||||||
ak: ak,
|
ak: ak,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBalance returns the total **spendable** balance of akava for a given account by address.
|
// GetBalance returns the total **spendable** balance of neuron for a given account by address.
|
||||||
func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
func (k EvmBankKeeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
|
||||||
if denom != EvmDenom {
|
if denom != chaincfg.BaseDenom {
|
||||||
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", EvmDenom))
|
panic(fmt.Errorf("only evm denom %s is supported by EvmBankKeeper", chaincfg.BaseDenom))
|
||||||
}
|
}
|
||||||
|
|
||||||
spendableCoins := k.bk.SpendableCoins(ctx, addr)
|
spendableCoins := k.bk.SpendableCoins(ctx, addr)
|
||||||
ukava := spendableCoins.AmountOf(CosmosDenom)
|
a0gi := spendableCoins.AmountOf(chaincfg.DisplayDenom)
|
||||||
akava := k.akavaKeeper.GetBalance(ctx, addr)
|
neuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||||
total := ukava.Mul(ConversionMultiplier).Add(akava)
|
total := a0gi.Mul(ConversionMultiplier).Add(neuron)
|
||||||
return sdk.NewCoin(EvmDenom, total)
|
return sdk.NewCoin(chaincfg.BaseDenom, total)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCoins transfers akava coins from a AccAddress to an AccAddress.
|
// SendCoins transfers neuron coins from a AccAddress to an AccAddress.
|
||||||
func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
||||||
// SendCoins method is not used by the evm module, but is required by the
|
// SendCoins method is not used by the evm module, but is required by the
|
||||||
// evmtypes.BankKeeper interface. This must be updated if the evm module
|
// evmtypes.BankKeeper interface. This must be updated if the evm module
|
||||||
@ -66,101 +59,101 @@ func (k EvmBankKeeper) SendCoins(ctx sdk.Context, senderAddr sdk.AccAddress, rec
|
|||||||
panic("not implemented")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCoinsFromModuleToAccount transfers akava coins from a ModuleAccount to an AccAddress.
|
// SendCoinsFromModuleToAccount transfers neuron coins from a ModuleAccount to an AccAddress.
|
||||||
// It will panic if the module account does not exist. An error is returned if the recipient
|
// It will panic if the module account does not exist. An error is returned if the recipient
|
||||||
// address is black-listed or if sending the tokens fails.
|
// address is black-listed or if sending the tokens fails.
|
||||||
func (k EvmBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
func (k EvmBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error {
|
||||||
ukava, akava, err := SplitAkavaCoins(amt)
|
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ukava.Amount.IsPositive() {
|
if a0gi.Amount.IsPositive() {
|
||||||
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.SendCoinsFromModuleToAccount(ctx, senderModule, recipientAddr, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
senderAddr := k.GetModuleAddress(senderModule)
|
senderAddr := k.GetModuleAddress(senderModule)
|
||||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, senderAddr, akava); err != nil {
|
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuron); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := k.akavaKeeper.SendBalance(ctx, senderAddr, recipientAddr, akava); err != nil {
|
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuron); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendCoinsFromAccountToModule transfers akava coins from an AccAddress to a ModuleAccount.
|
// SendCoinsFromAccountToModule transfers neuron coins from an AccAddress to a ModuleAccount.
|
||||||
// It will panic if the module account does not exist.
|
// It will panic if the module account does not exist.
|
||||||
func (k EvmBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error {
|
func (k EvmBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error {
|
||||||
ukava, akavaNeeded, err := SplitAkavaCoins(amt)
|
a0gi, neuronNeeded, err := SplitNeuronCoins(amt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.SendCoinsFromAccountToModule(ctx, senderAddr, recipientModule, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, senderAddr, akavaNeeded); err != nil {
|
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, senderAddr, neuronNeeded); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
recipientAddr := k.GetModuleAddress(recipientModule)
|
recipientAddr := k.GetModuleAddress(recipientModule)
|
||||||
if err := k.akavaKeeper.SendBalance(ctx, senderAddr, recipientAddr, akavaNeeded); err != nil {
|
if err := k.baseKeeper.SendBalance(ctx, senderAddr, recipientAddr, neuronNeeded); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MintCoins mints akava coins by minting the equivalent ukava coins and any remaining akava coins.
|
// MintCoins mints neuron coins by minting the equivalent a0gi coins and any remaining neuron coins.
|
||||||
// It will panic if the module account does not exist or is unauthorized.
|
// It will panic if the module account does not exist or is unauthorized.
|
||||||
func (k EvmBankKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
func (k EvmBankKeeper) MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
||||||
ukava, akava, err := SplitAkavaCoins(amt)
|
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.MintCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
recipientAddr := k.GetModuleAddress(moduleName)
|
recipientAddr := k.GetModuleAddress(moduleName)
|
||||||
if err := k.akavaKeeper.AddBalance(ctx, recipientAddr, akava); err != nil {
|
if err := k.baseKeeper.AddBalance(ctx, recipientAddr, neuron); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return k.ConvertAkavaToUkava(ctx, recipientAddr)
|
return k.ConvertNeuronToA0gi(ctx, recipientAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BurnCoins burns akava coins by burning the equivalent ukava coins and any remaining akava coins.
|
// BurnCoins burns neuron coins by burning the equivalent a0gi coins and any remaining neuron coins.
|
||||||
// It will panic if the module account does not exist or is unauthorized.
|
// It will panic if the module account does not exist or is unauthorized.
|
||||||
func (k EvmBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
func (k EvmBankKeeper) BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error {
|
||||||
ukava, akava, err := SplitAkavaCoins(amt)
|
a0gi, neuron, err := SplitNeuronCoins(amt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.BurnCoins(ctx, moduleName, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
moduleAddr := k.GetModuleAddress(moduleName)
|
moduleAddr := k.GetModuleAddress(moduleName)
|
||||||
if err := k.ConvertOneUkavaToAkavaIfNeeded(ctx, moduleAddr, akava); err != nil {
|
if err := k.ConvertOneA0giToNeuronIfNeeded(ctx, moduleAddr, neuron); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return k.akavaKeeper.RemoveBalance(ctx, moduleAddr, akava)
|
return k.baseKeeper.RemoveBalance(ctx, moduleAddr, neuron)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsSendEnabledCoins checks the coins provided and returns an ErrSendDisabled
|
// 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")
|
panic("not implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertOneUkavaToAkavaIfNeeded converts 1 ukava to akava for an address if
|
// ConvertOneA0giToNeuronIfNeeded converts 1 a0gi to neuron for an address if
|
||||||
// its akava balance is smaller than the akavaNeeded amount.
|
// its neuron balance is smaller than the neuronNeeded amount.
|
||||||
func (k EvmBankKeeper) ConvertOneUkavaToAkavaIfNeeded(ctx sdk.Context, addr sdk.AccAddress, akavaNeeded sdkmath.Int) error {
|
func (k EvmBankKeeper) ConvertOneA0giToNeuronIfNeeded(ctx sdk.Context, addr sdk.AccAddress, neuronNeeded sdkmath.Int) error {
|
||||||
akavaBal := k.akavaKeeper.GetBalance(ctx, addr)
|
neuronBal := k.baseKeeper.GetBalance(ctx, addr)
|
||||||
if akavaBal.GTE(akavaNeeded) {
|
if neuronBal.GTE(neuronNeeded) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ukavaToStore := sdk.NewCoins(sdk.NewCoin(CosmosDenom, sdk.OneInt()))
|
a0giToStore := sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdk.OneInt()))
|
||||||
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, ukavaToStore); err != nil {
|
if err := k.bk.SendCoinsFromAccountToModule(ctx, addr, types.ModuleName, a0giToStore); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// add 1ukava equivalent of akava to addr
|
// add 1a0gi equivalent of neuron to addr
|
||||||
akavaToReceive := ConversionMultiplier
|
neuronToReceive := ConversionMultiplier
|
||||||
if err := k.akavaKeeper.AddBalance(ctx, addr, akavaToReceive); err != nil {
|
if err := k.baseKeeper.AddBalance(ctx, addr, neuronToReceive); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertAkavaToUkava converts all available akava to ukava for a given AccAddress.
|
// ConvertNeuronToA0gi converts all available neuron to a0gi for a given AccAddress.
|
||||||
func (k EvmBankKeeper) ConvertAkavaToUkava(ctx sdk.Context, addr sdk.AccAddress) error {
|
func (k EvmBankKeeper) ConvertNeuronToA0gi(ctx sdk.Context, addr sdk.AccAddress) error {
|
||||||
totalAkava := k.akavaKeeper.GetBalance(ctx, addr)
|
totalNeuron := k.baseKeeper.GetBalance(ctx, addr)
|
||||||
ukava, _, err := SplitAkavaCoins(sdk.NewCoins(sdk.NewCoin(EvmDenom, totalAkava)))
|
a0gi, _, err := SplitNeuronCoins(sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, totalNeuron)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// do nothing if account does not have enough akava for a single ukava
|
// do nothing if account does not have enough neuron for a single a0gi
|
||||||
ukavaToReceive := ukava.Amount
|
a0giToReceive := a0gi.Amount
|
||||||
if !ukavaToReceive.IsPositive() {
|
if !a0giToReceive.IsPositive() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove akava used for converting to ukava
|
// remove neuron used for converting to a0gi
|
||||||
akavaToBurn := ukavaToReceive.Mul(ConversionMultiplier)
|
neuronToBurn := a0giToReceive.Mul(ConversionMultiplier)
|
||||||
finalBal := totalAkava.Sub(akavaToBurn)
|
finalBal := totalNeuron.Sub(neuronToBurn)
|
||||||
if err := k.akavaKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
if err := k.baseKeeper.SetBalance(ctx, addr, finalBal); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fromAddr := k.GetModuleAddress(types.ModuleName)
|
fromAddr := k.GetModuleAddress(types.ModuleName)
|
||||||
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(ukava)); err != nil {
|
if err := k.bk.SendCoins(ctx, fromAddr, addr, sdk.NewCoins(a0gi)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,35 +225,35 @@ func (k EvmBankKeeper) GetModuleAddress(moduleName string) sdk.AccAddress {
|
|||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
// SplitAkavaCoins splits akava coins to the equivalent ukava coins and any remaining akava balance.
|
// SplitNeuronCoins splits neuron coins to the equivalent a0gi coins and any remaining neuron balance.
|
||||||
// An error will be returned if the coins are not valid or if the coins are not the akava denom.
|
// An error will be returned if the coins are not valid or if the coins are not the neuron denom.
|
||||||
func SplitAkavaCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
func SplitNeuronCoins(coins sdk.Coins) (sdk.Coin, sdkmath.Int, error) {
|
||||||
akava := sdk.ZeroInt()
|
neuron := sdk.ZeroInt()
|
||||||
ukava := sdk.NewCoin(CosmosDenom, sdk.ZeroInt())
|
a0gi := sdk.NewCoin(chaincfg.DisplayDenom, sdk.ZeroInt())
|
||||||
|
|
||||||
if len(coins) == 0 {
|
if len(coins) == 0 {
|
||||||
return ukava, akava, nil
|
return a0gi, neuron, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ValidateEvmCoins(coins); err != nil {
|
if err := ValidateEvmCoins(coins); err != nil {
|
||||||
return ukava, akava, err
|
return a0gi, neuron, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate.
|
// note: we should always have len(coins) == 1 here since coins cannot have dup denoms after we validate.
|
||||||
coin := coins[0]
|
coin := coins[0]
|
||||||
remainingBalance := coin.Amount.Mod(ConversionMultiplier)
|
remainingBalance := coin.Amount.Mod(ConversionMultiplier)
|
||||||
if remainingBalance.IsPositive() {
|
if remainingBalance.IsPositive() {
|
||||||
akava = remainingBalance
|
neuron = remainingBalance
|
||||||
}
|
}
|
||||||
ukavaAmount := coin.Amount.Quo(ConversionMultiplier)
|
a0giAmount := coin.Amount.Quo(ConversionMultiplier)
|
||||||
if ukavaAmount.IsPositive() {
|
if a0giAmount.IsPositive() {
|
||||||
ukava = sdk.NewCoin(CosmosDenom, ukavaAmount)
|
a0gi = sdk.NewCoin(chaincfg.DisplayDenom, a0giAmount)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ukava, akava, nil
|
return a0gi, neuron, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateEvmCoins validates the coins from evm is valid and is the EvmDenom (akava).
|
// ValidateEvmCoins validates the coins from evm is valid and is the chaincfg.BaseDenom (neuron).
|
||||||
func ValidateEvmCoins(coins sdk.Coins) error {
|
func ValidateEvmCoins(coins sdk.Coins) error {
|
||||||
if len(coins) == 0 {
|
if len(coins) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@ -271,9 +264,9 @@ func ValidateEvmCoins(coins sdk.Coins) error {
|
|||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
|
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, coins.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate that coin denom is akava
|
// validate that coin denom is neuron
|
||||||
if len(coins) != 1 || coins[0].Denom != EvmDenom {
|
if len(coins) != 1 || coins[0].Denom != chaincfg.BaseDenom {
|
||||||
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", EvmDenom)
|
errMsg := fmt.Sprintf("invalid evm coin denom, only %s is supported", chaincfg.BaseDenom)
|
||||||
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
|
return errorsmod.Wrap(sdkerrors.ErrInvalidCoins, errMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
|
||||||
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
evmtypes "github.com/evmos/ethermint/x/evm/types"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
@ -27,8 +28,8 @@ func (suite *evmBankKeeperTestSuite) SetupTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
||||||
startingCoins := sdk.NewCoins(sdk.NewInt64Coin("ukava", 10))
|
startingCoins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10))
|
||||||
startingAkava := sdkmath.NewInt(100)
|
startingNeuron := sdkmath.NewInt(100)
|
||||||
|
|
||||||
now := tmtime.Now()
|
now := tmtime.Now()
|
||||||
endTime := now.Add(24 * time.Hour)
|
endTime := now.Add(24 * time.Hour)
|
||||||
@ -38,20 +39,20 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance_ReturnsSpendable() {
|
|||||||
|
|
||||||
err := suite.App.FundAccount(suite.Ctx, suite.Addrs[0], startingCoins)
|
err := suite.App.FundAccount(suite.Ctx, suite.Addrs[0], startingCoins)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingAkava)
|
err = suite.Keeper.SetBalance(suite.Ctx, suite.Addrs[0], startingNeuron)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "akava")
|
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||||
suite.Require().Equal(startingAkava, coin.Amount)
|
suite.Require().Equal(startingNeuron, coin.Amount)
|
||||||
|
|
||||||
ctx := suite.Ctx.WithBlockTime(now.Add(12 * time.Hour))
|
ctx := suite.Ctx.WithBlockTime(now.Add(12 * time.Hour))
|
||||||
coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], "akava")
|
coin = suite.EvmBankKeeper.GetBalance(ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||||
suite.Require().Equal(sdkmath.NewIntFromUint64(5_000_000_000_100), coin.Amount)
|
suite.Require().Equal(sdkmath.NewIntFromUint64(5_000_000_000_100), coin.Amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestGetBalance_NotEvmDenom() {
|
func (suite *evmBankKeeperTestSuite) TestGetBalance_NotEvmDenom() {
|
||||||
suite.Require().Panics(func() {
|
suite.Require().Panics(func() {
|
||||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
})
|
})
|
||||||
suite.Require().Panics(func() {
|
suite.Require().Panics(func() {
|
||||||
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "busd")
|
suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "busd")
|
||||||
@ -65,39 +66,39 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
|||||||
expAmount sdkmath.Int
|
expAmount sdkmath.Int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"ukava with akava",
|
"a0gi with neuron",
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 100),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||||
sdk.NewInt64Coin("ukava", 10),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 10),
|
||||||
),
|
),
|
||||||
sdkmath.NewInt(10_000_000_000_100),
|
sdkmath.NewInt(10_000_000_000_100),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"just akava",
|
"just neuron",
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 100),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||||
sdk.NewInt64Coin("busd", 100),
|
sdk.NewInt64Coin("busd", 100),
|
||||||
),
|
),
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"just ukava",
|
"just a0gi",
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("ukava", 10),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 10),
|
||||||
sdk.NewInt64Coin("busd", 100),
|
sdk.NewInt64Coin("busd", 100),
|
||||||
),
|
),
|
||||||
sdkmath.NewInt(10_000_000_000_000),
|
sdkmath.NewInt(10_000_000_000_000),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"no ukava or akava",
|
"no a0gi or neuron",
|
||||||
sdk.NewCoins(),
|
sdk.NewCoins(),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"with avaka that is more than 1 ukava",
|
"with avaka that is more than 1 a0gi",
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 20_000_000_000_220),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 20_000_000_000_220),
|
||||||
sdk.NewInt64Coin("ukava", 11),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 11),
|
||||||
),
|
),
|
||||||
sdkmath.NewInt(31_000_000_000_220),
|
sdkmath.NewInt(31_000_000_000_220),
|
||||||
},
|
},
|
||||||
@ -107,8 +108,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
|||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
|
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingAmount)
|
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAmount)
|
||||||
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "akava")
|
coin := suite.EvmBankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.BaseDenom)
|
||||||
suite.Require().Equal(tt.expAmount, coin.Amount)
|
suite.Require().Equal(tt.expAmount, coin.Amount)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -116,8 +117,8 @@ func (suite *evmBankKeeperTestSuite) TestGetBalance() {
|
|||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
||||||
startingModuleCoins := sdk.NewCoins(
|
startingModuleCoins := sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 200),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||||
sdk.NewInt64Coin("ukava", 100),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||||
)
|
)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -127,102 +128,102 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
|||||||
hasErr bool
|
hasErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"send more than 1 ukava",
|
"send more than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_010)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 10),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 10),
|
||||||
sdk.NewInt64Coin("ukava", 12),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 12),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send less than 1 ukava",
|
"send less than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 122),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 122),
|
||||||
sdk.NewInt64Coin("ukava", 0),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 0),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send an exact amount of ukava",
|
"send an exact amount of a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 0o0),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 0o0),
|
||||||
sdk.NewInt64Coin("ukava", 98),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 98),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send no akava",
|
"send no neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 0),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 0),
|
||||||
sdk.NewInt64Coin("ukava", 0),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 0),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if sending other coins",
|
"errors if sending other coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough total akava to cover",
|
"errors if not enough total neuron to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_001_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough ukava to cover",
|
"errors if not enough a0gi to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts receiver's akava to ukava if there's enough akava after the transfer",
|
"converts receiver's neuron to a0gi if there's enough neuron after the transfer",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_000_000_000_200)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_000_200)),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 999_999_999_900),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 999_999_999_900),
|
||||||
sdk.NewInt64Coin("ukava", 1),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||||
),
|
),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 100),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 100),
|
||||||
sdk.NewInt64Coin("ukava", 101),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 101),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts all of receiver's akava to ukava even if somehow receiver has more than 1ukava of akava",
|
"converts all of receiver's neuron to a0gi even if somehow receiver has more than 1a0gi of neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_100)),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 5_999_999_999_990),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 5_999_999_999_990),
|
||||||
sdk.NewInt64Coin("ukava", 1),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||||
),
|
),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 90),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 90),
|
||||||
sdk.NewInt64Coin("ukava", 19),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 19),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"swap 1 ukava for akava if module account doesn't have enough akava",
|
"swap 1 a0gi for neuron if module account doesn't have enough neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_000_000_001_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_000_000_001_000)),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 200),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||||
sdk.NewInt64Coin("ukava", 1),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 1),
|
||||||
),
|
),
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 1200),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 1200),
|
||||||
sdk.NewInt64Coin("ukava", 100),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||||
),
|
),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
@ -232,11 +233,11 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
|||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
|
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingAccBal)
|
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingAccBal)
|
||||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingModuleCoins)
|
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||||
|
|
||||||
// fund our module with some ukava to account for converting extra akava back to ukava
|
// fund our module with some a0gi to account for converting extra neuron back to a0gi
|
||||||
suite.FundModuleAccountWithKava(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||||
|
|
||||||
err := suite.EvmBankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, evmtypes.ModuleName, suite.Addrs[0], tt.sendCoins)
|
err := suite.EvmBankKeeper.SendCoinsFromModuleToAccount(suite.Ctx, evmtypes.ModuleName, suite.Addrs[0], tt.sendCoins)
|
||||||
if tt.hasErr {
|
if tt.hasErr {
|
||||||
@ -246,24 +247,24 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromModuleToAccount() {
|
|||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check ukava
|
// check a0gi
|
||||||
ukavaSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expAccBal.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||||
|
|
||||||
// check akava
|
// check neuron
|
||||||
actualAkava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().Equal(tt.expAccBal.AmountOf("akava").Int64(), actualAkava.Int64())
|
suite.Require().Equal(tt.expAccBal.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
||||||
startingAccCoins := sdk.NewCoins(
|
startingAccCoins := sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 200),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 200),
|
||||||
sdk.NewInt64Coin("ukava", 100),
|
sdk.NewInt64Coin(chaincfg.DisplayDenom, 100),
|
||||||
)
|
)
|
||||||
startingModuleCoins := sdk.NewCoins(
|
startingModuleCoins := sdk.NewCoins(
|
||||||
sdk.NewInt64Coin("akava", 100_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000),
|
||||||
)
|
)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -273,36 +274,36 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
|||||||
hasErr bool
|
hasErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"send more than 1 ukava",
|
"send more than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_000_000_000_010)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_010)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 190), sdk.NewInt64Coin("ukava", 88)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 190), sdk.NewInt64Coin(chaincfg.DisplayDenom, 88)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_010), sdk.NewInt64Coin("ukava", 12)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_010), sdk.NewInt64Coin(chaincfg.DisplayDenom, 12)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send less than 1 ukava",
|
"send less than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 78), sdk.NewInt64Coin("ukava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 78), sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_122), sdk.NewInt64Coin("ukava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_122), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send an exact amount of ukava",
|
"send an exact amount of a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 2)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 2)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 98)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 98)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"send no akava",
|
"send no neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if sending other coins",
|
"errors if sending other coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
@ -310,39 +311,39 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
|||||||
{
|
{
|
||||||
"errors if have dup coins",
|
"errors if have dup coins",
|
||||||
sdk.Coins{
|
sdk.Coins{
|
||||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||||
},
|
},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough total akava to cover",
|
"errors if not enough total neuron to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_001_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_001_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough ukava to cover",
|
"errors if not enough a0gi to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
sdk.Coins{},
|
sdk.Coins{},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts 1 ukava to akava if not enough akava to cover",
|
"converts 1 a0gi to neuron if not enough neuron to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 99_001_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 99_001_000_000_000)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 999_000_000_200), sdk.NewInt64Coin("ukava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 999_000_000_200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 101_000_000_000), sdk.NewInt64Coin("ukava", 99)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 101_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 99)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts receiver's akava to ukava if there's enough akava after the transfer",
|
"converts receiver's neuron to a0gi if there's enough neuron after the transfer",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 5_900_000_000_200)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_900_000_000_200)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_000_000_000), sdk.NewInt64Coin("ukava", 94)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_000_000_000), sdk.NewInt64Coin(chaincfg.DisplayDenom, 94)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200), sdk.NewInt64Coin("ukava", 6)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200), sdk.NewInt64Coin(chaincfg.DisplayDenom, 6)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -350,8 +351,8 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], startingAccCoins)
|
suite.FundAccountWithZgChain(suite.Addrs[0], startingAccCoins)
|
||||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingModuleCoins)
|
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingModuleCoins)
|
||||||
|
|
||||||
err := suite.EvmBankKeeper.SendCoinsFromAccountToModule(suite.Ctx, suite.Addrs[0], evmtypes.ModuleName, tt.sendCoins)
|
err := suite.EvmBankKeeper.SendCoinsFromAccountToModule(suite.Ctx, suite.Addrs[0], evmtypes.ModuleName, tt.sendCoins)
|
||||||
if tt.hasErr {
|
if tt.hasErr {
|
||||||
@ -362,67 +363,67 @@ func (suite *evmBankKeeperTestSuite) TestSendCoinsFromAccountToModule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check sender balance
|
// check sender balance
|
||||||
ukavaSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
a0giSender := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expSenderCoins.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||||
actualAkava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
actualNeuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().Equal(tt.expSenderCoins.AmountOf("akava").Int64(), actualAkava.Int64())
|
suite.Require().Equal(tt.expSenderCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||||
|
|
||||||
// check module balance
|
// check module balance
|
||||||
moduleAddr := suite.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
|
moduleAddr := suite.AccountKeeper.GetModuleAddress(evmtypes.ModuleName)
|
||||||
ukavaSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, "ukava")
|
a0giSender = suite.BankKeeper.GetBalance(suite.Ctx, moduleAddr, chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expModuleCoins.AmountOf("ukava").Int64(), ukavaSender.Amount.Int64())
|
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.DisplayDenom).Int64(), a0giSender.Amount.Int64())
|
||||||
actualAkava = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
actualNeuron = suite.Keeper.GetBalance(suite.Ctx, moduleAddr)
|
||||||
suite.Require().Equal(tt.expModuleCoins.AmountOf("akava").Int64(), actualAkava.Int64())
|
suite.Require().Equal(tt.expModuleCoins.AmountOf(chaincfg.BaseDenom).Int64(), actualNeuron.Int64())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
||||||
startingUkava := sdkmath.NewInt(100)
|
startingA0gi := sdkmath.NewInt(100)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
burnCoins sdk.Coins
|
burnCoins sdk.Coins
|
||||||
expUkava sdkmath.Int
|
expA0gi sdkmath.Int
|
||||||
expAkava sdkmath.Int
|
expNeuron sdkmath.Int
|
||||||
hasErr bool
|
hasErr bool
|
||||||
akavaStart sdkmath.Int
|
neuronStart sdkmath.Int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"burn more than 1 ukava",
|
"burn more than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||||
sdkmath.NewInt(88),
|
sdkmath.NewInt(88),
|
||||||
sdkmath.NewInt(100_000_000_000),
|
sdkmath.NewInt(100_000_000_000),
|
||||||
false,
|
false,
|
||||||
sdkmath.NewInt(121_000_000_002),
|
sdkmath.NewInt(121_000_000_002),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"burn less than 1 ukava",
|
"burn less than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 122)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 122)),
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
sdkmath.NewInt(878),
|
sdkmath.NewInt(878),
|
||||||
false,
|
false,
|
||||||
sdkmath.NewInt(1000),
|
sdkmath.NewInt(1000),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"burn an exact amount of ukava",
|
"burn an exact amount of a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 98_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 98_000_000_000_000)),
|
||||||
sdkmath.NewInt(2),
|
sdkmath.NewInt(2),
|
||||||
sdkmath.NewInt(10),
|
sdkmath.NewInt(10),
|
||||||
false,
|
false,
|
||||||
sdkmath.NewInt(10),
|
sdkmath.NewInt(10),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"burn no akava",
|
"burn no neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||||
startingUkava,
|
startingA0gi,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
false,
|
false,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if burning other coins",
|
"errors if burning other coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||||
startingUkava,
|
startingA0gi,
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
true,
|
true,
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
@ -430,41 +431,41 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
|||||||
{
|
{
|
||||||
"errors if have dup coins",
|
"errors if have dup coins",
|
||||||
sdk.Coins{
|
sdk.Coins{
|
||||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||||
},
|
},
|
||||||
startingUkava,
|
startingA0gi,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
true,
|
true,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if burn amount is negative",
|
"errors if burn amount is negative",
|
||||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-100)}},
|
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||||
startingUkava,
|
startingA0gi,
|
||||||
sdkmath.NewInt(50),
|
sdkmath.NewInt(50),
|
||||||
true,
|
true,
|
||||||
sdkmath.NewInt(50),
|
sdkmath.NewInt(50),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough akava to cover burn",
|
"errors if not enough neuron to cover burn",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100_999_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100_999_000_000_000)),
|
||||||
sdkmath.NewInt(0),
|
sdkmath.NewInt(0),
|
||||||
sdkmath.NewInt(99_000_000_000),
|
sdkmath.NewInt(99_000_000_000),
|
||||||
true,
|
true,
|
||||||
sdkmath.NewInt(99_000_000_000),
|
sdkmath.NewInt(99_000_000_000),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if not enough ukava to cover burn",
|
"errors if not enough a0gi to cover burn",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 200_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 200_000_000_000_000)),
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
true,
|
true,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts 1 ukava to akava if not enough akava to cover",
|
"converts 1 a0gi to neuron if not enough neuron to cover",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||||
sdkmath.NewInt(87),
|
sdkmath.NewInt(87),
|
||||||
sdkmath.NewInt(980_000_000_000),
|
sdkmath.NewInt(980_000_000_000),
|
||||||
false,
|
false,
|
||||||
@ -476,10 +477,10 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
|||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
startingCoins := sdk.NewCoins(
|
startingCoins := sdk.NewCoins(
|
||||||
sdk.NewCoin("ukava", startingUkava),
|
sdk.NewCoin(chaincfg.DisplayDenom, startingA0gi),
|
||||||
sdk.NewCoin("akava", tt.akavaStart),
|
sdk.NewCoin(chaincfg.BaseDenom, tt.neuronStart),
|
||||||
)
|
)
|
||||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, startingCoins)
|
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, startingCoins)
|
||||||
|
|
||||||
err := suite.EvmBankKeeper.BurnCoins(suite.Ctx, evmtypes.ModuleName, tt.burnCoins)
|
err := suite.EvmBankKeeper.BurnCoins(suite.Ctx, evmtypes.ModuleName, tt.burnCoins)
|
||||||
if tt.hasErr {
|
if tt.hasErr {
|
||||||
@ -489,53 +490,53 @@ func (suite *evmBankKeeperTestSuite) TestBurnCoins() {
|
|||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check ukava
|
// check a0gi
|
||||||
ukavaActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ukava")
|
a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expUkava, ukavaActual.Amount)
|
suite.Require().Equal(tt.expA0gi, a0giActual.Amount)
|
||||||
|
|
||||||
// check akava
|
// check neuron
|
||||||
akavaActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||||
suite.Require().Equal(tt.expAkava, akavaActual)
|
suite.Require().Equal(tt.expNeuron, neuronActual)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
mintCoins sdk.Coins
|
mintCoins sdk.Coins
|
||||||
ukava sdkmath.Int
|
a0gi sdkmath.Int
|
||||||
akava sdkmath.Int
|
neuron sdkmath.Int
|
||||||
hasErr bool
|
hasErr bool
|
||||||
akavaStart sdkmath.Int
|
neuronStart sdkmath.Int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"mint more than 1 ukava",
|
"mint more than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||||
sdkmath.NewInt(12),
|
sdkmath.NewInt(12),
|
||||||
sdkmath.NewInt(21_000_000_002),
|
sdkmath.NewInt(21_000_000_002),
|
||||||
false,
|
false,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mint less than 1 ukava",
|
"mint less than 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 901_000_000_001)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 901_000_000_001)),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
sdkmath.NewInt(901_000_000_001),
|
sdkmath.NewInt(901_000_000_001),
|
||||||
false,
|
false,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mint an exact amount of ukava",
|
"mint an exact amount of a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 123_000_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 123_000_000_000_000_000)),
|
||||||
sdkmath.NewInt(123_000),
|
sdkmath.NewInt(123_000),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
false,
|
false,
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mint no akava",
|
"mint no neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 0)),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
false,
|
false,
|
||||||
@ -543,7 +544,7 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if minting other coins",
|
"errors if minting other coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("busd", 1000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin("busd", 1000)),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
true,
|
true,
|
||||||
@ -552,8 +553,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
{
|
{
|
||||||
"errors if have dup coins",
|
"errors if have dup coins",
|
||||||
sdk.Coins{
|
sdk.Coins{
|
||||||
sdk.NewInt64Coin("akava", 12_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 12_000_000_000_000),
|
||||||
sdk.NewInt64Coin("akava", 2_000_000_000_000),
|
sdk.NewInt64Coin(chaincfg.BaseDenom, 2_000_000_000_000),
|
||||||
},
|
},
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
@ -562,23 +563,23 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"errors if mint amount is negative",
|
"errors if mint amount is negative",
|
||||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-100)}},
|
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-100)}},
|
||||||
sdk.ZeroInt(),
|
sdk.ZeroInt(),
|
||||||
sdkmath.NewInt(50),
|
sdkmath.NewInt(50),
|
||||||
true,
|
true,
|
||||||
sdkmath.NewInt(50),
|
sdkmath.NewInt(50),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"adds to existing akava balance",
|
"adds to existing neuron balance",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 12_021_000_000_002)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 12_021_000_000_002)),
|
||||||
sdkmath.NewInt(12),
|
sdkmath.NewInt(12),
|
||||||
sdkmath.NewInt(21_000_000_102),
|
sdkmath.NewInt(21_000_000_102),
|
||||||
false,
|
false,
|
||||||
sdkmath.NewInt(100),
|
sdkmath.NewInt(100),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"convert akava balance to ukava if it exceeds 1 ukava",
|
"convert neuron balance to a0gi if it exceeds 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_999_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_999_000_000_000)),
|
||||||
sdkmath.NewInt(12),
|
sdkmath.NewInt(12),
|
||||||
sdkmath.NewInt(1_200_000_001),
|
sdkmath.NewInt(1_200_000_001),
|
||||||
false,
|
false,
|
||||||
@ -589,8 +590,8 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
suite.FundModuleAccountWithKava(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
suite.FundModuleAccountWithZgChain(types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||||
suite.FundModuleAccountWithKava(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin("akava", tt.akavaStart)))
|
suite.FundModuleAccountWithZgChain(evmtypes.ModuleName, sdk.NewCoins(sdk.NewCoin(chaincfg.BaseDenom, tt.neuronStart)))
|
||||||
|
|
||||||
err := suite.EvmBankKeeper.MintCoins(suite.Ctx, evmtypes.ModuleName, tt.mintCoins)
|
err := suite.EvmBankKeeper.MintCoins(suite.Ctx, evmtypes.ModuleName, tt.mintCoins)
|
||||||
if tt.hasErr {
|
if tt.hasErr {
|
||||||
@ -600,13 +601,13 @@ func (suite *evmBankKeeperTestSuite) TestMintCoins() {
|
|||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check ukava
|
// check a0gi
|
||||||
ukavaActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, "ukava")
|
a0giActual := suite.BankKeeper.GetBalance(suite.Ctx, suite.EvmModuleAddr, chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.ukava, ukavaActual.Amount)
|
suite.Require().Equal(tt.a0gi, a0giActual.Amount)
|
||||||
|
|
||||||
// check akava
|
// check neuron
|
||||||
akavaActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
neuronActual := suite.Keeper.GetBalance(suite.Ctx, suite.EvmModuleAddr)
|
||||||
suite.Require().Equal(tt.akava, akavaActual)
|
suite.Require().Equal(tt.neuron, neuronActual)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -619,22 +620,22 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"valid coins",
|
"valid coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 500)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 500)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dup coins",
|
"dup coins",
|
||||||
sdk.Coins{sdk.NewInt64Coin("akava", 500), sdk.NewInt64Coin("akava", 500)},
|
sdk.Coins{sdk.NewInt64Coin(chaincfg.BaseDenom, 500), sdk.NewInt64Coin(chaincfg.BaseDenom, 500)},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"not evm coins",
|
"not evm coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 500)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 500)),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"negative coins",
|
"negative coins",
|
||||||
sdk.Coins{sdk.Coin{Denom: "akava", Amount: sdkmath.NewInt(-500)}},
|
sdk.Coins{sdk.Coin{Denom: chaincfg.BaseDenom, Amount: sdkmath.NewInt(-500)}},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -650,8 +651,8 @@ func (suite *evmBankKeeperTestSuite) TestValidateEvmCoins() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
func (suite *evmBankKeeperTestSuite) TestConvertOneA0giToNeuronIfNeeded() {
|
||||||
akavaNeeded := sdkmath.NewInt(200)
|
neuronNeeded := sdkmath.NewInt(200)
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
startingCoins sdk.Coins
|
startingCoins sdk.Coins
|
||||||
@ -659,21 +660,21 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
|||||||
success bool
|
success bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"not enough ukava for conversion",
|
"not enough a0gi for conversion",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts 1 ukava to akava",
|
"converts 1 a0gi to neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 9), sdk.NewInt64Coin("akava", 1_000_000_000_100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 9), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_100)),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"conversion not needed",
|
"conversion not needed",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 200)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 200)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 200)),
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -681,67 +682,67 @@ func (suite *evmBankKeeperTestSuite) TestConvertOneUkavaToAkavaIfNeeded() {
|
|||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
|
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingCoins)
|
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||||
err := suite.EvmBankKeeper.ConvertOneUkavaToAkavaIfNeeded(suite.Ctx, suite.Addrs[0], akavaNeeded)
|
err := suite.EvmBankKeeper.ConvertOneA0giToNeuronIfNeeded(suite.Ctx, suite.Addrs[0], neuronNeeded)
|
||||||
moduleKava := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), "ukava")
|
moduleZgChain := suite.BankKeeper.GetBalance(suite.Ctx, suite.AccountKeeper.GetModuleAddress(types.ModuleName), chaincfg.DisplayDenom)
|
||||||
if tt.success {
|
if tt.success {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
if tt.startingCoins.AmountOf("akava").LT(akavaNeeded) {
|
if tt.startingCoins.AmountOf(chaincfg.BaseDenom).LT(neuronNeeded) {
|
||||||
suite.Require().Equal(sdk.OneInt(), moduleKava.Amount)
|
suite.Require().Equal(sdk.OneInt(), moduleZgChain.Amount)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
suite.Require().Equal(sdk.ZeroInt(), moduleKava.Amount)
|
suite.Require().Equal(sdk.ZeroInt(), moduleZgChain.Amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
akava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||||
ukava := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
a0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestConvertAkavaToUkava() {
|
func (suite *evmBankKeeperTestSuite) TestConvertNeuronToA0gi() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
startingCoins sdk.Coins
|
startingCoins sdk.Coins
|
||||||
expectedCoins sdk.Coins
|
expectedCoins sdk.Coins
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"not enough ukava",
|
"not enough a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 100), sdk.NewInt64Coin("ukava", 0)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 100), sdk.NewInt64Coin(chaincfg.DisplayDenom, 0)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts akava for 1 ukava",
|
"converts neuron for 1 a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 1_000_000_000_003)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 1_000_000_000_003)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 11), sdk.NewInt64Coin("akava", 3)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 11), sdk.NewInt64Coin(chaincfg.BaseDenom, 3)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"converts more than 1 ukava of akava",
|
"converts more than 1 a0gi of neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 10), sdk.NewInt64Coin("akava", 8_000_000_000_123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10), sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 18), sdk.NewInt64Coin("akava", 123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 18), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
|
|
||||||
err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin("ukava", 10)))
|
err := suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 10)))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.FundAccountWithKava(suite.Addrs[0], tt.startingCoins)
|
suite.FundAccountWithZgChain(suite.Addrs[0], tt.startingCoins)
|
||||||
err = suite.EvmBankKeeper.ConvertAkavaToUkava(suite.Ctx, suite.Addrs[0])
|
err = suite.EvmBankKeeper.ConvertNeuronToA0gi(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
akava := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
neuron := suite.Keeper.GetBalance(suite.Ctx, suite.Addrs[0])
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||||
ukava := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], "ukava")
|
a0gi := suite.BankKeeper.GetBalance(suite.Ctx, suite.Addrs[0], chaincfg.DisplayDenom)
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
func (suite *evmBankKeeperTestSuite) TestSplitNeuronCoins() {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
coins sdk.Coins
|
coins sdk.Coins
|
||||||
@ -750,7 +751,7 @@ func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"invalid coins",
|
"invalid coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 500)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 500)),
|
||||||
nil,
|
nil,
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
@ -761,33 +762,33 @@ func (suite *evmBankKeeperTestSuite) TestSplitAkavaCoins() {
|
|||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ukava & akava coins",
|
"a0gi & neuron coins",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 8_000_000_000_123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 8_000_000_000_123)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 8), sdk.NewInt64Coin("akava", 123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 8), sdk.NewInt64Coin(chaincfg.BaseDenom, 123)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"only akava",
|
"only neuron",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 10_123)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 10_123)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"only ukava",
|
"only a0gi",
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("akava", 5_000_000_000_000)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.BaseDenom, 5_000_000_000_000)),
|
||||||
sdk.NewCoins(sdk.NewInt64Coin("ukava", 5)),
|
sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 5)),
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
suite.Run(tt.name, func() {
|
suite.Run(tt.name, func() {
|
||||||
ukava, akava, err := keeper.SplitAkavaCoins(tt.coins)
|
a0gi, neuron, err := keeper.SplitNeuronCoins(tt.coins)
|
||||||
if tt.shouldErr {
|
if tt.shouldErr {
|
||||||
suite.Require().Error(err)
|
suite.Require().Error(err)
|
||||||
} else {
|
} else {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("ukava"), ukava.Amount)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.DisplayDenom), a0gi.Amount)
|
||||||
suite.Require().Equal(tt.expectedCoins.AmountOf("akava"), akava)
|
suite.Require().Equal(tt.expectedCoins.AmountOf(chaincfg.BaseDenom), neuron)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func (suite *convertCosmosCoinToERC20Suite) TestConvertCosmosCoinToERC20() {
|
|||||||
caller, key := testutil.RandomEvmAccount()
|
caller, key := testutil.RandomEvmAccount()
|
||||||
query := func(method string, args ...interface{}) ([]interface{}, error) {
|
query := func(method string, args ...interface{}) ([]interface{}, error) {
|
||||||
return suite.QueryContract(
|
return suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
key,
|
key,
|
||||||
contractAddress,
|
contractAddress,
|
||||||
@ -90,7 +90,7 @@ func (suite *convertCosmosCoinToERC20Suite) TestConvertCosmosCoinToERC20() {
|
|||||||
// make the denom allowed for conversion
|
// make the denom allowed for conversion
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||||
)
|
)
|
||||||
suite.Keeper.SetParams(suite.Ctx, params)
|
suite.Keeper.SetParams(suite.Ctx, params)
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ func (suite *convertCosmosCoinFromERC20Suite) SetupTest() {
|
|||||||
caller, key := testutil.RandomEvmAccount()
|
caller, key := testutil.RandomEvmAccount()
|
||||||
suite.query = func(method string, args ...interface{}) ([]interface{}, error) {
|
suite.query = func(method string, args ...interface{}) ([]interface{}, error) {
|
||||||
return suite.QueryContract(
|
return suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
key,
|
key,
|
||||||
suite.contractAddress,
|
suite.contractAddress,
|
||||||
|
@ -43,7 +43,7 @@ func (suite *Bep3ConversionTestSuite) setEnabledConversionPairDenom(denom string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *Bep3ConversionTestSuite) testConvertBep3CoinToERC20(denom string) {
|
func (suite *Bep3ConversionTestSuite) testConvertBep3CoinToERC20(denom string) {
|
||||||
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
invoker, err := sdk.AccAddressFromBech32("0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||||
receiverAddr := testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
|
receiverAddr := testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
|
@ -68,10 +68,10 @@ func (k Keeper) DeployTestMintableERC20Contract(
|
|||||||
return types.NewInternalEVMAddress(contractAddr), nil
|
return types.NewInternalEVMAddress(contractAddr), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeployKavaWrappedCosmosCoinERC20Contract validates token details and then deploys an ERC20
|
// DeployZgChainWrappedCosmosCoinERC20Contract validates token details and then deploys an ERC20
|
||||||
// contract with the token metadata.
|
// contract with the token metadata.
|
||||||
// This method does NOT check if a token for the provided SdkDenom has already been deployed.
|
// This method does NOT check if a token for the provided SdkDenom has already been deployed.
|
||||||
func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
func (k Keeper) DeployZgChainWrappedCosmosCoinERC20Contract(
|
||||||
ctx sdk.Context,
|
ctx sdk.Context,
|
||||||
token types.AllowedCosmosCoinERC20Token,
|
token types.AllowedCosmosCoinERC20Token,
|
||||||
) (types.InternalEVMAddress, error) {
|
) (types.InternalEVMAddress, error) {
|
||||||
@ -79,7 +79,7 @@ func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
|||||||
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to deploy erc20 for sdk denom %s", token.CosmosDenom)
|
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to deploy erc20 for sdk denom %s", token.CosmosDenom)
|
||||||
}
|
}
|
||||||
|
|
||||||
packedAbi, err := types.ERC20KavaWrappedCosmosCoinContract.ABI.Pack(
|
packedAbi, err := types.ERC20ZgChainWrappedCosmosCoinContract.ABI.Pack(
|
||||||
"", // Empty string for contract constructor
|
"", // Empty string for contract constructor
|
||||||
token.Name,
|
token.Name,
|
||||||
token.Symbol,
|
token.Symbol,
|
||||||
@ -89,13 +89,13 @@ func (k Keeper) DeployKavaWrappedCosmosCoinERC20Contract(
|
|||||||
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to pack token with details %+v", token)
|
return types.InternalEVMAddress{}, errorsmod.Wrapf(err, "failed to pack token with details %+v", token)
|
||||||
}
|
}
|
||||||
|
|
||||||
data := make([]byte, len(types.ERC20KavaWrappedCosmosCoinContract.Bin)+len(packedAbi))
|
data := make([]byte, len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin)+len(packedAbi))
|
||||||
copy(
|
copy(
|
||||||
data[:len(types.ERC20KavaWrappedCosmosCoinContract.Bin)],
|
data[:len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin)],
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.Bin,
|
types.ERC20ZgChainWrappedCosmosCoinContract.Bin,
|
||||||
)
|
)
|
||||||
copy(
|
copy(
|
||||||
data[len(types.ERC20KavaWrappedCosmosCoinContract.Bin):],
|
data[len(types.ERC20ZgChainWrappedCosmosCoinContract.Bin):],
|
||||||
packedAbi,
|
packedAbi,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ func (k *Keeper) GetOrDeployCosmosCoinERC20Contract(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// deploy a new contract
|
// deploy a new contract
|
||||||
contractAddress, err := k.DeployKavaWrappedCosmosCoinERC20Contract(ctx, tokenInfo)
|
contractAddress, err := k.DeployZgChainWrappedCosmosCoinERC20Contract(ctx, tokenInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return contractAddress, err
|
return contractAddress, err
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ func (k Keeper) BurnERC20(
|
|||||||
) error {
|
) error {
|
||||||
_, err := k.CallEVM(
|
_, err := k.CallEVM(
|
||||||
ctx,
|
ctx,
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
types.ModuleEVMAddress,
|
types.ModuleEVMAddress,
|
||||||
contractAddr,
|
contractAddr,
|
||||||
erc20BurnMethod,
|
erc20BurnMethod,
|
||||||
@ -213,7 +213,7 @@ func (k Keeper) QueryERC20TotalSupply(
|
|||||||
) (*big.Int, error) {
|
) (*big.Int, error) {
|
||||||
res, err := k.CallEVM(
|
res, err := k.CallEVM(
|
||||||
ctx,
|
ctx,
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
types.ModuleEVMAddress,
|
types.ModuleEVMAddress,
|
||||||
contractAddr,
|
contractAddr,
|
||||||
erc20TotalSupplyMethod,
|
erc20TotalSupplyMethod,
|
||||||
|
@ -107,11 +107,11 @@ func (suite *ERC20TestSuite) TestQueryERC20TotalSupply() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ERC20TestSuite) TestDeployKavaWrappedCosmosCoinERC20Contract() {
|
func (suite *ERC20TestSuite) TestDeployZgChainWrappedCosmosCoinERC20Contract() {
|
||||||
suite.Run("fails to deploy invalid contract", func() {
|
suite.Run("fails to deploy invalid contract", func() {
|
||||||
// empty other fields means this token is invalid.
|
// empty other fields means this token is invalid.
|
||||||
invalidToken := types.AllowedCosmosCoinERC20Token{CosmosDenom: "nope"}
|
invalidToken := types.AllowedCosmosCoinERC20Token{CosmosDenom: "nope"}
|
||||||
_, err := suite.Keeper.DeployKavaWrappedCosmosCoinERC20Contract(suite.Ctx, invalidToken)
|
_, err := suite.Keeper.DeployZgChainWrappedCosmosCoinERC20Contract(suite.Ctx, invalidToken)
|
||||||
suite.ErrorContains(err, "token's name cannot be empty")
|
suite.ErrorContains(err, "token's name cannot be empty")
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -119,13 +119,13 @@ func (suite *ERC20TestSuite) TestDeployKavaWrappedCosmosCoinERC20Contract() {
|
|||||||
caller, privKey := testutil.RandomEvmAccount()
|
caller, privKey := testutil.RandomEvmAccount()
|
||||||
|
|
||||||
token := types.NewAllowedCosmosCoinERC20Token("hard", "EVM HARD", "HARD", 6)
|
token := types.NewAllowedCosmosCoinERC20Token("hard", "EVM HARD", "HARD", 6)
|
||||||
addr, err := suite.Keeper.DeployKavaWrappedCosmosCoinERC20Contract(suite.Ctx, token)
|
addr, err := suite.Keeper.DeployZgChainWrappedCosmosCoinERC20Contract(suite.Ctx, token)
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
suite.NotNil(addr)
|
suite.NotNil(addr)
|
||||||
|
|
||||||
callContract := func(method string, args ...interface{}) ([]interface{}, error) {
|
callContract := func(method string, args ...interface{}) ([]interface{}, error) {
|
||||||
return suite.QueryContract(
|
return suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
privKey,
|
privKey,
|
||||||
addr,
|
addr,
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant {
|
|||||||
})
|
})
|
||||||
|
|
||||||
bankAddr := authtypes.NewModuleAddress(types.ModuleName)
|
bankAddr := authtypes.NewModuleAddress(types.ModuleName)
|
||||||
bankBalance := bankK.GetBalance(ctx, bankAddr, CosmosDenom).Amount.Mul(ConversionMultiplier)
|
bankBalance := bankK.GetBalance(ctx, bankAddr, chaincfg.DisplayDenom).Amount.Mul(ConversionMultiplier)
|
||||||
|
|
||||||
broken = totalMinorBalances.GT(bankBalance)
|
broken = totalMinorBalances.GT(bankBalance)
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
@ -46,10 +47,10 @@ func (suite *invariantTestSuite) SetupValidState() {
|
|||||||
keeper.ConversionMultiplier.QuoRaw(2),
|
keeper.ConversionMultiplier.QuoRaw(2),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
suite.FundModuleAccountWithKava(
|
suite.FundModuleAccountWithZgChain(
|
||||||
types.ModuleName,
|
types.ModuleName,
|
||||||
sdk.NewCoins(
|
sdk.NewCoins(
|
||||||
sdk.NewCoin("ukava", sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(2)), // ( sum of all minor balances ) / conversion multiplier
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -159,8 +160,8 @@ func (suite *invariantTestSuite) TestSmallBalances() {
|
|||||||
|
|
||||||
// increase minor balance at least above conversion multiplier
|
// increase minor balance at least above conversion multiplier
|
||||||
suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], keeper.ConversionMultiplier)
|
suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], keeper.ConversionMultiplier)
|
||||||
// add same number of ukava to avoid breaking other invariants
|
// add same number of a0gi to avoid breaking other invariants
|
||||||
amt := sdk.NewCoins(sdk.NewInt64Coin(keeper.CosmosDenom, 1))
|
amt := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1))
|
||||||
suite.Require().NoError(
|
suite.Require().NoError(
|
||||||
suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, amt),
|
suite.App.FundModuleAccount(suite.Ctx, types.ModuleName, amt),
|
||||||
)
|
)
|
||||||
@ -190,7 +191,7 @@ func (suite *invariantTestSuite) TestSendToModuleAccountNotAllowed() {
|
|||||||
ToAddress: maccAddress.String(),
|
ToAddress: maccAddress.String(),
|
||||||
Amount: coins,
|
Amount: coins,
|
||||||
})
|
})
|
||||||
suite.ErrorContains(err, "kava1w9vxuke5dz6hyza2j932qgmxltnfxwl78u920k is not allowed to receive funds: unauthorized")
|
suite.ErrorContains(err, "0g1w9vxuke5dz6hyza2j932qgmxltnfxwl78u920k is not allowed to receive funds: unauthorized")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *invariantTestSuite) TestCosmosCoinsFullyBackedInvariant() {
|
func (suite *invariantTestSuite) TestCosmosCoinsFullyBackedInvariant() {
|
||||||
|
@ -115,7 +115,7 @@ func (k Keeper) SetAccount(ctx sdk.Context, account types.Account) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetBalance returns the total balance of akava for a given account by address.
|
// GetBalance returns the total balance of neuron for a given account by address.
|
||||||
func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
||||||
account := k.GetAccount(ctx, addr)
|
account := k.GetAccount(ctx, addr)
|
||||||
if account == nil {
|
if account == nil {
|
||||||
@ -124,7 +124,7 @@ func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress) sdkmath.Int {
|
|||||||
return account.Balance
|
return account.Balance
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetBalance sets the total balance of akava for a given account by address.
|
// SetBalance sets the total balance of neuron for a given account by address.
|
||||||
func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int) error {
|
func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int) error {
|
||||||
account := k.GetAccount(ctx, addr)
|
account := k.GetAccount(ctx, addr)
|
||||||
if account == nil {
|
if account == nil {
|
||||||
@ -140,10 +140,10 @@ func (k Keeper) SetBalance(ctx sdk.Context, addr sdk.AccAddress, bal sdkmath.Int
|
|||||||
return k.SetAccount(ctx, *account)
|
return k.SetAccount(ctx, *account)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendBalance transfers the akava balance from sender addr to recipient addr.
|
// SendBalance transfers the neuron balance from sender addr to recipient addr.
|
||||||
func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdkmath.Int) error {
|
func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipientAddr sdk.AccAddress, amt sdkmath.Int) error {
|
||||||
if amt.IsNegative() {
|
if amt.IsNegative() {
|
||||||
return fmt.Errorf("cannot send a negative amount of akava: %d", amt)
|
return fmt.Errorf("cannot send a negative amount of neuron: %d", amt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if amt.IsZero() {
|
if amt.IsZero() {
|
||||||
@ -162,13 +162,13 @@ func (k Keeper) SendBalance(ctx sdk.Context, senderAddr sdk.AccAddress, recipien
|
|||||||
return k.SetBalance(ctx, recipientAddr, receiverBal)
|
return k.SetBalance(ctx, recipientAddr, receiverBal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddBalance increments the akava balance of an address.
|
// AddBalance increments the neuron balance of an address.
|
||||||
func (k Keeper) AddBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
func (k Keeper) AddBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
||||||
bal := k.GetBalance(ctx, addr)
|
bal := k.GetBalance(ctx, addr)
|
||||||
return k.SetBalance(ctx, addr, amt.Add(bal))
|
return k.SetBalance(ctx, addr, amt.Add(bal))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveBalance decrements the akava balance of an address.
|
// RemoveBalance decrements the neuron balance of an address.
|
||||||
func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.Int) error {
|
||||||
if amt.IsNegative() {
|
if amt.IsNegative() {
|
||||||
return fmt.Errorf("cannot remove a negative amount from balance: %d", amt)
|
return fmt.Errorf("cannot remove a negative amount from balance: %d", amt)
|
||||||
@ -184,7 +184,7 @@ func (k Keeper) RemoveBalance(ctx sdk.Context, addr sdk.AccAddress, amt sdkmath.
|
|||||||
return k.SetBalance(ctx, addr, finalBal)
|
return k.SetBalance(ctx, addr, finalBal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeployedCosmosCoinContract stores a single deployed ERC20KavaWrappedCosmosCoin contract address
|
// SetDeployedCosmosCoinContract stores a single deployed ERC20ZgChainWrappedCosmosCoin contract address
|
||||||
func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string, contractAddress types.InternalEVMAddress) error {
|
func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string, contractAddress types.InternalEVMAddress) error {
|
||||||
if err := sdk.ValidateDenom(cosmosDenom); err != nil {
|
if err := sdk.ValidateDenom(cosmosDenom); err != nil {
|
||||||
return errorsmod.Wrap(types.ErrInvalidCosmosDenom, cosmosDenom)
|
return errorsmod.Wrap(types.ErrInvalidCosmosDenom, cosmosDenom)
|
||||||
@ -203,7 +203,7 @@ func (k *Keeper) SetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom stri
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetDeployedCosmosCoinContract gets a deployed ERC20KavaWrappedCosmosCoin contract address by cosmos denom
|
// SetDeployedCosmosCoinContract gets a deployed ERC20ZgChainWrappedCosmosCoin contract address by cosmos denom
|
||||||
// Returns the stored address and a bool indicating if it was found or not
|
// Returns the stored address and a bool indicating if it was found or not
|
||||||
func (k *Keeper) GetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string) (types.InternalEVMAddress, bool) {
|
func (k *Keeper) GetDeployedCosmosCoinContract(ctx sdk.Context, cosmosDenom string) (types.InternalEVMAddress, bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
@ -26,7 +26,7 @@ var _ types.MsgServer = msgServer{}
|
|||||||
////////////////////////////
|
////////////////////////////
|
||||||
|
|
||||||
// ConvertCoinToERC20 handles a MsgConvertCoinToERC20 message to convert
|
// ConvertCoinToERC20 handles a MsgConvertCoinToERC20 message to convert
|
||||||
// sdk.Coin to Kava EVM tokens.
|
// sdk.Coin to 0gChain EVM tokens.
|
||||||
func (s msgServer) ConvertCoinToERC20(
|
func (s msgServer) ConvertCoinToERC20(
|
||||||
goCtx context.Context,
|
goCtx context.Context,
|
||||||
msg *types.MsgConvertCoinToERC20,
|
msg *types.MsgConvertCoinToERC20,
|
||||||
@ -64,7 +64,7 @@ func (s msgServer) ConvertCoinToERC20(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConvertERC20ToCoin handles a MsgConvertERC20ToCoin message to convert
|
// ConvertERC20ToCoin handles a MsgConvertERC20ToCoin message to convert
|
||||||
// sdk.Coin to Kava EVM tokens.
|
// sdk.Coin to 0gChain EVM tokens.
|
||||||
func (s msgServer) ConvertERC20ToCoin(
|
func (s msgServer) ConvertERC20ToCoin(
|
||||||
goCtx context.Context,
|
goCtx context.Context,
|
||||||
msg *types.MsgConvertERC20ToCoin,
|
msg *types.MsgConvertERC20ToCoin,
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (suite *MsgServerSuite) TestConvertCoinToERC20_Bep3() {
|
func (suite *MsgServerSuite) TestConvertCoinToERC20_Bep3() {
|
||||||
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
invoker, err := sdk.AccAddressFromBech32("0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||||
receiverAddr := testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
|
receiverAddr := testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ func TestMsgServerSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *MsgServerSuite) TestConvertCoinToERC20() {
|
func (suite *MsgServerSuite) TestConvertCoinToERC20() {
|
||||||
invoker, err := sdk.AccAddressFromBech32("kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
invoker, err := sdk.AccAddressFromBech32("0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz")
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
err = suite.App.FundAccount(suite.Ctx, invoker, sdk.NewCoins(sdk.NewCoin("erc20/usdc", sdkmath.NewInt(10000))))
|
err = suite.App.FundAccount(suite.Ctx, invoker, sdk.NewCoins(sdk.NewCoin("erc20/usdc", sdkmath.NewInt(10000))))
|
||||||
@ -282,7 +282,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
|||||||
// make the denom allowed for conversion
|
// make the denom allowed for conversion
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||||
)
|
)
|
||||||
suite.Keeper.SetParams(suite.Ctx, params)
|
suite.Keeper.SetParams(suite.Ctx, params)
|
||||||
|
|
||||||
@ -331,7 +331,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_InitialContractDeploy(
|
|||||||
{
|
{
|
||||||
name: "invalid - bad initiator",
|
name: "invalid - bad initiator",
|
||||||
msg: types.NewMsgConvertCosmosCoinToERC20(
|
msg: types.NewMsgConvertCosmosCoinToERC20(
|
||||||
"invalid-kava-address",
|
"invalid-0g-address",
|
||||||
testutil.RandomEvmAddress().Hex(),
|
testutil.RandomEvmAddress().Hex(),
|
||||||
sdk.NewInt64Coin(allowedDenom, 1e4),
|
sdk.NewInt64Coin(allowedDenom, 1e4),
|
||||||
),
|
),
|
||||||
@ -452,7 +452,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_AlreadyDeployedContrac
|
|||||||
// make the denom allowed for conversion
|
// make the denom allowed for conversion
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
params.AllowedCosmosDenoms = types.NewAllowedCosmosCoinERC20Tokens(
|
||||||
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "Kava EVM Atom", "ATOM", 6),
|
types.NewAllowedCosmosCoinERC20Token(allowedDenom, "0gChain EVM Atom", "ATOM", 6),
|
||||||
)
|
)
|
||||||
suite.Keeper.SetParams(suite.Ctx, params)
|
suite.Keeper.SetParams(suite.Ctx, params)
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinToERC20_AlreadyDeployedContrac
|
|||||||
// check total supply
|
// check total supply
|
||||||
caller, key := testutil.RandomEvmAccount()
|
caller, key := testutil.RandomEvmAccount()
|
||||||
totalSupply, err := suite.QueryContract(
|
totalSupply, err := suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
key,
|
key,
|
||||||
contractAddress,
|
contractAddress,
|
||||||
@ -639,7 +639,7 @@ func (suite *MsgServerSuite) TestConvertCosmosCoinFromERC20() {
|
|||||||
// expect erc20 total supply to reflect new value
|
// expect erc20 total supply to reflect new value
|
||||||
caller, key := testutil.RandomEvmAccount()
|
caller, key := testutil.RandomEvmAccount()
|
||||||
totalSupply, err := suite.QueryContract(
|
totalSupply, err := suite.QueryContract(
|
||||||
types.ERC20KavaWrappedCosmosCoinContract.ABI,
|
types.ERC20ZgChainWrappedCosmosCoinContract.ABI,
|
||||||
caller,
|
caller,
|
||||||
key,
|
key,
|
||||||
contractAddress,
|
contractAddress,
|
||||||
|
@ -66,9 +66,9 @@ func (suite *keeperTestSuite) TestGetAllowedTokenMetadata() {
|
|||||||
|
|
||||||
atom := types.NewAllowedCosmosCoinERC20Token(
|
atom := types.NewAllowedCosmosCoinERC20Token(
|
||||||
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
|
"ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
|
||||||
"Kava EVM ATOM", "ATOM", 6,
|
"0gChain EVM ATOM", "ATOM", 6,
|
||||||
)
|
)
|
||||||
hard := types.NewAllowedCosmosCoinERC20Token("hard", "Kava EVM Hard", "HARD", 6)
|
hard := types.NewAllowedCosmosCoinERC20Token("hard", "0gChain EVM Hard", "HARD", 6)
|
||||||
|
|
||||||
// init state with some allowed tokens
|
// init state with some allowed tokens
|
||||||
params := suite.Keeper.GetParams(suite.Ctx)
|
params := suite.Keeper.GetParams(suite.Ctx)
|
||||||
|
@ -37,6 +37,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
"github.com/0glabs/0g-chain/x/evmutil/keeper"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
)
|
)
|
||||||
@ -81,14 +82,14 @@ func (suite *Suite) SetupTest() {
|
|||||||
suite.Addrs = addrs
|
suite.Addrs = addrs
|
||||||
|
|
||||||
evmGenesis := evmtypes.DefaultGenesisState()
|
evmGenesis := evmtypes.DefaultGenesisState()
|
||||||
evmGenesis.Params.EvmDenom = "akava"
|
evmGenesis.Params.EvmDenom = chaincfg.BaseDenom
|
||||||
|
|
||||||
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
||||||
feemarketGenesis.Params.EnableHeight = 1
|
feemarketGenesis.Params.EnableHeight = 1
|
||||||
feemarketGenesis.Params.NoBaseFee = false
|
feemarketGenesis.Params.NoBaseFee = false
|
||||||
|
|
||||||
cdc := suite.App.AppCodec()
|
cdc := suite.App.AppCodec()
|
||||||
coins := sdk.NewCoins(sdk.NewInt64Coin("ukava", 1000_000_000_000_000_000))
|
coins := sdk.NewCoins(sdk.NewInt64Coin(chaincfg.DisplayDenom, 1000_000_000_000_000_000))
|
||||||
authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{
|
authGS := app.NewFundedGenStateWithSameCoins(cdc, coins, []sdk.AccAddress{
|
||||||
sdk.AccAddress(suite.Key1.PubKey().Address()),
|
sdk.AccAddress(suite.Key1.PubKey().Address()),
|
||||||
sdk.AccAddress(suite.Key2.PubKey().Address()),
|
sdk.AccAddress(suite.Key2.PubKey().Address()),
|
||||||
@ -184,29 +185,29 @@ func (suite *Suite) ModuleBalance(denom string) sdk.Int {
|
|||||||
return suite.App.GetModuleAccountBalance(suite.Ctx, types.ModuleName, denom)
|
return suite.App.GetModuleAccountBalance(suite.Ctx, types.ModuleName, denom)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *Suite) FundAccountWithKava(addr sdk.AccAddress, coins sdk.Coins) {
|
func (suite *Suite) FundAccountWithZgChain(addr sdk.AccAddress, coins sdk.Coins) {
|
||||||
ukava := coins.AmountOf("ukava")
|
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin("ukava", ukava)))
|
err := suite.App.FundAccount(suite.Ctx, addr, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
akava := coins.AmountOf("akava")
|
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||||
if akava.IsPositive() {
|
if neuron.IsPositive() {
|
||||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, akava)
|
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *Suite) FundModuleAccountWithKava(moduleName string, coins sdk.Coins) {
|
func (suite *Suite) FundModuleAccountWithZgChain(moduleName string, coins sdk.Coins) {
|
||||||
ukava := coins.AmountOf("ukava")
|
a0gi := coins.AmountOf(chaincfg.DisplayDenom)
|
||||||
if ukava.IsPositive() {
|
if a0gi.IsPositive() {
|
||||||
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin("ukava", ukava)))
|
err := suite.App.FundModuleAccount(suite.Ctx, moduleName, sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, a0gi)))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
akava := coins.AmountOf("akava")
|
neuron := coins.AmountOf(chaincfg.BaseDenom)
|
||||||
if akava.IsPositive() {
|
if neuron.IsPositive() {
|
||||||
addr := suite.AccountKeeper.GetModuleAddress(moduleName)
|
addr := suite.AccountKeeper.GetModuleAddress(moduleName)
|
||||||
err := suite.Keeper.SetBalance(suite.Ctx, addr, akava)
|
err := suite.Keeper.SetBalance(suite.Ctx, addr, neuron)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,7 +218,7 @@ func (suite *Suite) DeployERC20() types.InternalEVMAddress {
|
|||||||
suite.App.FundModuleAccount(
|
suite.App.FundModuleAccount(
|
||||||
suite.Ctx,
|
suite.Ctx,
|
||||||
types.ModuleName,
|
types.ModuleName,
|
||||||
sdk.NewCoins(sdk.NewCoin("ukava", sdkmath.NewInt(0))),
|
sdk.NewCoins(sdk.NewCoin(chaincfg.DisplayDenom, sdkmath.NewInt(0))),
|
||||||
)
|
)
|
||||||
|
|
||||||
contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18))
|
contractAddr, err := suite.Keeper.DeployTestMintableERC20Contract(suite.Ctx, "USDC", "USDC", uint8(18))
|
||||||
@ -318,7 +319,7 @@ func (suite *Suite) SendTx(
|
|||||||
// Mint the max gas to the FeeCollector to ensure balance in case of refund
|
// Mint the max gas to the FeeCollector to ensure balance in case of refund
|
||||||
suite.MintFeeCollector(sdk.NewCoins(
|
suite.MintFeeCollector(sdk.NewCoins(
|
||||||
sdk.NewCoin(
|
sdk.NewCoin(
|
||||||
"ukava",
|
chaincfg.DisplayDenom,
|
||||||
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
|
sdkmath.NewInt(baseFee.Int64()*int64(gasRes.Gas*2)),
|
||||||
)))
|
)))
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// InternalEVMAddress is a type alias of common.Address to represent an address
|
// InternalEVMAddress is a type alias of common.Address to represent an address
|
||||||
// on the Kava EVM.
|
// on the 0gChain EVM.
|
||||||
type InternalEVMAddress struct {
|
type InternalEVMAddress struct {
|
||||||
common.Address
|
common.Address
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,11 @@ var (
|
|||||||
// ERC20MintableBurnableAddress is the erc20 module address
|
// ERC20MintableBurnableAddress is the erc20 module address
|
||||||
ERC20MintableBurnableAddress common.Address
|
ERC20MintableBurnableAddress common.Address
|
||||||
|
|
||||||
//go:embed ethermint_json/ERC20KavaWrappedCosmosCoin.json
|
//go:embed ethermint_json/ERC20ZgChainWrappedCosmosCoin.json
|
||||||
ERC20KavaWrappedCosmosCoinJSON []byte
|
ERC20ZgChainWrappedCosmosCoinJSON []byte
|
||||||
|
|
||||||
// ERC20KavaWrappedCosmosCoinContract is the compiled erc20 contract
|
// ERC20ZgChainWrappedCosmosCoinContract is the compiled erc20 contract
|
||||||
ERC20KavaWrappedCosmosCoinContract evmtypes.CompiledContract
|
ERC20ZgChainWrappedCosmosCoinContract evmtypes.CompiledContract
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -53,12 +53,12 @@ func init() {
|
|||||||
panic("loading ERC20MintableBurnable contract failed")
|
panic("loading ERC20MintableBurnable contract failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(ERC20KavaWrappedCosmosCoinJSON, &ERC20KavaWrappedCosmosCoinContract)
|
err = json.Unmarshal(ERC20ZgChainWrappedCosmosCoinJSON, &ERC20ZgChainWrappedCosmosCoinContract)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to unmarshal ERC20KavaWrappedCosmosCoinJSON: %s. %s", err, string(ERC20KavaWrappedCosmosCoinJSON)))
|
panic(fmt.Sprintf("failed to unmarshal ERC20ZgChainWrappedCosmosCoinJSON: %s. %s", err, string(ERC20ZgChainWrappedCosmosCoinJSON)))
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ERC20KavaWrappedCosmosCoinContract.Bin) == 0 {
|
if len(ERC20ZgChainWrappedCosmosCoinContract.Bin) == 0 {
|
||||||
panic("loading ERC20KavaWrappedCosmosCoin contract failed")
|
panic("loading ERC20ZgChainWrappedCosmosCoin contract failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func NewConversionPair(address InternalEVMAddress, denom string) ConversionPair
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAddress returns the InternalEVMAddress of the Kava ERC20 address.
|
// GetAddress returns the InternalEVMAddress of the 0gChain ERC20 address.
|
||||||
func (pair ConversionPair) GetAddress() InternalEVMAddress {
|
func (pair ConversionPair) GetAddress() InternalEVMAddress {
|
||||||
return NewInternalEVMAddress(common.BytesToAddress(pair.ZgchainERC20Address))
|
return NewInternalEVMAddress(common.BytesToAddress(pair.ZgchainERC20Address))
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package types_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -142,7 +143,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
|||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||||
"kava",
|
chaincfg.DisplayDenom,
|
||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
@ -162,7 +163,7 @@ func TestConversionPairs_Validate(t *testing.T) {
|
|||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
testutil.MustNewInternalEVMAddressFromString("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
||||||
"kava",
|
chaincfg.DisplayDenom,
|
||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
@ -183,16 +184,16 @@ func TestConversionPairs_Validate(t *testing.T) {
|
|||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||||
"kava",
|
chaincfg.DisplayDenom,
|
||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
"kava",
|
chaincfg.DisplayDenom,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
errArgs{
|
errArgs{
|
||||||
expectPass: false,
|
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(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
"kava",
|
chaincfg.DisplayDenom,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -240,12 +241,12 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "valid token",
|
name: "valid token",
|
||||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 6),
|
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 6),
|
||||||
expErr: "",
|
expErr: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "valid - highest allowed decimals",
|
name: "valid - highest allowed decimals",
|
||||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 255),
|
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 255),
|
||||||
expErr: "",
|
expErr: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -280,7 +281,7 @@ func TestAllowedCosmosCoinERC20Token_Validate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - decimals higher than uint8",
|
name: "invalid - decimals higher than uint8",
|
||||||
token: types.NewAllowedCosmosCoinERC20Token("uatom", "Kava-wrapped ATOM", "kATOM", 256),
|
token: types.NewAllowedCosmosCoinERC20Token("uatom", "0gChain-wrapped ATOM", "kATOM", 256),
|
||||||
expErr: "decimals must be less than 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 (
|
var (
|
||||||
// AccountStoreKeyPrefix is the prefix for keys that store accounts
|
// AccountStoreKeyPrefix is the prefix for keys that store accounts
|
||||||
AccountStoreKeyPrefix = []byte{0x00}
|
AccountStoreKeyPrefix = []byte{0x00}
|
||||||
// DeployedCosmosCoinContractKeyPrefix is the key for storing deployed KavaWrappedCosmosCoinERC20s contract addresses
|
// DeployedCosmosCoinContractKeyPrefix is the key for storing deployed ZgChainWrappedCosmosCoinERC20s contract addresses
|
||||||
DeployedCosmosCoinContractKeyPrefix = []byte{0x01}
|
DeployedCosmosCoinContractKeyPrefix = []byte{0x01}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
"github.com/0glabs/0g-chain/x/evmutil/testutil"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -13,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMsgConvertCoinToERC20(t *testing.T) {
|
func TestMsgConvertCoinToERC20(t *testing.T) {
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
|
|
||||||
type errArgs struct {
|
type errArgs struct {
|
||||||
expectPass bool
|
expectPass bool
|
||||||
@ -29,7 +30,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"valid",
|
"valid",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -38,7 +39,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"valid-bnb",
|
"valid-bnb",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.NewCoin("bnb", sdkmath.NewInt(1234)),
|
sdk.NewCoin("bnb", sdkmath.NewInt(1234)),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -47,7 +48,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - odd length hex address",
|
"invalid - odd length hex address",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
||||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
sdk.NewCoin("erc20/weth", sdkmath.NewInt(1234)),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -57,7 +58,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - zero amount",
|
"invalid - zero amount",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.NewCoin("erc20/weth", sdkmath.NewInt(0)),
|
sdk.NewCoin("erc20/weth", sdkmath.NewInt(0)),
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -67,7 +68,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - negative amount",
|
"invalid - negative amount",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
// Create manually so there is no validation
|
// Create manually so there is no validation
|
||||||
sdk.Coin{Denom: "erc20/weth", Amount: sdkmath.NewInt(-1234)},
|
sdk.Coin{Denom: "erc20/weth", Amount: sdkmath.NewInt(-1234)},
|
||||||
@ -78,7 +79,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - empty denom",
|
"invalid - empty denom",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.Coin{Denom: "", Amount: sdkmath.NewInt(-1234)},
|
sdk.Coin{Denom: "", Amount: sdkmath.NewInt(-1234)},
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -88,7 +89,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - invalid denom",
|
"invalid - invalid denom",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
sdk.Coin{Denom: "h", Amount: sdkmath.NewInt(-1234)},
|
sdk.Coin{Denom: "h", Amount: sdkmath.NewInt(-1234)},
|
||||||
errArgs{
|
errArgs{
|
||||||
@ -118,7 +119,7 @@ func TestMsgConvertCoinToERC20(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMsgConvertERC20ToCoin(t *testing.T) {
|
func TestMsgConvertERC20ToCoin(t *testing.T) {
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
|
|
||||||
type errArgs struct {
|
type errArgs struct {
|
||||||
expectPass bool
|
expectPass bool
|
||||||
@ -135,7 +136,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"valid",
|
"valid",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
sdkmath.NewInt(1234),
|
sdkmath.NewInt(1234),
|
||||||
@ -145,7 +146,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - odd length hex address",
|
"invalid - odd length hex address",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
sdkmath.NewInt(1234),
|
sdkmath.NewInt(1234),
|
||||||
@ -156,7 +157,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - zero amount",
|
"invalid - zero amount",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
sdkmath.NewInt(0),
|
sdkmath.NewInt(0),
|
||||||
@ -167,7 +168,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - negative amount",
|
"invalid - negative amount",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369e",
|
||||||
sdkmath.NewInt(-1234),
|
sdkmath.NewInt(-1234),
|
||||||
@ -178,7 +179,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"invalid - invalid contract address",
|
"invalid - invalid contract address",
|
||||||
"kava123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
"0g123fxg0l602etulhhcdm0vt7l57qya5wjcrwhzz",
|
||||||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
||||||
"0x404F9466d758eA33eA84CeBE9E444b06533b369",
|
"0x404F9466d758eA33eA84CeBE9E444b06533b369",
|
||||||
sdkmath.NewInt(1234),
|
sdkmath.NewInt(1234),
|
||||||
@ -210,7 +211,7 @@ func TestMsgConvertERC20ToCoin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
||||||
validKavaAddr := app.RandomAddress()
|
validZgChainAddr := app.RandomAddress()
|
||||||
validHexAddr, _ := testutil.RandomEvmAccount()
|
validHexAddr, _ := testutil.RandomEvmAccount()
|
||||||
invalidAddr := "not-an-address"
|
invalidAddr := "not-an-address"
|
||||||
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
||||||
@ -224,14 +225,14 @@ func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: validZgChainAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: validAmount,
|
amount: validAmount,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - sending to kava addr",
|
name: "invalid - sending to 0g addr",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: validZgChainAddr.String(),
|
||||||
receiver: app.RandomAddress().String(),
|
receiver: app.RandomAddress().String(),
|
||||||
amount: validAmount,
|
amount: validAmount,
|
||||||
expectedErr: "receiver is not a valid hex address",
|
expectedErr: "receiver is not a valid hex address",
|
||||||
@ -245,35 +246,35 @@ func TestConvertCosmosCoinToERC20_ValidateBasic(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid receiver",
|
name: "invalid - invalid receiver",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: validZgChainAddr.String(),
|
||||||
receiver: invalidAddr,
|
receiver: invalidAddr,
|
||||||
amount: validAmount,
|
amount: validAmount,
|
||||||
expectedErr: "receiver is not a valid hex address",
|
expectedErr: "receiver is not a valid hex address",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - nil",
|
name: "invalid - invalid amount - nil",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: validZgChainAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: sdk.Coin{},
|
amount: sdk.Coin{},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - zero",
|
name: "invalid - invalid amount - zero",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: validZgChainAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: sdk.NewInt64Coin("magic", 0),
|
amount: sdk.NewInt64Coin("magic", 0),
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - negative",
|
name: "invalid - invalid amount - negative",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: validZgChainAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - invalid denom",
|
name: "invalid - invalid amount - invalid denom",
|
||||||
initiator: validKavaAddr.String(),
|
initiator: validZgChainAddr.String(),
|
||||||
receiver: validHexAddr.String(),
|
receiver: validHexAddr.String(),
|
||||||
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
@ -322,7 +323,7 @@ func TestConvertCosmosCoinToERC20_GetSigners(t *testing.T) {
|
|||||||
|
|
||||||
func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
||||||
validHexAddr := testutil.RandomEvmAddress()
|
validHexAddr := testutil.RandomEvmAddress()
|
||||||
validKavaAddr := app.RandomAddress()
|
validZgChainAddr := app.RandomAddress()
|
||||||
invalidAddr := "not-an-address"
|
invalidAddr := "not-an-address"
|
||||||
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
validAmount := sdk.NewInt64Coin("hard", 5e3)
|
||||||
|
|
||||||
@ -336,7 +337,7 @@ func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "valid",
|
name: "valid",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: validZgChainAddr.String(),
|
||||||
amount: validAmount,
|
amount: validAmount,
|
||||||
expectedErr: "",
|
expectedErr: "",
|
||||||
},
|
},
|
||||||
@ -364,28 +365,28 @@ func TestConvertCosmosCoinFromERC20_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid - invalid amount - nil",
|
name: "invalid - invalid amount - nil",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: validZgChainAddr.String(),
|
||||||
amount: sdk.Coin{},
|
amount: sdk.Coin{},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - zero",
|
name: "invalid - invalid amount - zero",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: validZgChainAddr.String(),
|
||||||
amount: sdk.NewInt64Coin("magic", 0),
|
amount: sdk.NewInt64Coin("magic", 0),
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - negative",
|
name: "invalid - invalid amount - negative",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: validZgChainAddr.String(),
|
||||||
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
amount: sdk.Coin{Denom: "magic", Amount: sdkmath.NewInt(-42)},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "invalid - invalid amount - invalid denom",
|
name: "invalid - invalid amount - invalid denom",
|
||||||
initiator: validHexAddr.String(),
|
initiator: validHexAddr.String(),
|
||||||
receiver: validKavaAddr.String(),
|
receiver: validZgChainAddr.String(),
|
||||||
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
amount: sdk.Coin{Denom: "", Amount: sdkmath.NewInt(42)},
|
||||||
expectedErr: "invalid coins",
|
expectedErr: "invalid coins",
|
||||||
},
|
},
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
|
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/testutil"
|
||||||
"github.com/0glabs/0g-chain/x/evmutil/types"
|
"github.com/0glabs/0g-chain/x/evmutil/types"
|
||||||
)
|
)
|
||||||
@ -19,7 +19,7 @@ type ParamsTestSuite struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ParamsTestSuite) SetupTest() {
|
func (suite *ParamsTestSuite) SetupTest() {
|
||||||
app.SetSDKConfig()
|
chaincfg.SetSDKConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *ParamsTestSuite) TestDefault() {
|
func (suite *ParamsTestSuite) TestDefault() {
|
||||||
@ -107,11 +107,11 @@ func (suite *ParamsTestSuite) TestParams_Validate() {
|
|||||||
invalidConversionPairs := types.NewConversionPairs(
|
invalidConversionPairs := types.NewConversionPairs(
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000A"),
|
||||||
"kava",
|
chaincfg.DisplayDenom,
|
||||||
),
|
),
|
||||||
types.NewConversionPair(
|
types.NewConversionPair(
|
||||||
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
testutil.MustNewInternalEVMAddressFromString("0x000000000000000000000000000000000000000B"),
|
||||||
"kava", // duplicate denom!
|
chaincfg.DisplayDenom, // duplicate denom!
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
validAllowedCosmosDenoms := types.NewAllowedCosmosCoinERC20Tokens(
|
validAllowedCosmosDenoms := types.NewAllowedCosmosCoinERC20Tokens(
|
||||||
|
@ -40,7 +40,7 @@ func queryCirculatingSupply() *cobra.Command {
|
|||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "circulating-supply",
|
Use: "circulating-supply",
|
||||||
Short: "Get circulating supply",
|
Short: "Get circulating supply",
|
||||||
Long: "Get the current circulating supply of kava tokens",
|
Long: "Get the current circulating supply of 0g tokens",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cliCtx, err := client.GetClientQueryContext(cmd)
|
cliCtx, err := client.GetClientQueryContext(cmd)
|
||||||
@ -62,7 +62,7 @@ func queryTotalSupply() *cobra.Command {
|
|||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "total-supply",
|
Use: "total-supply",
|
||||||
Short: "Get total supply",
|
Short: "Get total supply",
|
||||||
Long: "Get the current total supply of kava tokens",
|
Long: "Get the current total supply of 0g tokens",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
cliCtx, err := client.GetClientQueryContext(cmd)
|
cliCtx, err := client.GetClientQueryContext(cmd)
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdkmath "cosmossdk.io/math"
|
sdkmath "cosmossdk.io/math"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/validator-vesting/types"
|
"github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
@ -20,23 +21,23 @@ func NewQueryServerImpl(bk types.BankKeeper) types.QueryServer {
|
|||||||
return &queryServer{bk: bk}
|
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.
|
func (s queryServer) CirculatingSupply(c context.Context, req *types.QueryCirculatingSupplyRequest) (*types.
|
||||||
QueryCirculatingSupplyResponse, error) {
|
QueryCirculatingSupplyResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
ctx := sdk.UnwrapSDKContext(c)
|
||||||
|
|
||||||
totalSupply := s.bk.GetSupply(ctx, "ukava").Amount
|
totalSupply := s.bk.GetSupply(ctx, chaincfg.DisplayDenom).Amount
|
||||||
supplyInt := getCirculatingSupply(ctx.BlockTime(), totalSupply)
|
supplyInt := getCirculatingSupply(ctx.BlockTime(), totalSupply)
|
||||||
return &types.QueryCirculatingSupplyResponse{
|
return &types.QueryCirculatingSupplyResponse{
|
||||||
Amount: supplyInt,
|
Amount: supplyInt,
|
||||||
}, nil
|
}, 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) {
|
func (s queryServer) TotalSupply(c context.Context, req *types.QueryTotalSupplyRequest) (*types.QueryTotalSupplyResponse, error) {
|
||||||
ctx := sdk.UnwrapSDKContext(c)
|
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()
|
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt()
|
||||||
return &types.QueryTotalSupplyResponse{
|
return &types.QueryTotalSupplyResponse{
|
||||||
Amount: supplyInt,
|
Amount: supplyInt,
|
||||||
@ -255,7 +256,7 @@ func (s queryServer) CirculatingSupplySWP(c context.Context, req *types.QueryCir
|
|||||||
monthlyStakersSwp := int64(520_833)
|
monthlyStakersSwp := int64(520_833)
|
||||||
monthlyLPIncentivesSwp := int64(2_343_750)
|
monthlyLPIncentivesSwp := int64(2_343_750)
|
||||||
|
|
||||||
// []{Ecosystem, Team, Treasury, Kava Stakers, LP Incentives}
|
// []{Ecosystem, Team, Treasury, 0gChain Stakers, LP Incentives}
|
||||||
scheduleAmounts := [][]int64{
|
scheduleAmounts := [][]int64{
|
||||||
{12_500_000, 0, 15_625_000, monthlyStakersSwp, monthlyLPIncentivesSwp}, // *** Year ONE ***
|
{12_500_000, 0, 15_625_000, monthlyStakersSwp, monthlyLPIncentivesSwp}, // *** Year ONE ***
|
||||||
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 1
|
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 1
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/0glabs/0g-chain/app"
|
"github.com/0glabs/0g-chain/app"
|
||||||
|
"github.com/0glabs/0g-chain/chaincfg"
|
||||||
"github.com/0glabs/0g-chain/x/validator-vesting/keeper"
|
"github.com/0glabs/0g-chain/x/validator-vesting/keeper"
|
||||||
"github.com/0glabs/0g-chain/x/validator-vesting/types"
|
"github.com/0glabs/0g-chain/x/validator-vesting/types"
|
||||||
)
|
)
|
||||||
@ -52,7 +53,7 @@ func TestGrpcQueryTestSuite(t *testing.T) {
|
|||||||
|
|
||||||
func (suite *grpcQueryTestSuite) TestCirculatingSupply() {
|
func (suite *grpcQueryTestSuite) TestCirculatingSupply() {
|
||||||
suite.Run("vesting period supply", func() {
|
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)
|
lastVestingPeriod := time.Date(2022, 8, 5, 24, 0, 0, 0, time.UTC)
|
||||||
queryClient := suite.queryClientWithBlockTime(lastVestingPeriod)
|
queryClient := suite.queryClientWithBlockTime(lastVestingPeriod)
|
||||||
res, err := queryClient.CirculatingSupply(context.Background(), &types.QueryCirculatingSupplyRequest{})
|
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.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{})
|
res, err := suite.queryClient.CirculatingSupply(context.Background(), &types.QueryCirculatingSupplyRequest{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(sdkmath.NewInt(100), res.Amount)
|
suite.Require().Equal(sdkmath.NewInt(100), res.Amount)
|
||||||
@ -69,7 +70,7 @@ func (suite *grpcQueryTestSuite) TestCirculatingSupply() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *grpcQueryTestSuite) TestTotalSupply() {
|
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{})
|
res, err := suite.queryClient.TotalSupply(context.Background(), &types.QueryTotalSupplyRequest{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(sdkmath.NewInt(100), res.Amount)
|
suite.Require().Equal(sdkmath.NewInt(100), res.Amount)
|
||||||
|
Loading…
Reference in New Issue
Block a user