smartcontract: add CreateDefaultMultiSigRedeemScript
And use it where appropriate. Some of our code was just plain wrong (like the one in GAS contract) and unification is always useful here.
This commit is contained in:
parent
80302c5c07
commit
dba248236c
6 changed files with 62 additions and 15 deletions
|
@ -36,3 +36,50 @@ func TestCreateMultiSigRedeemScript(t *testing.T) {
|
|||
assert.Equal(t, opcode.SYSCALL, opcode.Opcode(br.ReadB()))
|
||||
assert.Equal(t, emit.InteropNameToID([]byte("Neo.Crypto.CheckMultisigWithECDsaSecp256r1")), br.ReadU32LE())
|
||||
}
|
||||
|
||||
func TestCreateDefaultMultiSigRedeemScript(t *testing.T) {
|
||||
var validators = make([]*keys.PublicKey, 0)
|
||||
|
||||
var addKey = func() {
|
||||
key, err := keys.NewPrivateKey()
|
||||
require.NoError(t, err)
|
||||
validators = append(validators, key.PublicKey())
|
||||
}
|
||||
var checkM = func(m int) {
|
||||
validScript, err := CreateMultiSigRedeemScript(m, validators)
|
||||
require.NoError(t, err)
|
||||
defaultScript, err := CreateDefaultMultiSigRedeemScript(validators)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, validScript, defaultScript)
|
||||
}
|
||||
|
||||
// 1 out of 1
|
||||
addKey()
|
||||
checkM(1)
|
||||
|
||||
// 2 out of 2
|
||||
addKey()
|
||||
checkM(2)
|
||||
|
||||
// 3 out of 4
|
||||
for i := 0; i < 2; i++ {
|
||||
addKey()
|
||||
}
|
||||
checkM(3)
|
||||
|
||||
// 5 out of 6
|
||||
for i := 0; i < 2; i++ {
|
||||
addKey()
|
||||
}
|
||||
checkM(5)
|
||||
|
||||
// 5 out of 7
|
||||
addKey()
|
||||
checkM(5)
|
||||
|
||||
// 7 out of 10
|
||||
for i := 0; i < 3; i++ {
|
||||
addKey()
|
||||
}
|
||||
checkM(7)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue