From e598ecea68b65e40436eba3286e7a5d4baae9d91 Mon Sep 17 00:00:00 2001 From: bwty Date: Wed, 11 Aug 2021 10:35:20 +0800 Subject: [PATCH] using authaccount to update store --- lib/go/vault/vault.go | 36 +++++++++++++++++++++++++++++ lib/go/vault/vault_test.go | 28 ++++++++++++++++++++++ transactions/ownerUpdateStore.cdc | 12 ++++++++++ transactions/ownerUpdateTxIndex.cdc | 9 ++++++++ 4 files changed, 85 insertions(+) create mode 100644 transactions/ownerUpdateStore.cdc create mode 100644 transactions/ownerUpdateTxIndex.cdc diff --git a/lib/go/vault/vault.go b/lib/go/vault/vault.go index b8d7115..0b73d07 100644 --- a/lib/go/vault/vault.go +++ b/lib/go/vault/vault.go @@ -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 +} diff --git a/lib/go/vault/vault_test.go b/lib/go/vault/vault_test.go index f5f048c..8e83a18 100644 --- a/lib/go/vault/vault_test.go +++ b/lib/go/vault/vault_test.go @@ -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) +} diff --git a/transactions/ownerUpdateStore.cdc b/transactions/ownerUpdateStore.cdc new file mode 100644 index 0000000..dcd1fdb --- /dev/null +++ b/transactions/ownerUpdateStore.cdc @@ -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 + } + +} diff --git a/transactions/ownerUpdateTxIndex.cdc b/transactions/ownerUpdateTxIndex.cdc new file mode 100644 index 0000000..b38fdfb --- /dev/null +++ b/transactions/ownerUpdateTxIndex.cdc @@ -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 + } +}