Skip to content

Commit

Permalink
using authaccount to update store
Browse files Browse the repository at this point in the history
  • Loading branch information
whalelephant committed Aug 11, 2021
1 parent b4985b7 commit e598ece
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/go/vault/vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,39 @@ func MultiSig_PubUpdateStore(
events = util.ParseTestEvents(e)
return
}

func MultiSig_OwnerUpdateTxIndex(
g *gwtf.GoWithTheFlow,
index uint64,
payerAcct string,
vaultAcct string,
) (events []*gwtf.FormatedEvent, err error) {
txFilename := "../../../transactions/ownerUpdateTxIndex.cdc"
txScript := util.ParseCadenceTemplate(txFilename)

e, err := g.TransactionFromFile(txFilename, txScript).
SignProposeAndPayAs(payerAcct).
AccountArgument(vaultAcct).
UInt64Argument(index).
Run()
events = util.ParseTestEvents(e)
return
}

func MultiSig_OwnerUpdateStore(
g *gwtf.GoWithTheFlow,
index uint64,
payerAcct string,
vaultAcct string,
) (events []*gwtf.FormatedEvent, err error) {
txFilename := "../../../transactions/ownerUpdateStore.cdc"
txScript := util.ParseCadenceTemplate(txFilename)

e, err := g.TransactionFromFile(txFilename, txScript).
SignProposeAndPayAs(payerAcct).
AccountArgument(vaultAcct).
UInt64Argument(index).
Run()
events = util.ParseTestEvents(e)
return
}
28 changes: 28 additions & 0 deletions lib/go/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,31 @@ func TestPubUpdateStore(t *testing.T) {
// | ^^^^^^^^^^^^^^ consider making it publicly settable with `pub(set)`
assert.Error(t, err)
}

func TestOwnerUpdateTxIndex(t *testing.T) {
g := gwtf.NewGoWithTheFlow("../../../flow.json")
ownerAcct := "vaulted-account"
vaultAcct := "vaulted-account"

_, err := MultiSig_OwnerUpdateTxIndex(g, 11, ownerAcct, vaultAcct)
// error: cannot assign to unassignable expression
// --> cc200f93812741ff8731fe90ba0685f70ca942c9bbd62318245e1c9c4ea9bfdd:17:8
// |
// 17 | vaultRef.signatureStore!.txIndex = txIndex
// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
assert.Error(t, err)
}

func TestOwnerUpdateStore(t *testing.T) {
g := gwtf.NewGoWithTheFlow("../../../flow.json")
ownerAcct := "vaulted-account"
vaultAcct := "vaulted-account"

_, err := MultiSig_OwnerUpdateStore(g, 11, ownerAcct, vaultAcct)
// error: cannot assign to `signatureStore`: field has public access
// --> 9d6495e2eb98d399c4581b879745414ecaaa17581ef1e657239f0e14afb9534f:19:17
// |
// 19 | vaultRef.signatureStore = store
// | ^^^^^^^^^^^^^^ consider making it publicly settable with `pub(set)`
assert.Error(t, err)
}
12 changes: 12 additions & 0 deletions transactions/ownerUpdateStore.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import MultiSigFlowToken from 0x{{.MultiSigFlowToken}}
import OnChainMultiSig from 0x{{.OnChainMultiSig}}

transaction (multiSigVaultAddr: Address, txIndex: UInt64) {
prepare(owner: AuthAccount) {
let s = owner.borrow<&MultiSigFlowToken.Vault>(from: MultiSigFlowToken.VaultStoragePath) ?? panic ("cannot borrow own resource")
let store = s.signatureStore!
store.txIndex = txIndex
s.signatureStore = store
}

}
9 changes: 9 additions & 0 deletions transactions/ownerUpdateTxIndex.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import MultiSigFlowToken from 0x{{.MultiSigFlowToken}}
import OnChainMultiSig from 0x{{.OnChainMultiSig}}

transaction (multiSigVaultAddr: Address, txIndex: UInt64) {
prepare(owner: AuthAccount) {
let s = owner.borrow<&MultiSigFlowToken.Vault>(from: MultiSigFlowToken.VaultStoragePath) ?? panic ("cannot borrow own resource")
s.signatureStore!.txIndex = txIndex
}
}

0 comments on commit e598ece

Please sign in to comment.