2
2
package adminrpc
3
3
4
4
import (
5
+ "bytes"
5
6
"context"
6
7
"crypto/ecdsa"
7
8
"testing"
@@ -17,9 +18,11 @@ import (
17
18
"github.com/ethereum/go-ethereum/ethclient"
18
19
"github.com/ethereum/go-ethereum/event"
19
20
ethRpc "github.com/ethereum/go-ethereum/rpc"
21
+ "github.com/stretchr/testify/assert"
20
22
"github.com/stretchr/testify/require"
21
23
"github.com/wormhole-foundation/wormhole/sdk/vaa"
22
24
"go.uber.org/zap"
25
+ "google.golang.org/protobuf/encoding/prototext"
23
26
)
24
27
25
28
type mockEVMConnector struct {
@@ -270,3 +273,47 @@ func TestSignExistingVAA_Valid(t *testing.T) {
270
273
v2 := generateMockVAA (1 , append (gsKeys , s .gk ))
271
274
require .Equal (t , v2 , res .Vaa )
272
275
}
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