Skip to content

Commit

Permalink
rebase develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed May 29, 2024
2 parents 953b6c9 + 180fcef commit 3381d85
Show file tree
Hide file tree
Showing 29 changed files with 1,071 additions and 66 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* [2113](https://github.com/zeta-chain/node/pull/2113) - add zetaclientd-supervisor process
* [2154](https://github.com/zeta-chain/node/pull/2154) - add `ibccrosschain` module
* [2258](https://github.com/zeta-chain/node/pull/2258) - add Optimism and Base in static chain information
* [2279](https://github.com/zeta-chain/node/pull/2279) - add a CCTXGateway field to chain static data
* [2275](https://github.com/zeta-chain/node/pull/2275) - add ChainInfo singleton state variable in authority

### Refactor

Expand Down
8 changes: 4 additions & 4 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ if [ "$OPTION" == "upgrade" ]; then
# When the upgrade height is greater than 100 for upgrade test, the Bitcoin tests have been run once, therefore the Bitcoin wallet is already set up
# Use light flag to skip advanced tests
if [ "$UPGRADE_HEIGHT" -lt 100 ]; then
zetae2e "$ZETAE2E_CMD" --skip-setup --config deployed.yml --light --skip-header-proof
zetae2e $ZETAE2E_CMD --skip-setup --config deployed.yml --light --skip-header-proof
else
zetae2e "$ZETAE2E_CMD" --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof
zetae2e $ZETAE2E_CMD --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof
fi

ZETAE2E_EXIT_CODE=$?
Expand All @@ -156,7 +156,7 @@ else
echo "running e2e setup..."

if [[ ! -f deployed.yml ]]; then
zetae2e "$ZETAE2E_CMD" --setup-only --config-out deployed.yml
zetae2e $ZETAE2E_CMD --setup-only --config-out deployed.yml
if [ $? -ne 0 ]; then
echo "e2e setup failed"
exit 1
Expand All @@ -167,7 +167,7 @@ else

echo "running e2e tests..."

zetae2e "$ZETAE2E_CMD" --skip-setup --config deployed.yml
zetae2e $ZETAE2E_CMD --skip-setup --config deployed.yml
ZETAE2E_EXIT_CODE=$?

# if e2e passed, exit with 0, otherwise exit with 1
Expand Down
15 changes: 15 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56744,6 +56744,18 @@ definitions:
description: |-
QueryGetPoliciesResponse is the response type for the Query/Policies RPC
method.
chainsCCTXGateway:
type: string
enum:
- zevm
- observers
default: zevm
description: |-
- zevm: zevm is the internal CCTX gateway to process outbound on the ZEVM and read
inbound events from the ZEVM only used for ZetaChain chains
- observers: observers is the CCTX gateway for chains relying on the observer set to
observe inbounds and TSS for outbounds
title: CCTXGateway describes for the chain the gateway used to handle CCTX outbounds
chainsChain:
type: object
properties:
Expand All @@ -56769,6 +56781,9 @@ definitions:
is_external:
type: boolean
title: IsExternal describe if the chain is ZetaChain or external
cctx_gateway:
$ref: '#/definitions/chainsCCTXGateway'
title: CCTXGateway is the gateway used to handle CCTX outbounds
title: |-
Chain represents static data about a blockchain network
it is identified by a unique chain ID
Expand Down
33 changes: 33 additions & 0 deletions pkg/chains/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,47 @@ type SigninAlgo string
// Chains represent a slice of Chain
type Chains []Chain

// Validate checks whether the chain is valid
// The function check the chain ID is positive and all enum fields have a defined value
func (chain Chain) Validate() error {
if chain.ChainId <= 0 {
return fmt.Errorf("chain ID must be positive")
}

if _, ok := ChainName_name[int32(chain.ChainName)]; !ok {
return fmt.Errorf("invalid chain name %d", int32(chain.ChainName))
}

if _, ok := Network_name[int32(chain.Network)]; !ok {
return fmt.Errorf("invalid network %d", int32(chain.Network))
}

if _, ok := NetworkType_name[int32(chain.NetworkType)]; !ok {
return fmt.Errorf("invalid network type %d", int32(chain.NetworkType))
}

if _, ok := Vm_name[int32(chain.Vm)]; !ok {
return fmt.Errorf("invalid vm %d", int32(chain.Vm))
}

if _, ok := Consensus_name[int32(chain.Consensus)]; !ok {
return fmt.Errorf("invalid consensus %d", int32(chain.Consensus))
}

return nil
}

// IsEqual compare two chain to see whether they represent the same chain
func (chain Chain) IsEqual(c Chain) bool {
return chain.ChainId == c.ChainId
}

// IsZetaChain returns true if the chain is a ZetaChain chain
func (chain Chain) IsZetaChain() bool {
return chain.Network == Network_zeta
}

// IsExternalChain returns true if the chain is an ExternalChain chain, not ZetaChain
func (chain Chain) IsExternalChain() bool {
return chain.IsExternal
}
Expand Down
127 changes: 127 additions & 0 deletions pkg/chains/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,133 @@ import (
"github.com/stretchr/testify/require"
)

func TestChain_Validate(t *testing.T) {
tests := []struct {
name string
chain Chain
errStr string
}{
{
name: "should pass if chain is valid",
chain: Chain{
ChainId: 42,
ChainName: ChainName_empty,
Network: Network_optimism,
NetworkType: NetworkType_testnet,
Vm: Vm_evm,
Consensus: Consensus_op_stack,
IsExternal: true,
},
},
{
name: "should error if chain ID is zero",
chain: Chain{
ChainId: 0,
ChainName: ChainName_empty,
Network: Network_optimism,
NetworkType: NetworkType_testnet,
Vm: Vm_evm,
Consensus: Consensus_op_stack,
IsExternal: true,
},
errStr: "chain ID must be positive",
},
{
name: "should error if chain ID is negative",
chain: Chain{
ChainId: 0,
ChainName: ChainName_empty,
Network: Network_optimism,
NetworkType: NetworkType_testnet,
Vm: Vm_evm,
Consensus: Consensus_op_stack,
IsExternal: true,
},
errStr: "chain ID must be positive",
},
{
name: "should error if chain name invalid",
chain: Chain{
ChainId: 42,
ChainName: ChainName_base_sepolia + 1,
Network: Network_optimism,
NetworkType: NetworkType_testnet,
Vm: Vm_evm,
Consensus: Consensus_op_stack,
IsExternal: true,
},
errStr: "invalid chain name",
},
{
name: "should error if network invalid",
chain: Chain{
ChainId: 42,
ChainName: ChainName_empty,
Network: Network_base + 1,
NetworkType: NetworkType_testnet,
Vm: Vm_evm,
Consensus: Consensus_op_stack,
IsExternal: true,
},
errStr: "invalid network",
},
{
name: "should error if network type invalid",
chain: Chain{
ChainId: 42,
ChainName: ChainName_empty,
Network: Network_base,
NetworkType: NetworkType_devnet + 1,
Vm: Vm_evm,
Consensus: Consensus_op_stack,
IsExternal: true,
},
errStr: "invalid network type",
},
{
name: "should error if vm invalid",
chain: Chain{
ChainId: 42,
ChainName: ChainName_empty,
Network: Network_base,
NetworkType: NetworkType_devnet,
Vm: Vm_evm + 1,
Consensus: Consensus_op_stack,
IsExternal: true,
},
errStr: "invalid vm",
},
{
name: "should error if consensus invalid",
chain: Chain{
ChainId: 42,
ChainName: ChainName_empty,
Network: Network_base,
NetworkType: NetworkType_devnet,
Vm: Vm_evm,
Consensus: Consensus_op_stack + 1,
IsExternal: true,
},
errStr: "invalid consensus",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.errStr != "" {
require.ErrorContains(t, tt.chain.Validate(), tt.errStr)
} else {
require.NoError(t, tt.chain.Validate())
}
})
}

t.Run("all default chains are valid", func(t *testing.T) {
for _, chain := range DefaultChainsList() {
require.NoError(t, chain.Validate())
}
})
}

func TestChain_EncodeAddress(t *testing.T) {
tests := []struct {
name string
Expand Down
Loading

0 comments on commit 3381d85

Please sign in to comment.