Skip to content

Commit

Permalink
Node fix register chain vaa format error (#2100)
Browse files Browse the repository at this point in the history
* Node: Fix register chain VAA format error

Change-Id: If60ae2e072da025029b8a817272d8175585baa7d

* sdk_tests: adding sdk vaa tests

* sdk/vaa: share governance serialization

Co-authored-by: Bruce Riley <[email protected]>
Co-authored-by: Evan Gray <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2022
1 parent f39acdb commit 82651e4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,16 @@ jobs:
- run: curl https://get.ignite.com/[email protected] | bash && mv ignite /usr/local/bin/
- run: cd wormchain && make proto -B && make test

# Verify go sdk unit tests
sdk_vaa:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "1.19.3"
- run: cd sdk/vaa && go test

# Run Go linters, Go tests and other outside-of-Tilt things.
lint-and-tests:
# The linter is slow enough that we want to run it on the self-hosted runner
Expand Down
14 changes: 9 additions & 5 deletions sdk/vaa/payloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,26 @@ func (b BodyGuardianSetUpdate) Serialize() []byte {
}

func (r BodyTokenBridgeRegisterChain) Serialize() []byte {
return serializeBridgeGovernanceVaa(r.Module, 1, r.ChainID, r.EmitterAddress)
payload := &bytes.Buffer{}
MustWrite(payload, binary.BigEndian, r.ChainID)
payload.Write(r.EmitterAddress[:])
// target chain 0 = universal
return serializeBridgeGovernanceVaa(r.Module, 1, 0, payload.Bytes())
}

func (r BodyTokenBridgeUpgradeContract) Serialize() []byte {
return serializeBridgeGovernanceVaa(r.Module, 2, r.TargetChainID, r.NewContract)
return serializeBridgeGovernanceVaa(r.Module, 2, r.TargetChainID, r.NewContract[:])
}

func (r BodyWormchainStoreCode) Serialize() []byte {
return serializeBridgeGovernanceVaa(WasmdModuleStr, ActionStoreCode, ChainIDWormchain, r.WasmHash)
return serializeBridgeGovernanceVaa(WasmdModuleStr, ActionStoreCode, ChainIDWormchain, r.WasmHash[:])
}

func (r BodyWormchainInstantiateContract) Serialize() []byte {
return serializeBridgeGovernanceVaa(WasmdModuleStr, ActionInstantiateContract, ChainIDWormchain, r.InstantiationParamsHash)
return serializeBridgeGovernanceVaa(WasmdModuleStr, ActionInstantiateContract, ChainIDWormchain, r.InstantiationParamsHash[:])
}

func serializeBridgeGovernanceVaa(module string, actionId GovernanceAction, chainId ChainID, payload [32]byte) []byte {
func serializeBridgeGovernanceVaa(module string, actionId GovernanceAction, chainId ChainID, payload []byte) []byte {
if len(module) > 32 {
panic("module longer than 32 byte")
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/vaa/payloads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestBodyContractUpgradeSerialize(t *testing.T) {
bodyContractUpgrade := BodyContractUpgrade{ChainID: 1, NewContract: addr}
expected := "00000000000000000000000000000000000000000000000000000000436f72650100010000000000000000000000000000000000000000000000000000000000000004"
serializedBodyContractUpgrade := bodyContractUpgrade.Serialize()
assert.Equal(t, hex.EncodeToString(serializedBodyContractUpgrade), expected)
assert.Equal(t, expected, hex.EncodeToString(serializedBodyContractUpgrade))
}

func TestBodyGuardianSetUpdateSerialize(t *testing.T) {
Expand All @@ -64,7 +64,7 @@ func TestBodyGuardianSetUpdateSerialize(t *testing.T) {
bodyGuardianSetUpdate := BodyGuardianSetUpdate{Keys: keys, NewIndex: uint32(1)}
expected := "00000000000000000000000000000000000000000000000000000000436f726502000000000001025aaeb6053f3e94c9b9a09f33669435e7ef1beaed5aaeb6053f3e94c9b9a09f33669435e7ef1beaee"
serializedBodyGuardianSetUpdate := bodyGuardianSetUpdate.Serialize()
assert.Equal(t, hex.EncodeToString(serializedBodyGuardianSetUpdate), expected)
assert.Equal(t, expected, hex.EncodeToString(serializedBodyGuardianSetUpdate))
}

func TestBodyTokenBridgeRegisterChainSerialize(t *testing.T) {
Expand All @@ -73,7 +73,7 @@ func TestBodyTokenBridgeRegisterChainSerialize(t *testing.T) {
bodyTokenBridgeRegisterChain := BodyTokenBridgeRegisterChain{Module: module, ChainID: 1, EmitterAddress: addr}
expected := "000000000000000000000000000000000000000000000000000000007465737401000000010000000000000000000000000000000000000000000000000000000000000004"
serializedBodyTokenBridgeRegisterChain := bodyTokenBridgeRegisterChain.Serialize()
assert.Equal(t, hex.EncodeToString(serializedBodyTokenBridgeRegisterChain), expected)
assert.Equal(t, expected, hex.EncodeToString(serializedBodyTokenBridgeRegisterChain))
}

func TestBodyTokenBridgeUpgradeContractSerialize(t *testing.T) {
Expand All @@ -82,5 +82,5 @@ func TestBodyTokenBridgeUpgradeContractSerialize(t *testing.T) {
bodyTokenBridgeUpgradeContract := BodyTokenBridgeUpgradeContract{Module: module, TargetChainID: 1, NewContract: addr}
expected := "00000000000000000000000000000000000000000000000000000000746573740200010000000000000000000000000000000000000000000000000000000000000004"
serializedBodyTokenBridgeUpgradeContract := bodyTokenBridgeUpgradeContract.Serialize()
assert.Equal(t, hex.EncodeToString(serializedBodyTokenBridgeUpgradeContract), expected)
assert.Equal(t, expected, hex.EncodeToString(serializedBodyTokenBridgeUpgradeContract))
}

0 comments on commit 82651e4

Please sign in to comment.