-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
083bc30
commit 79c9c29
Showing
10 changed files
with
301 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package keys | ||
|
||
import ( | ||
"github.com/bjartek/go-with-the-flow/gwtf" | ||
util "github.com/flow-hydraulics/onchain-multisig" | ||
"github.com/onflow/cadence" | ||
) | ||
|
||
func MultiSig_NewRemoveSignerPayload( | ||
g *gwtf.GoWithTheFlow, | ||
acctToRemove string, | ||
signerAcct string, | ||
vaultAcct string, | ||
) (events []*gwtf.FormatedEvent, err error) { | ||
txFilename := "../../../transactions/new_pending_remove_multisig_key.cdc" | ||
txScript := util.ParseCadenceTemplate(txFilename) | ||
|
||
method := "removeKey" | ||
pkToRemove := g.Accounts[acctToRemove].PrivateKey.PublicKey().String() | ||
signable, err := util.GetSignableDataFromScript(g, method, cadence.NewString(pkToRemove[2:])) | ||
if err != nil { | ||
return | ||
} | ||
|
||
sig, err := util.SignPayloadOffline(g, signable, signerAcct) | ||
if err != nil { | ||
return | ||
} | ||
|
||
signerPubKey := g.Accounts[signerAcct].PrivateKey.PublicKey().String() | ||
e, err := g.TransactionFromFile(txFilename, txScript). | ||
SignProposeAndPayAs(signerAcct). | ||
StringArgument(signerPubKey[2:]). | ||
StringArgument(sig). | ||
AccountArgument(vaultAcct). | ||
StringArgument(method). | ||
StringArgument(pkToRemove[2:]). | ||
Run() | ||
events = util.ParseTestEvents(e) | ||
return | ||
} | ||
|
||
func MultiSig_NewRemoveKeyPayloadSignature( | ||
g *gwtf.GoWithTheFlow, | ||
acctToRemove string, | ||
txIndex uint64, | ||
signerAcct string, | ||
vaultAcct string, | ||
) (events []*gwtf.FormatedEvent, err error) { | ||
method := "removeKey" | ||
pkToRemove := g.Accounts[acctToRemove].PrivateKey.PublicKey().String() | ||
signable, err := util.GetSignableDataFromScript(g, method, cadence.NewString(pkToRemove[2:])) | ||
if err != nil { | ||
return | ||
} | ||
|
||
sig, err := util.SignPayloadOffline(g, signable, signerAcct) | ||
if err != nil { | ||
return | ||
} | ||
|
||
return util.MultiSigVault_NewPayloadSignature(g, txIndex, sig, signerAcct, vaultAcct) | ||
} | ||
|
||
func MultiSig_NewConfigSignerPayload( | ||
g *gwtf.GoWithTheFlow, | ||
acctToConfig string, | ||
acctToConfigWeight string, | ||
signerAcct string, | ||
vaultAcct string, | ||
) (events []*gwtf.FormatedEvent, err error) { | ||
txFilename := "../../../transactions/new_pending_config_multisig_key.cdc" | ||
txScript := util.ParseCadenceTemplate(txFilename) | ||
|
||
method := "configureKey" | ||
pkToConfig := g.Accounts[acctToConfig].PrivateKey.PublicKey().String() | ||
weightToConfig, err := cadence.NewUFix64(acctToConfigWeight) | ||
if err != nil { | ||
return | ||
} | ||
signable, err := util.GetSignableDataFromScript(g, method, cadence.NewString(pkToConfig[2:]), weightToConfig) | ||
if err != nil { | ||
return | ||
} | ||
|
||
sig, err := util.SignPayloadOffline(g, signable, signerAcct) | ||
if err != nil { | ||
return | ||
} | ||
|
||
signerPubKey := g.Accounts[signerAcct].PrivateKey.PublicKey().String() | ||
e, err := g.TransactionFromFile(txFilename, txScript). | ||
SignProposeAndPayAs(signerAcct). | ||
StringArgument(signerPubKey[2:]). | ||
StringArgument(sig). | ||
AccountArgument(vaultAcct). | ||
StringArgument(method). | ||
StringArgument(pkToConfig[2:]). | ||
UFix64Argument(acctToConfigWeight). | ||
Run() | ||
events = util.ParseTestEvents(e) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package keys | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/bjartek/go-with-the-flow/gwtf" | ||
util "github.com/flow-hydraulics/onchain-multisig" | ||
"github.com/flow-hydraulics/onchain-multisig/vault" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAddNewPendingKeyRemoval(t *testing.T) { | ||
g := gwtf.NewGoWithTheFlow("../../../flow.json") | ||
|
||
vaultAcct := "vaulted-account" | ||
payerAcct := "owner" | ||
|
||
initTxIndex, err := util.GetTxIndex(g, vaultAcct) | ||
assert.NoError(t, err) | ||
|
||
events, 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) | ||
} | ||
|
||
func TestRemovaledKeyCannotAddSig(t *testing.T) { | ||
g := gwtf.NewGoWithTheFlow("../../../flow.json") | ||
|
||
vaultAcct := "vaulted-account" | ||
removedAcct := vault.Acct500_1 | ||
|
||
_, err := MultiSig_NewRemoveKeyPayloadSignature(g, removedAcct, 1, removedAcct, vaultAcct) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestAddNewPendingKeyConfig(t *testing.T) { | ||
g := gwtf.NewGoWithTheFlow("../../../flow.json") | ||
|
||
vaultAcct := "vaulted-account" | ||
payerAcct := "owner" | ||
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) | ||
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.Equal(t, newAcctWeight, weight.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,4 @@ go clean -testcache | |
|
||
go run scripts/deploy/deploy.go | ||
go test ./vault -v | ||
go test ./keys -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// This script reads the balance field of an account's Balance | ||
import FungibleToken from 0x{{.FungibleToken}} | ||
import OnChainMultiSig from 0x{{.OnChainMultiSig}} | ||
import MultiSigFlowToken from 0x{{.MultiSigFlowToken}} | ||
|
||
pub fun main(account: Address, key: String): UFix64 { | ||
let acct = getAccount(account) | ||
let vaultRef = acct.getCapability(MultiSigFlowToken.VaultPubSigner) | ||
.borrow<&MultiSigFlowToken.Vault{OnChainMultiSig.PublicSigner}>() | ||
?? panic("Could not borrow Pub Signer reference to the Vault") | ||
|
||
let attr = vaultRef.signatureStore!.keyList[key]! | ||
return attr.weight | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Masterminter uses this to configure which minter the minter controller manages | ||
import MultiSigFlowToken from 0x{{.MultiSigFlowToken}} | ||
import OnChainMultiSig from 0x{{.OnChainMultiSig}} | ||
|
||
transaction (publicKey: String, sig: String, addr: Address, method: String, pubKeyToConfig: String, weight: UFix64) { | ||
prepare(oneOfMultiSig: AuthAccount) { | ||
} | ||
|
||
execute { | ||
let vaultedAcct = getAccount(addr) | ||
|
||
let pubSigRef = vaultedAcct.getCapability(MultiSigFlowToken.VaultPubSigner) | ||
.borrow<&MultiSigFlowToken.Vault{OnChainMultiSig.PublicSigner}>() | ||
?? panic("Could not borrow vault pub sig reference") | ||
|
||
let pk = OnChainMultiSig.PayloadArg(t: Type<String>(), v: pubKeyToConfig); | ||
let w = OnChainMultiSig.PayloadArg(t: Type<UFix64>(), v: weight); | ||
let p = OnChainMultiSig.PayloadDetails(method: method, args: [pk, w]); | ||
return pubSigRef.addNewPayload(payload: p, publicKey: publicKey, sig: sig.decodeHex()) | ||
} | ||
} |
Oops, something went wrong.