The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/crypto/bls/bls_test.go

57 lines
1.4 KiB

package bls
import (
"testing"
"github.com/harmony-one/bls/ffi/go/bls"
"github.com/harmony-one/harmony/internal/utils"
)
// Test the basic functionality of a BLS multi-sig mask.
func TestNewMask(test *testing.T) {
_, pubKey1 := utils.GenKey("127.0.0.1", "5555")
_, pubKey2 := utils.GenKey("127.0.0.1", "6666")
_, pubKey3 := utils.GenKey("127.0.0.1", "7777")
mask, err := NewMask([]*bls.PublicKey{pubKey1, pubKey2, pubKey3}, pubKey1)
if err != nil {
test.Errorf("Failed to create a new Mask: %s", err)
}
if mask.Len() != 1 {
test.Errorf("Mask created with wrong size: %d", mask.Len())
}
enabled, err := mask.KeyEnabled(pubKey1)
if !enabled || err != nil {
test.Errorf("My key pubKey1 should have been enabled: %s", err)
}
if mask.CountEnabled() != 1 {
test.Error("Only one key should have been enabled")
}
if mask.CountTotal() != 3 {
test.Error("Should have a total of 3 keys")
}
}
func TestNewMaskWithAbsentPublicKey(test *testing.T) {
_, pubKey1 := utils.GenKey("127.0.0.1", "5555")
_, pubKey2 := utils.GenKey("127.0.0.1", "6666")
_, pubKey3 := utils.GenKey("127.0.0.1", "7777")
_, pubKey4 := utils.GenKey("127.0.0.1", "8190")
mask, err := NewMask([]*bls.PublicKey{pubKey1, pubKey2, pubKey3}, pubKey4)
if err == nil {
test.Errorf("Failed to create a new Mask: %s", err)
}
if mask != nil {
test.Errorf("Expected failure to create a new mask")
}
}