Skip to content

Commit

Permalink
fix: keys tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whalelephant committed Aug 8, 2021
1 parent 79c9c29 commit 586e354
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 27 deletions.
12 changes: 12 additions & 0 deletions lib/go/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import (
"github.com/onflow/cadence"
)

func ContainsKey(g *gwtf.GoWithTheFlow, resourceAcct string, key string) (result bool, err error) {
keys, err := util.GetStoreKeys(g, resourceAcct)
result = false
for _, k := range keys {
if k == key {
result = true
return
}
}
return
}

func MultiSig_NewRemoveSignerPayload(
g *gwtf.GoWithTheFlow,
acctToRemove string,
Expand Down
37 changes: 10 additions & 27 deletions lib/go/keys/keys_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keys

import (
"strconv"
"testing"

"github.com/bjartek/go-with-the-flow/gwtf"
Expand All @@ -15,40 +14,27 @@ func TestAddNewPendingKeyRemoval(t *testing.T) {

vaultAcct := "vaulted-account"
payerAcct := "owner"
removedPk := g.Accounts[vault.Acct500_1].PrivateKey.PublicKey().String()[2:]

initTxIndex, err := util.GetTxIndex(g, vaultAcct)
hasKey, err := ContainsKey(g, vaultAcct, removedPk)
assert.NoError(t, err)
assert.Equal(t, hasKey, true)

events, err := MultiSig_NewRemoveSignerPayload(g, vault.Acct500_1, vault.Acct1000, vaultAcct)
_, err = MultiSig_NewRemoveSignerPayload(g, vault.Acct500_1, vault.Acct1000, vaultAcct)
assert.NoError(t, err)

postTxIndex, err := util.GetTxIndex(g, vaultAcct)
assert.NoError(t, err)
assert.Equal(t, uint64(1), postTxIndex-initTxIndex)

uuid, err := util.GetVaultUUID(g, vaultAcct)
assert.NoError(t, err)

util.NewExpectedEvent("OnChainMultiSig", "NewPayloadAdded").
AddField("resourceId", strconv.Itoa(int(uuid))).
AddField("txIndex", strconv.Itoa(int(postTxIndex))).
AssertEqual(t, events[0])

_, err = vault.MultiSig_VaultExecuteTx(g, postTxIndex, payerAcct, vaultAcct)
assert.NoError(t, err)

removedPk := g.Accounts[vault.Acct500_1].PrivateKey.PublicKey().String()[2:]
keys, err := util.GetStoreKeys(g, vaultAcct)
var removed bool = true
for _, key := range keys {
if key == removedPk {
removed = false
}
}
assert.Equal(t, removed, true)
hasKey, err = ContainsKey(g, vaultAcct, removedPk)
assert.NoError(t, err)
assert.Equal(t, hasKey, false)
}

func TestRemovaledKeyCannotAddSig(t *testing.T) {
func TestRemovedKeyCannotAddSig(t *testing.T) {
g := gwtf.NewGoWithTheFlow("../../../flow.json")

vaultAcct := "vaulted-account"
Expand All @@ -66,19 +52,16 @@ func TestAddNewPendingKeyConfig(t *testing.T) {
newAcct := vault.Acct500_1
newAcctWeight := "100.00000000"

initTxIndex, err := util.GetTxIndex(g, vaultAcct)
assert.NoError(t, err)

_, err = MultiSig_NewConfigSignerPayload(g, newAcct, newAcctWeight, vault.Acct1000, vaultAcct)
_, err := MultiSig_NewConfigSignerPayload(g, newAcct, newAcctWeight, vault.Acct1000, vaultAcct)
assert.NoError(t, err)

postTxIndex, err := util.GetTxIndex(g, vaultAcct)
assert.NoError(t, err)
assert.Equal(t, uint64(1), postTxIndex-initTxIndex)

_, err = vault.MultiSig_VaultExecuteTx(g, postTxIndex, payerAcct, vaultAcct)
assert.NoError(t, err)

weight, err := util.GetKeyWeight(g, vaultAcct, newAcct)
assert.NoError(t, err)
assert.Equal(t, newAcctWeight, weight.String())
}

0 comments on commit 586e354

Please sign in to comment.