Skip to content

Commit 616ca16

Browse files
Parse account storage (#323)
* Parse account storage * Parse account storage * fix test * fix test * use jsoncdc on account storage * return empty strings on err
1 parent 06bde90 commit 616ca16

File tree

5 files changed

+7
-64
lines changed

5 files changed

+7
-64
lines changed

blockchain/flowkit.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,11 @@ func (fk *flowKit) getAccountStorage(address flow.Address) (string, error) {
413413
return "", err
414414
}
415415

416-
/* TODO: Parse account storage
417-
_, err = ParseAccountStorage(val)
416+
storage, err := jsoncdc.Encode(val)
418417
if err != nil {
419418
return "", err
420419
}
421-
*/
422-
423-
return val.String(), nil
420+
return string(storage), nil
424421
}
425422

426423
func (fk *flowKit) getAccount(address flow.Address) (*flow.Account, error) {

blockchain/flowkit_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ func Test_NewFlowkit(t *testing.T) {
6666
assert.NoError(t, err)
6767

6868
assert.Equal(t, account.Address, accountList[i].Address)
69-
assert.Contains(t, accountStorage, "A.0000000000000003.FlowToken.Vault(uuid:")
70-
assert.Contains(t, accountStorage, `"path": /storage/flowTokenVault`)
69+
assert.Contains(t, accountStorage, "A.0000000000000003.FlowToken.Vault")
7170
}
7271
}
7372

blockchain/storage.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818

1919
package blockchain
2020

21-
type AccountStorage any
22-
23-
type StorageItem struct {
24-
Value interface{}
25-
Type interface{}
26-
Path interface{}
27-
}
28-
2921
const StorageIteration = `
3022
pub fun main(address: Address) : AnyStruct{
3123
@@ -64,26 +56,3 @@ pub fun main(address: Address) : AnyStruct{
6456
})
6557
return res
6658
}`
67-
68-
//type StorageItem map[interface{}]interface{}
69-
70-
/* TODO: Parse account storage into a useful format or structure
71-
func ParseAccountStorage(rawStorage cadence.Value) (*AccountStorage, error) {
72-
encoded, err := jsoncdc.Encode(rawStorage)
73-
if err != nil {
74-
return nil, err
75-
}
76-
77-
var storage AccountStorage
78-
err = yaml.Unmarshal(encoded, &storage)
79-
if err != nil {
80-
fmt.Println("ERROR Unmarshal", err.Error())
81-
}
82-
83-
for key, val := range storage.(map[interface{}]interface{}) {
84-
fmt.Println("Key, val:", key, ",", val)
85-
}
86-
87-
return nil, nil
88-
}
89-
*/

e2eTest/account_test.go

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package e2eTest
2020

2121
import (
22-
"encoding/json"
2322
"github.com/dapperlabs/flow-playground-api/e2eTest/client"
2423
"github.com/stretchr/testify/assert"
2524
"github.com/stretchr/testify/require"
@@ -80,8 +79,6 @@ func TestAccountDeployedContracts(t *testing.T) {
8079
}
8180

8281
func TestAccountStorage(t *testing.T) {
83-
t.Skip("Account storage parsing not implemented with FlowKit") // TODO: Add back account storage
84-
8582
c := newClient()
8683

8784
project := createProject(t, c)
@@ -96,12 +93,9 @@ func TestAccountStorage(t *testing.T) {
9693
client.Var("address", account.Address),
9794
)
9895
require.NoError(t, err)
99-
10096
assert.Equal(t, account.Address, accResp.Account.Address)
101-
assert.Equal(t, `{}`, accResp.Account.State)
10297

10398
var resp CreateTransactionExecutionResponse
104-
10599
const script = `
106100
transaction {
107101
prepare(signer: AuthAccount) {
@@ -128,25 +122,9 @@ func TestAccountStorage(t *testing.T) {
128122
client.Var("address", account.Address),
129123
)
130124
require.NoError(t, err)
131-
132125
assert.Equal(t, account.Address, accResp.Account.Address)
133-
assert.NotEmpty(t, accResp.Account.State)
134-
135-
type accountStorage struct {
136-
Private map[string]any
137-
Public map[string]any
138-
Storage map[string]any
139-
}
140-
141-
var accStorage accountStorage
142-
err = json.Unmarshal([]byte(accResp.Account.State), &accStorage)
143-
require.NoError(t, err)
144-
145-
assert.Equal(t, "storage value", accStorage.Storage["storageTest"])
146-
assert.NotEmpty(t, accStorage.Private["privateTest"])
147-
assert.NotEmpty(t, accStorage.Public["publicTest"])
148126

149-
assert.NotContains(t, accStorage.Public, "flowTokenBalance")
150-
assert.NotContains(t, accStorage.Public, "flowTokenReceiver")
151-
assert.NotContains(t, accStorage.Storage, "flowTokenVault")
127+
assert.Contains(t, accResp.Account.State, `storageTest`)
128+
assert.Contains(t, accResp.Account.State, `publicTest`)
129+
assert.Contains(t, accResp.Account.State, `privateTest`)
152130
}

e2eTest/contract_deployments_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func TestContractRedeployment(t *testing.T) {
355355
require.NoError(t, err)
356356
require.Contains(t,
357357
accResp.Account.State,
358-
`{"value": A.0000000000000005.Person.Friendship`)
358+
`A.0000000000000005.Person.Friendship`)
359359

360360
PersonContractUpdate := `
361361
pub contract Person {

0 commit comments

Comments
 (0)