コード例 #1
0
ファイル: adminBlock.go プロジェクト: FactomProject/factomd
func (c *AdminBlock) AddFederatedServerBitcoinAnchorKey(identityChainID interfaces.IHash, keyPriority byte, keyType byte, ecdsaPublicKey *[20]byte) error {
	b := new(primitives.ByteSlice20)
	err := b.UnmarshalBinary(ecdsaPublicKey[:])
	if err != nil {
		return err
	} else {
		entry := NewAddFederatedServerBitcoinAnchorKey(identityChainID, keyPriority, keyType, *b)
		c.AddEntry(entry)
		return nil
	}
}
func TestAddFederatedServerBitcoinAnchorKeyMarshalUnmarshal(t *testing.T) {
	identity := testHelper.NewRepeatingHash(0xAB)
	pub := new(primitives.ByteSlice20)
	err := pub.UnmarshalBinary(testHelper.NewRepeatingHash(0xCD).Bytes())
	if err != nil {
		t.Error(err)
	}
	var keyPriority byte = 3
	var keyType byte = 1

	afsk := NewAddFederatedServerBitcoinAnchorKey(identity, keyPriority, keyType, *pub)
	if afsk.Type() != constants.TYPE_ADD_BTC_ANCHOR_KEY {
		t.Errorf("Invalid type")
	}
	if afsk.IdentityChainID.IsSameAs(identity) == false {
		t.Errorf("Invalid IdentityChainID")
	}
	if afsk.KeyPriority != keyPriority {
		t.Errorf("Invalid KeyPriority")
	}
	if afsk.KeyType != keyType {
		t.Errorf("Invalid KeyType")
	}
	if afsk.ECDSAPublicKey.String() != pub.String() {
		t.Errorf("Invalid ECDSAPublicKey")
	}
	tmp2, err := afsk.MarshalBinary()
	if err != nil {
		t.Error(err)
	}

	afsk = new(AddFederatedServerBitcoinAnchorKey)
	err = afsk.UnmarshalBinary(tmp2)
	if err != nil {
		t.Error(err)
	}
	if afsk.IdentityChainID.IsSameAs(identity) == false {
		t.Errorf("Invalid IdentityChainID")
	}
	if afsk.KeyPriority != keyPriority {
		t.Errorf("Invalid KeyPriority")
	}
	if afsk.KeyType != keyType {
		t.Errorf("Invalid KeyType")
	}
	if afsk.ECDSAPublicKey.String() != pub.String() {
		t.Errorf("Invalid ECDSAPublicKey")
	}
}