Skip to content

Commit

Permalink
Merge branch 'develop' into feat-observe-blob-transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie authored Mar 6, 2024
2 parents 26a4042 + 22549db commit 457b349
Show file tree
Hide file tree
Showing 17 changed files with 101 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:
cancel-in-progress: false

env:
DOCKER_REPO: "zeatcored"
DOCKER_REPO: "zetacored"
DOCKER_ORG: "zetachain"
DOCKER_REGISTRY: "https://index.docker.io/v1/"

Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ test :clean-test-dir run-test
test-hsm:
@go test ${HSM_BUILD_FLAGS} ${TEST_DIR}

test-coverage-exclude-core:
@go test ${TEST_BUILD_FLAGS} -v -coverprofile coverage.out $(go list ./... | grep -v /x/zetacore/)

# Generate the test coverage
# "|| exit 1" is used to return a non-zero exit code if the tests fail
test-coverage:
-@go test ${TEST_BUILD_FLAGS} -v -coverprofile coverage.out ${TEST_DIR}
@go test ${TEST_BUILD_FLAGS} -coverprofile coverage.out ${TEST_DIR} || exit 1

coverage-report: test-coverage
@go tool cover -html=coverage.out -o coverage.html
Expand Down
11 changes: 6 additions & 5 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# CHANGELOG
## Version: v14

### Fixes
- [1817](https://github.com/zeta-chain/node/pull/1817) - Add migration script to fix pending and chain nonces on testnet

## Unreleased

Expand Down Expand Up @@ -30,12 +26,17 @@
* [1767](https://github.com/zeta-chain/node/pull/1767) - add unit tests for emissions module begin blocker
* [1816](https://github.com/zeta-chain/node/pull/1816) - add args to e2e tests
* [1791](https://github.com/zeta-chain/node/pull/1791) - add e2e tests for feature of restricted address
* [1787](https://github.com/zeta-chain/node/pull/1787) - add unit tests for cross-chain evm hooks and e2e test failed withdraw to BTC legacy address
* [1787](https://github.com/zeta-chain/node/pull/1787) - add unit tests for cross-chain evm hooks and e2e test failed withdraw to BTC legacy address
* [1840](https://github.com/zeta-chain/node/pull/1840) - fix code coverage test failures ignored in CI

### Chores

* [1814](https://github.com/zeta-chain/node/pull/1814) - fix code coverage ignore for protobuf generated files

## Version: v14

- [1817](https://github.com/zeta-chain/node/pull/1817) - Add migration script to fix pending and chain nonces on testnet

## Version: v13.0.0

### Breaking Changes
Expand Down
3 changes: 0 additions & 3 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ comment:

flags:
zetacore:
carryforward: true
paths:
- "x/"
zetaclient:
carryforward: true
paths:
- "zetaclient/"
common:
carryforward: true
paths:
- "common/"

Expand Down
34 changes: 23 additions & 11 deletions testutil/network/genesis_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strconv"
"testing"

authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/codec"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -77,17 +79,6 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage
GranteePubkeys: observerList,
BlockNumber: 5,
}
// set admin policy with first validator as admin
observerGenesis.Params.AdminPolicy = []*observertypes.Admin_Policy{
{
PolicyType: observertypes.Policy_Type_group1,
Address: "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax",
},
{
PolicyType: observertypes.Policy_Type_group2,
Address: "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax",
},
}
observerGenesis.CrosschainFlags = &observertypes.CrosschainFlags{
IsInboundEnabled: true,
IsOutboundEnabled: true,
Expand All @@ -96,10 +87,31 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage
observerGenesisBz, err := codec.MarshalJSON(&observerGenesis)
require.NoError(t, err)

// authority genesis state
var authorityGenesis authoritytypes.GenesisState
require.NoError(t, codec.UnmarshalJSON(genesisState[authoritytypes.ModuleName], &authorityGenesis))
policies := authoritytypes.Policies{
Items: []*authoritytypes.Policy{
{
PolicyType: authoritytypes.PolicyType_groupEmergency,
Address: "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax",
},
{
PolicyType: authoritytypes.PolicyType_groupAdmin,
Address: "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax",
},
},
}
authorityGenesis.Policies = policies
require.NoError(t, authorityGenesis.Validate())
authorityGenesisBz, err := codec.MarshalJSON(&authorityGenesis)
require.NoError(t, err)

genesisState[types.ModuleName] = crossChainGenesisBz
genesisState[stakingtypes.ModuleName] = stakingGenesisStateBz
genesisState[observertypes.ModuleName] = observerGenesisBz
genesisState[evmtypes.ModuleName] = evmGenesisBz
genesisState[authoritytypes.ModuleName] = authorityGenesisBz
}

func AddObserverData(t *testing.T, n int, genesisState map[string]json.RawMessage, codec codec.Codec, ballots []*observertypes.Ballot) *observertypes.GenesisState {
Expand Down
2 changes: 0 additions & 2 deletions x/authority/types/message_update_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
)

func TestMsgUpdatePolicies_ValidateBasic(t *testing.T) {
setConfig()

tests := []struct {
name string
msg *types.MsgUpdatePolicies
Expand Down
2 changes: 0 additions & 2 deletions x/authority/types/policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ func setConfig() {
}

func TestPolicies_Validate(t *testing.T) {
setConfig()

// use table driven tests to test the validation of policies
tests := []struct {
name string
Expand Down
13 changes: 4 additions & 9 deletions x/crosschain/keeper/evm_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ import (
"github.com/zeta-chain/zetacore/testutil/sample"
crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper"
fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

func SetupStateForProcessLogsZetaSent(t *testing.T, ctx sdk.Context, k *crosschainkeeper.Keeper, zk keepertest.ZetaKeepers, sdkk keepertest.SDKKeepers, chain common.Chain) {
admin := sample.AccAddress()
setAdminPolicies(ctx, zk, admin)

assetAddress := sample.EthAddress().String()
gasZRC20 := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chain.ChainId, "ethereum", "ETH")
zrc20Addr := deployZRC20(
Expand All @@ -39,12 +35,10 @@ func SetupStateForProcessLogsZetaSent(t *testing.T, ctx sdk.Context, k *crosscha
assetAddress,
"ETH",
)
fungibleMsgServer := fungiblekeeper.NewMsgServerImpl(*zk.FungibleKeeper)
_, err := fungibleMsgServer.UpdateZRC20WithdrawFee(
sdk.UnwrapSDKContext(ctx),
fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), sdkmath.Uint{}),
)

_, err := zk.FungibleKeeper.UpdateZRC20ProtocolFlatFee(ctx, gasZRC20, big.NewInt(withdrawFee))
require.NoError(t, err)

k.SetGasPrice(ctx, crosschaintypes.GasPrice{
ChainId: chain.ChainId,
MedianIndex: 0,
Expand All @@ -58,6 +52,7 @@ func SetupStateForProcessLogsZetaSent(t *testing.T, ctx sdk.Context, k *crosscha
zrc20Addr,
)
}

func SetupStateForProcessLogs(t *testing.T, ctx sdk.Context, k *crosschainkeeper.Keeper, zk keepertest.ZetaKeepers, sdkk keepertest.SDKKeepers, chain common.Chain) {

deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper)
Expand Down
52 changes: 31 additions & 21 deletions x/emissions/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,7 @@ func TestBeginBlocker(t *testing.T) {
}

func TestDistributeObserverRewards(t *testing.T) {

k, ctx, sk, zk := keepertest.EmissionsKeeper(t)
observerSet := sample.ObserverSet(4)
zk.ObserverKeeper.SetObserverSet(ctx, observerSet)
// Total block rewards is the fixed amount of rewards that are distributed
totalBlockRewards, err := common.GetAzetaDecFromAmountInZeta(emissionstypes.BlockRewardsInZeta)
totalRewardCoins := sdk.NewCoins(sdk.NewCoin(config.BaseDenom, totalBlockRewards.TruncateInt()))
require.NoError(t, err)
// Fund the emission pool to start the emission process
err = sk.BankKeeper.MintCoins(ctx, emissionstypes.ModuleName, totalRewardCoins)
require.NoError(t, err)
// Set starting emission for all observers to 100 so that we can calculate the rewards and slashes
for _, observer := range observerSet.ObserverList {
k.SetWithdrawableEmission(ctx, emissionstypes.WithdrawableEmissions{
Address: observer,
Amount: sdkmath.NewInt(100),
})
}

tt := []struct {
name string
Expand Down Expand Up @@ -256,9 +239,34 @@ func TestDistributeObserverRewards(t *testing.T) {
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {

// Keeper initialization
k, ctx, sk, zk := keepertest.EmissionsKeeper(t)
zk.ObserverKeeper.SetObserverSet(ctx, observerSet)

// Total block rewards is the fixed amount of rewards that are distributed
totalBlockRewards, err := common.GetAzetaDecFromAmountInZeta(emissionstypes.BlockRewardsInZeta)
totalRewardCoins := sdk.NewCoins(sdk.NewCoin(config.BaseDenom, totalBlockRewards.TruncateInt()))
require.NoError(t, err)

// Fund the emission pool to start the emission process
err = sk.BankKeeper.MintCoins(ctx, emissionstypes.ModuleName, totalRewardCoins)
require.NoError(t, err)

// Set starting emission for all observers to 100 so that we can calculate the rewards and slashes
for _, observer := range observerSet.ObserverList {
k.SetWithdrawableEmission(ctx, emissionstypes.WithdrawableEmissions{
Address: observer,
Amount: sdkmath.NewInt(100),
})
}

// Set the params
params := emissionstypes.DefaultParams()
params.ObserverSlashAmount = tc.slashAmount
k.SetParams(ctx, params)

// Set the ballot list
ballotIdentifiers := []string{}
for i, votes := range tc.votes {
ballot := observerTypes.Ballot{
Expand All @@ -276,12 +284,14 @@ func TestDistributeObserverRewards(t *testing.T) {
})

ctx = ctx.WithBlockHeight(100)
err := emissionsModule.DistributeObserverRewards(ctx, tc.totalRewardsForBlock, *k)

// Distribute the rewards and check if the rewards are distributed correctly
err = emissionsModule.DistributeObserverRewards(ctx, tc.totalRewardsForBlock, *k)
require.NoError(t, err)
for _, observer := range observerSet.ObserverList {
for i, observer := range observerSet.ObserverList {
observerEmission, found := k.GetWithdrawableEmission(ctx, observer)
require.True(t, found)
require.Equal(t, tc.expectedRewards[observer], observerEmission.Amount.Int64())
require.True(t, found, "withdrawable emission not found for observer %d", i)
require.Equal(t, tc.expectedRewards[observer], observerEmission.Amount.Int64(), "invalid withdrawable emission for observer %d", i)
}
})
}
Expand Down
4 changes: 4 additions & 0 deletions x/observer/keeper/msg_server_remove_chain_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func TestMsgServer_RemoveChainParams(t *testing.T) {
require.Equal(t, chain1, chainParamsList.ChainParams[0].ChainId)
require.Equal(t, chain3, chainParamsList.ChainParams[1].ChainId)

keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true)

// remove chain params
_, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &types.MsgRemoveChainParams{
Creator: admin,
Expand All @@ -68,6 +70,8 @@ func TestMsgServer_RemoveChainParams(t *testing.T) {
require.Len(t, chainParamsList.ChainParams, 1)
require.Equal(t, chain3, chainParamsList.ChainParams[0].ChainId)

keepertest.MockIsAuthorized(&authorityMock.Mock, admin, authoritytypes.PolicyType_groupAdmin, true)

// remove chain params
_, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &types.MsgRemoveChainParams{
Creator: admin,
Expand Down
6 changes: 3 additions & 3 deletions x/observer/keeper/nonce_to_cctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestKeeper_GetNonceToCctx(t *testing.T) {
t.Run("Get nonce to cctx", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
nonceToCctxList := sample.NonceToCctxList(t, "sample", 1)
for _, n := range nonceToCctxList {
k.SetNonceToCctx(ctx, n)
Expand All @@ -22,7 +22,7 @@ func TestKeeper_GetNonceToCctx(t *testing.T) {
}
})
t.Run("Get nonce to cctx not found", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
nonceToCctxList := sample.NonceToCctxList(t, "sample", 1)
for _, n := range nonceToCctxList {
k.SetNonceToCctx(ctx, n)
Expand All @@ -31,7 +31,7 @@ func TestKeeper_GetNonceToCctx(t *testing.T) {
require.False(t, found)
})
t.Run("Get all nonce to cctx", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
nonceToCctxList := sample.NonceToCctxList(t, "sample", 10)
for _, n := range nonceToCctxList {
k.SetNonceToCctx(ctx, n)
Expand Down
6 changes: 3 additions & 3 deletions x/observer/keeper/nonces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func TestChainNoncesGet(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
items := sample.ChainNoncesList(t, 10)
for _, item := range items {
k.SetChainNonces(ctx, item)
Expand All @@ -21,7 +21,7 @@ func TestChainNoncesGet(t *testing.T) {
}
}
func TestChainNoncesRemove(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
items := sample.ChainNoncesList(t, 10)
for _, item := range items {
k.SetChainNonces(ctx, item)
Expand All @@ -34,7 +34,7 @@ func TestChainNoncesRemove(t *testing.T) {
}

func TestChainNoncesGetAll(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
items := sample.ChainNoncesList(t, 10)
for _, item := range items {
k.SetChainNonces(ctx, item)
Expand Down
14 changes: 7 additions & 7 deletions x/observer/keeper/observer_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestKeeper_GetObserverSet(t *testing.T) {
t.Run("get observer set", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
os := sample.ObserverSet(10)
k.SetObserverSet(ctx, os)
tfm, found := k.GetObserverSet(ctx)
Expand All @@ -21,7 +21,7 @@ func TestKeeper_GetObserverSet(t *testing.T) {

func TestKeeper_IsAddressPartOfObserverSet(t *testing.T) {
t.Run("address is part of observer set", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
os := sample.ObserverSet(10)
k.SetObserverSet(ctx, os)
require.True(t, k.IsAddressPartOfObserverSet(ctx, os.ObserverList[0]))
Expand All @@ -31,7 +31,7 @@ func TestKeeper_IsAddressPartOfObserverSet(t *testing.T) {

func TestKeeper_AddObserverToSet(t *testing.T) {
t.Run("add observer to set", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
os := sample.ObserverSet(10)
k.SetObserverSet(ctx, os)
newObserver := sample.AccAddress()
Expand All @@ -46,7 +46,7 @@ func TestKeeper_AddObserverToSet(t *testing.T) {

func TestKeeper_RemoveObserverFromSet(t *testing.T) {
t.Run("remove observer from set", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
os := sample.ObserverSet(10)
k.SetObserverSet(ctx, os)
k.RemoveObserverFromSet(ctx, os.ObserverList[0])
Expand All @@ -59,7 +59,7 @@ func TestKeeper_RemoveObserverFromSet(t *testing.T) {

func TestKeeper_UpdateObserverAddress(t *testing.T) {
t.Run("update observer address", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
oldObserverAddress := sample.AccAddress()
newObserverAddress := sample.AccAddress()
observerSet := sample.ObserverSet(10)
Expand All @@ -72,7 +72,7 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) {
require.Equal(t, newObserverAddress, observerSet.ObserverList[len(observerSet.ObserverList)-1])
})
t.Run("update observer address long observerList", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
oldObserverAddress := sample.AccAddress()
newObserverAddress := sample.AccAddress()
observerSet := sample.ObserverSet(10000)
Expand All @@ -85,7 +85,7 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) {
require.Equal(t, newObserverAddress, observerMappers.ObserverList[len(observerMappers.ObserverList)-1])
})
t.Run("update observer address short observerList", func(t *testing.T) {
k, ctx, _ := keepertest.ObserverKeeper(t)
k, ctx, _, _ := keepertest.ObserverKeeper(t)
oldObserverAddress := sample.AccAddress()
newObserverAddress := sample.AccAddress()
observerSet := sample.ObserverSet(1)
Expand Down
Loading

0 comments on commit 457b349

Please sign in to comment.