Skip to content

Commit bf5ceb5

Browse files
bruce-rileyevan-gray
authored andcommitted
Add admin command tests
1 parent e4931fe commit bf5ceb5

File tree

3 files changed

+1169
-1
lines changed

3 files changed

+1169
-1
lines changed

node/cmd/guardiand/admintemplate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ func runWormchainMigrateContractTemplate(cmd *cobra.Command, args []string) {
717717
log.Fatal("--contract-address must be specified.")
718718
}
719719
if *wormchainMigrateContractInstantiationMsg == "" {
720-
log.Fatal("--instantiate-msg must be specified.")
720+
log.Fatal("--instantiation-msg must be specified.")
721721
}
722722

723723
m := &nodev1.InjectGovernanceVAARequest{

node/pkg/adminrpc/adminserver_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package adminrpc
33

44
import (
5+
"bytes"
56
"context"
67
"crypto/ecdsa"
78
"testing"
@@ -17,9 +18,11 @@ import (
1718
"github.com/ethereum/go-ethereum/ethclient"
1819
"github.com/ethereum/go-ethereum/event"
1920
ethRpc "github.com/ethereum/go-ethereum/rpc"
21+
"github.com/stretchr/testify/assert"
2022
"github.com/stretchr/testify/require"
2123
"github.com/wormhole-foundation/wormhole/sdk/vaa"
2224
"go.uber.org/zap"
25+
"google.golang.org/protobuf/encoding/prototext"
2326
)
2427

2528
type mockEVMConnector struct {
@@ -270,3 +273,47 @@ func TestSignExistingVAA_Valid(t *testing.T) {
270273
v2 := generateMockVAA(1, append(gsKeys, s.gk))
271274
require.Equal(t, v2, res.Vaa)
272275
}
276+
277+
const govGuardianSetIndex = uint32(4)
278+
279+
var govTimestamp = time.Now()
280+
281+
const govEmitterChain = vaa.ChainIDSolana
282+
283+
var govEmitterAddr vaa.Address = [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4}
284+
285+
// verifyGovernanceVAA verifies the VAA fields of a generated governance VAA. Note that it doesn't verify the payload because that is
286+
// already verified in `sdk/vaa/payload_test` and we don't want to duplicate all those arrays.
287+
func verifyGovernanceVAA(t *testing.T, v *vaa.VAA, expectedSeqNo uint64, expectedNonce uint32) {
288+
t.Helper()
289+
require.NotNil(t, v)
290+
assert.Equal(t, uint8(vaa.SupportedVAAVersion), v.Version)
291+
assert.Equal(t, govGuardianSetIndex, v.GuardianSetIndex)
292+
assert.Nil(t, v.Signatures)
293+
assert.Equal(t, govTimestamp, v.Timestamp)
294+
assert.Equal(t, expectedNonce, v.Nonce)
295+
assert.Equal(t, expectedSeqNo, v.Sequence)
296+
assert.Equal(t, uint8(32), v.ConsistencyLevel)
297+
assert.Equal(t, govEmitterChain, v.EmitterChain)
298+
assert.True(t, bytes.Equal(govEmitterAddr[:], v.EmitterAddress[:]))
299+
}
300+
301+
// Test_adminCommands executes all of the tests in prototext_test.go, unmarshaling the prototext and feeding it into `GovMsgToVaa`.
302+
func Test_adminCommands(t *testing.T) {
303+
for _, tst := range adminCommandTest {
304+
t.Run(tst.label, func(t *testing.T) {
305+
var msg nodev1.InjectGovernanceVAARequest
306+
err := prototext.Unmarshal([]byte(tst.prototext), &msg)
307+
require.NoError(t, err)
308+
require.Equal(t, 1, len(msg.Messages))
309+
govMsg := msg.Messages[0]
310+
vaa, err := GovMsgToVaa(govMsg, govGuardianSetIndex, govTimestamp)
311+
if tst.errText == "" {
312+
require.NoError(t, err)
313+
verifyGovernanceVAA(t, vaa, govMsg.Sequence, govMsg.Nonce)
314+
} else {
315+
require.ErrorContains(t, err, tst.errText)
316+
}
317+
})
318+
}
319+
}

0 commit comments

Comments
 (0)