github.com/koko1123/flow-go-1@v0.29.6/model/flow/account_encoder_test.go (about) 1 package flow_test 2 3 import ( 4 "encoding/hex" 5 "testing" 6 7 "github.com/ethereum/go-ethereum/rlp" 8 "github.com/stretchr/testify/assert" 9 "github.com/stretchr/testify/require" 10 11 "github.com/koko1123/flow-go-1/model/flow" 12 "github.com/onflow/flow-go/crypto" 13 "github.com/onflow/flow-go/crypto/hash" 14 ) 15 16 type legacyAccountPublicKeyWrapper struct { 17 PublicKey []byte 18 SignAlgo uint 19 HashAlgo uint 20 Weight uint 21 SeqNumber uint64 22 // "Revoked" field intentionally omitted 23 } 24 25 func TestDecodeAccountPublicKey_Legacy(t *testing.T) { 26 publicKeyBytes, err := hex.DecodeString("98fd858d00b995cc9d67ec6c140f0fc26fcf7895621b3bf2661ea7b99e54f8cebd9143b50d21e6854187f895db7b6c7ec3032be5047b3652a0c2686e5b97de48") 27 require.NoError(t, err) 28 29 publicKey, err := crypto.DecodePublicKey(crypto.ECDSAP256, publicKeyBytes) 30 require.NoError(t, err) 31 32 sigAlgo := crypto.ECDSAP256 33 hashAlgo := hash.SHA3_256 34 weight := 1000 35 sequenceNumber := uint64(42) 36 37 // manually encode key in legacy format 38 w := legacyAccountPublicKeyWrapper{ 39 PublicKey: publicKey.Encode(), 40 SignAlgo: uint(crypto.ECDSAP256), 41 HashAlgo: uint(hash.SHA3_256), 42 Weight: uint(weight), 43 SeqNumber: sequenceNumber, 44 } 45 46 b, err := rlp.EncodeToBytes(&w) 47 require.NoError(t, err) 48 49 accountKey, err := flow.DecodeAccountPublicKey(b, 1) 50 require.NoError(t, err) 51 52 assert.Equal(t, 1, accountKey.Index) 53 assert.Equal(t, publicKey, accountKey.PublicKey) 54 assert.Equal(t, sigAlgo, accountKey.SignAlgo) 55 assert.Equal(t, hashAlgo, accountKey.HashAlgo) 56 assert.Equal(t, weight, accountKey.Weight) 57 assert.Equal(t, sequenceNumber, accountKey.SeqNumber) 58 59 // legacy account key should not be revoked 60 assert.False(t, accountKey.Revoked) 61 }