Skip to content

Commit 94f51af

Browse files
author
gregorgololicic
committed
account tests
1 parent 8bb318d commit 94f51af

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ require (
1010
github.com/onflow/flow-go-sdk v0.13.1
1111
github.com/spf13/cobra v1.1.1
1212
github.com/spf13/viper v1.7.0
13+
github.com/stretchr/testify v1.5.1
1314
google.golang.org/grpc v1.31.1
1415
)

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZL
342342
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw=
343343
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
344344
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
345+
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
345346
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
346347
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
347348
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=

test/account_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)