Skip to content

Commit

Permalink
Merge branch 'e2e-testings'
Browse files Browse the repository at this point in the history
  • Loading branch information
tubackkhoa committed Jan 10, 2023
2 parents 24cb5c9 + 971850e commit 89292cc
Show file tree
Hide file tree
Showing 30 changed files with 643 additions and 395 deletions.
Empty file modified docker-compose.yml
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions docs/developer/e2e-tests.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ yarn hardhat node --fork https://data-seed-prebsc-1-s1.binance.org:8545 --fork-b
npx ts-node scripts/get-dummy-balance.ts

# Add new evm chain
gravity tx gravity add-evm-chain "goerli network" foobar "add goerli network" 100000000uoraib "foobar" --from validator1 --home data/validator1/ -y
gravity tx gov vote 1 yes --from validator1 --home data/validator1/ -y
gravity tx gravity add-evm-chain "goerli network 2nd" "foobar" "421" "defaultgravityid" "add goerli network 2nd" 100000000uoraib "foobar" --from validator1 --home e2e/data/validator1/ -y --keyring-backend test --chain-id gravity-test -b block --gas 2000000
gravity tx gov vote 1 yes --from validator1 --home e2e/data/validator1/ -y
```

<!-- oraid tx ibc-transfer transfer transfer channel-0 oraib1kvx7v59g9e8zvs7e8jm2a8w4mtp9ys2sjufdm4 1orai --from validator -y -->
1 change: 1 addition & 0 deletions docs/developer/unit-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

go test ./x/gravity/migrations/v2/... -v --count=1
go test ./x/gravity/migrations/v3/... -v --count=1
go test ./x/gravity/migrations/v4/... -v --count=1
go test ./x/gravity/keeper/... -v --count=1
68 changes: 13 additions & 55 deletions e2e/data/validator1/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@
},
"votes": [],
"voting_params": {
"voting_period": "60s"
"voting_period": "30s"
}
},
"gravity": {
Expand Down Expand Up @@ -410,64 +410,22 @@
"reward_token": "0x0000000000000000000000000000000000000000"
}
]
},
{
"attestations": [],
"batch_confirms": [],
"batches": [],
"delegate_keys": [
{
"eth_address": "0xc9B6f87d637d4774EEB54f8aC2b89dBC3D38226b",
"orchestrator": "oraib1t8luzfnnrnupg6uhwr9gfdd6t7amshpj0nxh0g",
"validator": "oraibvaloper1kvx7v59g9e8zvs7e8jm2a8w4mtp9ys2su2jgqk"
}
],
"erc20_to_denoms": [],
"evm_chain": {
"evm_chain_name": "goerli testnet 2nd fork",
"evm_chain_net_version": "0",
"evm_chain_prefix": "testnet-goerli-2"
},
"gravity_nonces": {
"last_batch_id": "0",
"last_observed_evm_block_height": "0",
"last_observed_nonce": "0",
"last_slashed_batch_block": "0",
"last_slashed_logic_call_block": "0",
"last_slashed_valset_nonce": "0",
"last_tx_pool_id": "0",
"latest_valset_nonce": "1"
},
"logic_call_confirms": [],
"logic_calls": [],
"pending_ibc_auto_forwards": [],
"unbatched_transfers": [],
"valset_confirms": [],
"valsets": [
{
"height": "1",
"members": [
{
"ethereum_address": "0xc9B6f87d637d4774EEB54f8aC2b89dBC3D38226b",
"power": "4294967296"
}
],
"nonce": "1",
"reward_amount": "0",
"reward_token": "0x0000000000000000000000000000000000000000"
}
]
}
],
"params": {
"evm_chain_params": [
{
"evm_chain_prefix": "goerli-testnet",
"average_ethereum_block_time": "15000",
"bridge_active": true,
"bridge_chain_id": "420",
"bridge_ethereum_address": "0x0000000000000000000000000000000000000000",
"contract_source_hash": "",
"ethereum_blacklist": [],
"gravity_id": "defaultgravityid"
}
],
"average_block_time": "5000",
"average_ethereum_block_time": "15000",
"bridge_active": true,
"bridge_chain_id": "0",
"bridge_ethereum_address": "0x0000000000000000000000000000000000000000",
"contract_source_hash": "",
"ethereum_blacklist": [],
"gravity_id": "defaultgravityid",
"min_chain_fee_basis_points": "0",
"signed_batches_window": "10000",
"signed_logic_calls_window": "10000",
Expand Down
1 change: 0 additions & 1 deletion module/Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ RUN apk add upx bash jq
WORKDIR /workspace
COPY . /workspace/

# # force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN make install LEDGER_ENABLED=false BUILD_TAGS=muslc
8 changes: 6 additions & 2 deletions module/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import (
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades"
v2 "github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/v2"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/exported"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/keeper"
gravitytypes "github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/types"
)
Expand Down Expand Up @@ -369,6 +370,8 @@ func NewGravityApp(
}

paramsKeeper := initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tKeys[paramstypes.TStoreKey])
// for the sake of param migration
paramsKeeper.Subspace(exported.DefaultParamspace)
app.paramsKeeper = &paramsKeeper

bApp.SetParamStore(paramsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))
Expand Down Expand Up @@ -478,7 +481,7 @@ func NewGravityApp(

gravityKeeper := keeper.NewKeeper(
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.ModuleName),
app.GetSubspace(gravitytypes.DefaultParamspace),
appCodec,
&bankKeeper,
&stakingKeeper,
Expand Down Expand Up @@ -636,6 +639,7 @@ func NewGravityApp(
gravity.NewAppModule(
gravityKeeper,
bankKeeper,
app.GetSubspace(exported.DefaultParamspace),
),
bech32ibc.NewAppModule(
appCodec,
Expand Down Expand Up @@ -956,7 +960,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable())
paramsKeeper.Subspace(crisistypes.ModuleName)
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
paramsKeeper.Subspace(gravitytypes.ModuleName)
paramsKeeper.Subspace(gravitytypes.DefaultParamspace)
paramsKeeper.Subspace(ibchost.ModuleName)

return paramsKeeper
Expand Down
4 changes: 2 additions & 2 deletions module/proto/gravity/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ message Params {
cosmos.base.v1beta1.Coin valset_reward = 11 [ (gogoproto.nullable) = false ];
uint64 min_chain_fee_basis_points = 12;

repeated EvmChainParams evm_chain_params = 13;
repeated EvmChainParam evm_chain_params = 13;
}

// GenesisState struct, containing all persistant data required by the Gravity
Expand Down Expand Up @@ -149,7 +149,7 @@ message GenesisState {
// bridge_chain_id:
// the unique identifier of the Ethereum chain, this is a reference value
// only and is not actually used by any Gravity code
message EvmChainParams {
message EvmChainParam {
option (gogoproto.stringer) = false;

string gravity_id = 1;
Expand Down
1 change: 1 addition & 0 deletions module/proto/gravity/v1/types.proto
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ message AddEvmChainProposal {
string evm_chain_name = 3;
string evm_chain_prefix = 4;
uint64 evm_chain_net_version = 5;
string gravity_id = 6;
}

// PendingIbcAutoForward represents a SendToCosmos transaction with a foreign CosmosReceiver which will be added to the
Expand Down
6 changes: 3 additions & 3 deletions module/x/gravity/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ func slashing(ctx sdk.Context, k keeper.Keeper, params types.Params, evmChainPre
func attestationTally(ctx sdk.Context, k keeper.Keeper, evmChainPrefix string) {
params := k.GetParams(ctx)

evmChainParams := params.EvmChain(evmChainPrefix)
evmChainParam := params.GetEvmChain(evmChainPrefix)

if evmChainParams == nil {
if evmChainParam == nil {
return
}

// bridge is currently disabled, do not process attestations from evm chain
if !evmChainParams.BridgeActive {
if !evmChainParam.BridgeActive {
return
}

Expand Down
4 changes: 2 additions & 2 deletions module/x/gravity/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,9 @@ func TestBatchTimeout(t *testing.T) {
require.NoError(t, err)

require.Greater(t, params.AverageBlockTime, uint64(0))
evmChainParams := params.EvmChain(evmChain.EvmChainPrefix)
evmChainParam := params.GetEvmChain(evmChain.EvmChainPrefix)

require.Greater(t, evmChainParams.AverageEthereumBlockTime, uint64(0))
require.Greater(t, evmChainParam.AverageEthereumBlockTime, uint64(0))

// mint some vouchers first
require.NoError(t, input.BankKeeper.MintCoins(ctx, types.ModuleName, allVouchers))
Expand Down
9 changes: 5 additions & 4 deletions module/x/gravity/client/cli/tx.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,17 @@ func CmdGovUnhaltBridgeProposal() *cobra.Command {
func CmdAddEvmChainProposal() *cobra.Command {
// nolint: exhaustruct
cmd := &cobra.Command{
Use: "add-evm-chain [evm-chain-name] [evm-chain-prefix] [evm-chain-net-version] [title] [initial-deposit] [description]",
Use: "add-evm-chain [evm-chain-name] [evm-chain-prefix] [evm-chain-net-version] [evm-chain-gravity-id] [title] [initial-deposit] [description]",
Short: "Creates a governance proposal to support a new EVM chain on the network",
Args: cobra.ExactArgs(6),
Args: cobra.ExactArgs(7),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
cosmosAddr := cliCtx.GetFromAddress()

initialDeposit, err := sdk.ParseCoinsNormalized(args[4])
initialDeposit, err := sdk.ParseCoinsNormalized(args[5])
if err != nil {
return sdkerrors.Wrap(err, "bad initial deposit amount")
}
Expand All @@ -331,8 +331,9 @@ func CmdAddEvmChainProposal() *cobra.Command {
if err != nil {
return fmt.Errorf("EVM chain net version should be an unsigned integer")
}
gravityId := args[3]

proposal := &types.AddEvmChainProposal{EvmChainName: evmChainName, EvmChainPrefix: evmChainPrefix, EvmChainNetVersion: evmChainNetVersion, Title: args[3], Description: args[5]}
proposal := &types.AddEvmChainProposal{EvmChainName: evmChainName, EvmChainPrefix: evmChainPrefix, EvmChainNetVersion: evmChainNetVersion, GravityId: gravityId, Title: args[4], Description: args[6]}
proposalAny, err := codectypes.NewAnyWithValue(proposal)
if err != nil {
return sdkerrors.Wrap(err, "invalid metadata or proposal details!")
Expand Down
23 changes: 23 additions & 0 deletions module/x/gravity/exported/exported.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package exported

import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

type (
ParamSet = paramtypes.ParamSet

// Subspace defines an interface that implements the legacy x/params Subspace
// type.
//
// NOTE: This is used solely for migration of x/params managed parameters.
Subspace interface {
GetParamSet(ctx sdk.Context, ps ParamSet)
WithKeyTable(table paramtypes.KeyTable) paramtypes.Subspace
}
)

var (
DefaultParamspace = "gravity"
)
7 changes: 4 additions & 3 deletions module/x/gravity/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,15 @@ func TestEthereumBlacklist(t *testing.T) {
blockedAddress := anyETHSender
newParams := k.GetParams(ctx)

evmChainParams := newParams.EvmChain(evmChain.EvmChainPrefix)
evmChainParams.EthereumBlacklist = []string{blockedAddress}
evmChainParam := newParams.GetEvmChain(evmChain.EvmChainPrefix)
evmChainParam.EthereumBlacklist = []string{blockedAddress}

k.SetParams(ctx, newParams)

params := k.GetParams(ctx)
evmParams := params.GetEvmChain(evmChain.EvmChainPrefix)

assert.Equal(t, params.EvmChain(evmChain.EvmChainPrefix).EthereumBlacklist, []string{blockedAddress})
assert.Equal(t, evmParams.EthereumBlacklist, []string{blockedAddress})

// send attestations from all five validators
for _, v := range keeper.OrchAddrs {
Expand Down
16 changes: 8 additions & 8 deletions module/x/gravity/keeper/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func (k Keeper) BuildOutgoingTxBatch(
return nil, sdkerrors.Wrap(types.ErrInvalid, "max elements value")
}
params := k.GetParams(ctx)
evmChainParams := params.EvmChain(evmChainPrefix)
evmChainParam := params.GetEvmChain(evmChainPrefix)

if evmChainParams == nil {
return nil, sdkerrors.Wrap(types.ErrEmpty, "EvmChainParams not found "+evmChainPrefix)
if evmChainParam == nil {
return nil, sdkerrors.Wrap(types.ErrEmpty, "EvmChainParams not found for prefix "+evmChainPrefix)
}

if !evmChainParams.BridgeActive {
if !evmChainParam.BridgeActive {
return nil, sdkerrors.Wrap(types.ErrInvalid, "bridge paused")
}

Expand Down Expand Up @@ -92,9 +92,9 @@ func (k Keeper) BuildOutgoingTxBatch(
func (k Keeper) getBatchTimeoutHeight(ctx sdk.Context, evmChainPrefix string) uint64 {
params := k.GetParams(ctx)

evmChainParams := params.EvmChain(evmChainPrefix)
evmChainParam := params.GetEvmChain(evmChainPrefix)

if evmChainParams == nil {
if evmChainParam == nil {
return 0
}

Expand All @@ -108,10 +108,10 @@ func (k Keeper) getBatchTimeoutHeight(ctx sdk.Context, evmChainPrefix string) ui
// we project how long it has been in milliseconds since the last evm chain block height was observed
projectedMillis := (uint64(currentCosmosHeight) - heights.CosmosBlockHeight) * params.AverageBlockTime
// we convert that projection into the current evm chain height using the average evm chain block time in millis
projectedCurrentEvmChainHeight := (projectedMillis / evmChainParams.AverageEthereumBlockTime) + heights.EthereumBlockHeight
projectedCurrentEvmChainHeight := (projectedMillis / evmChainParam.AverageEthereumBlockTime) + heights.EthereumBlockHeight
// we convert our target time for block timeouts (lets say 12 hours) into a number of blocks to
// place on top of our projection of the current evm chain block height.
blocksToAdd := params.TargetBatchTimeout / evmChainParams.AverageEthereumBlockTime
blocksToAdd := params.TargetBatchTimeout / evmChainParam.AverageEthereumBlockTime
return projectedCurrentEvmChainHeight + blocksToAdd
}

Expand Down
13 changes: 8 additions & 5 deletions module/x/gravity/keeper/batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestBatches(t *testing.T) {
// ==================

for _, evmChain := range input.GravityKeeper.GetEvmChains(ctx) {
println("evm chain prefix: ", evmChain.EvmChainPrefix)
// batch should not be created if there is no txs of the given token type in tx pool
noBatch, err := input.GravityKeeper.BuildOutgoingTxBatch(ctx, evmChain.EvmChainPrefix, *myTokenContractAddr, 2)
require.Nil(t, noBatch)
Expand Down Expand Up @@ -730,8 +731,9 @@ func TestBatchesNotCreatedWhenBridgePaused(t *testing.T) {

// pause the bridge
params := input.GravityKeeper.GetParams(ctx)
evmChainParams := params.EvmChain(evmChain.EvmChainPrefix)
evmChainParams.BridgeActive = false
evmChainParam := params.GetEvmChain(evmChain.EvmChainPrefix)
evmChainParam.BridgeActive = false

input.GravityKeeper.SetParams(ctx, params)

// mint some voucher first
Expand Down Expand Up @@ -774,7 +776,7 @@ func TestBatchesNotCreatedWhenBridgePaused(t *testing.T) {
require.Nil(t, gotFirstBatch)

// resume the bridge
evmChainParams.BridgeActive = true
evmChainParam.BridgeActive = true
input.GravityKeeper.SetParams(ctx, params)

// when
Expand Down Expand Up @@ -810,8 +812,9 @@ func TestEthereumBlacklistBatches(t *testing.T) {

// add the blacklisted address to the blacklist
params := input.GravityKeeper.GetParams(ctx)
evmChainParams := params.EvmChain(evmChain.EvmChainPrefix)
evmChainParams.EthereumBlacklist = append(evmChainParams.EthereumBlacklist, blacklistedReceiver.GetAddress().Hex())
evmChainParam := params.GetEvmChain(evmChain.EvmChainPrefix)
evmChainParam.EthereumBlacklist = append(evmChainParam.EthereumBlacklist, blacklistedReceiver.GetAddress().Hex())

input.GravityKeeper.SetParams(ctx, params)

// mint some voucher first
Expand Down
15 changes: 15 additions & 0 deletions module/x/gravity/keeper/governance_proposals.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ func (k Keeper) HandleAddEvmChainProposal(ctx sdk.Context, p *types.AddEvmChainP
k.SetEvmChainData(ctx, evmChain.EvmChain)

initBridgeDataFromGenesis(ctx, k, evmChain)

// update param to match with the new evm chain
params := k.GetParams(ctx)
evmChainParam := &types.EvmChainParam{
EvmChainPrefix: p.EvmChainPrefix,
GravityId: p.GravityId,
ContractSourceHash: "",
BridgeEthereumAddress: "0x0000000000000000000000000000000000000000",
BridgeChainId: p.EvmChainNetVersion,
AverageEthereumBlockTime: 15000,
BridgeActive: true,
EthereumBlacklist: []string{},
}
params.EvmChainParams = append(params.EvmChainParams, evmChainParam)
k.SetParams(ctx, params)
return nil
}

Expand Down
Loading

0 comments on commit 89292cc

Please sign in to comment.