Skip to content

Commit

Permalink
Merge pull request #416 from iov-one/multisig_support_voting_weight_i…
Browse files Browse the repository at this point in the history
…ssue_285

 Extend multisig contract with weights
  • Loading branch information
husio authored Mar 21, 2019
2 parents a849904 + 21a8610 commit a921d89
Show file tree
Hide file tree
Showing 17 changed files with 952 additions and 567 deletions.
44 changes: 34 additions & 10 deletions cmd/bcpd/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func withWalletAppState(t require.TestingT, accounts []*account) string {
type contract struct {
id []byte
accountSigs []*account
threshold int64
threshold multisig.Weight
}

func (c *contract) address() []byte {
Expand Down Expand Up @@ -390,11 +390,28 @@ func sendBatch(t require.TestingT, fail bool, baseApp app.BaseApp, chainID strin

// createContract creates an immutable contract, signs the transaction and sends it
// checks contract has been created correctly
func createContract(t require.TestingT, baseApp app.BaseApp, chainID string, height int64, signers []*account, activationThreshold int64, contractSigs ...[]byte) []byte {
func createContract(
t testing.TB,
baseApp app.BaseApp,
chainID string,
height int64,
signers []*account,
activationThreshold multisig.Weight,
contractSigs ...[]byte,
) []byte {
t.Helper()

participants := make([]*multisig.Participant, len(contractSigs))
for i, addr := range contractSigs {
participants[i] = &multisig.Participant{
Signature: addr,
Power: 1,
}
}
msg := &multisig.CreateContractMsg{
Sigs: contractSigs,
Participants: participants,
ActivationThreshold: activationThreshold,
AdminThreshold: int64(len(contractSigs)) + 1, // immutable
AdminThreshold: multisig.Weight(len(contractSigs)) + 1, // immutable
}

tx := &Tx{
Expand All @@ -407,9 +424,9 @@ func createContract(t require.TestingT, baseApp app.BaseApp, chainID string, hei
contractID := dres.Data
queryAndCheckContract(t, baseApp, "/contracts", contractID,
multisig.Contract{
Sigs: contractSigs,
Participants: participants,
ActivationThreshold: activationThreshold,
AdminThreshold: int64(len(contractSigs)) + 1,
AdminThreshold: multisig.Weight(len(contractSigs)) + 1,
})

return contractID
Expand Down Expand Up @@ -541,9 +558,16 @@ func makeSendTxMultisig(t require.TestingT, chainID string, sender, receiver *co
return txBytes
}

func makeCreateContractTx(t require.TestingT, chainID string, signers [][]byte, threshold int64) *Tx {
func makeCreateContractTx(t require.TestingT, chainID string, signers [][]byte, threshold multisig.Weight) *Tx {
participants := make([]*multisig.Participant, len(signers))
for i, addr := range signers {
participants[i] = &multisig.Participant{
Signature: addr,
Power: 1,
}
}
msg := &multisig.CreateContractMsg{
Sigs: signers,
Participants: participants,
ActivationThreshold: threshold,
AdminThreshold: threshold,
}
Expand All @@ -559,7 +583,7 @@ func makeCreateContractTx(t require.TestingT, chainID string, signers [][]byte,
// N * DeliverTx
// EndBlock
// Commit
func benchmarkSendTxWithMultisig(b *testing.B, nbAccounts, blockSize, nbContracts, nbMultisigSigs int, threshold int64) {
func benchmarkSendTxWithMultisig(b *testing.B, nbAccounts, blockSize, nbContracts, nbMultisigSigs int, threshold multisig.Weight) {
id := func(i int64) []byte {
bz := make([]byte, 8)
binary.BigEndian.PutUint64(bz, uint64(i))
Expand Down Expand Up @@ -707,7 +731,7 @@ func BenchmarkSendTxMultiSig(b *testing.B) {
blockSize int
contracts int
nbSigs int
threshold int64
threshold multisig.Weight
}{
{10000, 100, 100, 2, 1},
{10000, 100, 100, 10, 5},
Expand Down
26 changes: 20 additions & 6 deletions cmd/bnsd/app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,26 @@ func sendToken(t *testing.T, baseApp weaveApp.BaseApp, chainID string, height in

// createContract creates an immutable contract, signs the transaction and sends it
// checks contract has been created correctly
func createContract(t *testing.T, baseApp weaveApp.BaseApp, chainID string, height int64, signers []Signer,
activationThreshold int64, contractSigs ...[]byte) []byte {
func createContract(
t *testing.T,
baseApp weaveApp.BaseApp,
chainID string,
height int64,
signers []Signer,
activationThreshold multisig.Weight,
contractSigs ...[]byte,
) []byte {
participants := make([]*multisig.Participant, len(contractSigs))
for i, addr := range contractSigs {
participants[i] = &multisig.Participant{
Signature: addr,
Power: 1,
}
}
msg := &multisig.CreateContractMsg{
Sigs: contractSigs,
Participants: participants,
ActivationThreshold: activationThreshold,
AdminThreshold: int64(len(contractSigs)) + 1, // immutable
AdminThreshold: multisig.Weight(len(contractSigs)) + 1, // immutable
}

tx := &app.Tx{
Expand All @@ -173,9 +187,9 @@ func createContract(t *testing.T, baseApp weaveApp.BaseApp, chainID string, heig
contractID := dres.Data
queryAndCheckContract(t, baseApp, "/contracts", contractID,
multisig.Contract{
Sigs: contractSigs,
Participants: participants,
ActivationThreshold: activationThreshold,
AdminThreshold: int64(len(contractSigs)) + 1,
AdminThreshold: multisig.Weight(len(contractSigs)) + 1,
})

return contractID
Expand Down
4 changes: 3 additions & 1 deletion cmd/bnsd/scenarios/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ func initGenesis(filename string, addr weave.Address) (*tm.GenesisDoc, error) {
},
"multisig": []interface{}{
dict{
"sigs": []weave.Address{addr},
"participants": []interface{}{
dict{"power": 1, "signature": addr},
},
"activation_threshold": 1,
"admin_threshold": 1,
},
Expand Down
4 changes: 3 additions & 1 deletion weavetest/handlers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package weavetest

import "github.com/iov-one/weave"
import (
"github.com/iov-one/weave"
)

// Handler implements a mock of weave.Handler
//
Expand Down
4 changes: 2 additions & 2 deletions weavetest/results.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a921d89

Please sign in to comment.