|
| 1 | +package test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/onflow/flow-go-sdk/crypto" |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + |
| 9 | + "github.com/onflow/flow-go-sdk" |
| 10 | + "github.com/sideninja/flow-cli/models" |
| 11 | +) |
| 12 | + |
| 13 | +var sigAlgo = crypto.StringToSignatureAlgorithm("ECDSA_P256") |
| 14 | +var pubKey, _ = crypto.DecodePublicKeyHex(sigAlgo, "0a4c9f7bf0c8adf6ebdf4859c11d8e2867e0eaa4af6880e18a0730a0b44a494e976cefa0caf8efb7ec2da469c3f320dab4a2ca72fb340621776f4a1403ae39ed") |
| 15 | + |
| 16 | +var flowAccount = flow.Account{ |
| 17 | + Address: flow.HexToAddress("01cf0e2f2f715450"), |
| 18 | + Balance: 10, |
| 19 | + Code: nil, |
| 20 | + Keys: []*flow.AccountKey{ |
| 21 | + &flow.AccountKey{ |
| 22 | + Index: 1, |
| 23 | + PublicKey: pubKey, |
| 24 | + SigAlgo: sigAlgo, |
| 25 | + HashAlgo: crypto.HashAlgorithm(1), |
| 26 | + Weight: 1000, |
| 27 | + SequenceNumber: 1, |
| 28 | + Revoked: false, |
| 29 | + }, |
| 30 | + }, |
| 31 | +} |
| 32 | + |
| 33 | +var account = &models.Account{&flowAccount} |
| 34 | + |
| 35 | +func TestAccountEncapsulation(t *testing.T) { |
| 36 | + assert.Equal(t, account.Address.String(), "01cf0e2f2f715450") |
| 37 | + assert.Equal(t, int(account.Balance), 10) |
| 38 | +} |
| 39 | + |
| 40 | +func TestAccountStringSerialization(t *testing.T) { |
| 41 | + |
| 42 | + assert.Equal(t, account.String("address"), "01cf0e2f2f715450") |
| 43 | + assert.Equal(t, account.String("balance"), "10") |
| 44 | + assert.Equal(t, account.String("keys"), "\nKey 0\tPublic Key\t\t 0a4c9f7bf0c8adf6ebdf4859c11d8e2867e0eaa4af6880e18a0730a0b44a494e976cefa0caf8efb7ec2da469c3f320dab4a2ca72fb340621776f4a1403ae39ed\n\tWeight\t\t\t 1000\n\tSignature Algorithm\t ECDSA_P256\n\tHash Algorithm\t\t SHA2_256\n\n") |
| 45 | + |
| 46 | + assert.Equal(t, account.String(""), "\nAddress\t 01cf0e2f2f715450\nBalance\t 10\nKeys\t 1\n\nKey 0\tPublic Key\t\t 0a4c9f7bf0c8adf6ebdf4859c11d8e2867e0eaa4af6880e18a0730a0b44a494e976cefa0caf8efb7ec2da469c3f320dab4a2ca72fb340621776f4a1403ae39ed\n\tWeight\t\t\t 1000\n\tSignature Algorithm\t ECDSA_P256\n\tHash Algorithm\t\t SHA2_256\n\n\nCode\t\t \n") |
| 47 | +} |
| 48 | + |
| 49 | +func TestAccountJSONSerialization(t *testing.T) { |
| 50 | + assert.Equal(t, account.JSON(""), "{\"Address\":\"01cf0e2f2f715450\",\"Balance\":10,\"Code\":null,\"Keys\":[{\"Index\":1,\"PublicKey\":{},\"SigAlgo\":2,\"HashAlgo\":1,\"Weight\":1000,\"SequenceNumber\":1,\"Revoked\":false}],\"Contracts\":null}") |
| 51 | + assert.Equal(t, account.JSON("balance"), "{\"Balance\":10}") |
| 52 | + assert.Equal(t, account.JSON("address"), "{\"Address\":\"01cf0e2f2f715450\"}") |
| 53 | + assert.Equal(t, account.JSON("keys"), "[{\"Index\":1,\"PublicKey\":{},\"SigAlgo\":2,\"HashAlgo\":1,\"Weight\":1000,\"SequenceNumber\":1,\"Revoked\":false}]") |
| 54 | +} |
0 commit comments