2018-03-25 10:45:54 +00:00
|
|
|
package smartcontract
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-08-27 13:29:42 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/crypto/keys"
|
2018-03-25 10:45:54 +00:00
|
|
|
"github.com/CityOfZion/neo-go/pkg/util"
|
|
|
|
"github.com/CityOfZion/neo-go/pkg/vm"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCreateMultiSigRedeemScript(t *testing.T) {
|
2019-08-27 13:29:42 +00:00
|
|
|
val1, _ := keys.NewPublicKeyFromString("03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c")
|
|
|
|
val2, _ := keys.NewPublicKeyFromString("02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093")
|
|
|
|
val3, _ := keys.NewPublicKeyFromString("03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a")
|
2018-03-25 10:45:54 +00:00
|
|
|
|
2019-08-27 13:29:42 +00:00
|
|
|
validators := []*keys.PublicKey{val1, val2, val3}
|
2018-03-25 10:45:54 +00:00
|
|
|
|
|
|
|
out, err := CreateMultiSigRedeemScript(3, validators)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-09-15 11:58:19 +00:00
|
|
|
br := util.NewBinReaderFromBuf(out)
|
2019-08-28 16:34:38 +00:00
|
|
|
var b uint8
|
|
|
|
br.ReadLE(&b)
|
2019-08-14 12:40:31 +00:00
|
|
|
assert.Equal(t, vm.PUSH3, vm.Instruction(b))
|
2018-03-25 10:45:54 +00:00
|
|
|
|
|
|
|
for i := 0; i < len(validators); i++ {
|
2019-08-28 16:34:38 +00:00
|
|
|
bb := br.ReadBytes()
|
2018-03-25 10:45:54 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-08-28 16:34:38 +00:00
|
|
|
assert.Equal(t, validators[i].Bytes(), bb)
|
2018-03-25 10:45:54 +00:00
|
|
|
}
|
|
|
|
|
2019-08-28 16:34:38 +00:00
|
|
|
br.ReadLE(&b)
|
2019-08-14 12:40:31 +00:00
|
|
|
assert.Equal(t, vm.PUSH3, vm.Instruction(b))
|
2019-08-28 16:34:38 +00:00
|
|
|
br.ReadLE(&b)
|
2019-08-14 12:40:31 +00:00
|
|
|
assert.Equal(t, vm.CHECKMULTISIG, vm.Instruction(b))
|
2018-03-25 10:45:54 +00:00
|
|
|
}
|