本文整理匯總了Golang中github.com/FactomProject/factomd/common/primitives.AreBytesEqual函數的典型用法代碼示例。如果您正苦於以下問題:Golang AreBytesEqual函數的具體用法?Golang AreBytesEqual怎麽用?Golang AreBytesEqual使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AreBytesEqual函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSaveLoadABlockHead
func TestSaveLoadABlockHead(t *testing.T) {
b1 := CreateTestAdminBlock(nil)
dbo := NewOverlay(new(mapdb.MapDB))
defer dbo.Close()
err := dbo.SaveABlockHead(b1)
if err != nil {
t.Error(err)
}
head, err := dbo.FetchABlockHead()
if err != nil {
t.Error(err)
}
if head == nil {
t.Error("DBlock head is nil")
}
m1, err := b1.MarshalBinary()
if err != nil {
t.Error(err)
}
m2, err := head.MarshalBinary()
if err != nil {
t.Error(err)
}
if primitives.AreBytesEqual(m1, m2) == false {
t.Error("Blocks are not equal")
}
b2 := CreateTestAdminBlock(b1)
err = dbo.SaveABlockHead(b2)
if err != nil {
t.Error(err)
}
head, err = dbo.FetchABlockHead()
if err != nil {
t.Error(err)
}
if head == nil {
t.Error("DBlock head is nil")
}
m1, err = b2.MarshalBinary()
if err != nil {
t.Error(err)
}
m2, err = head.MarshalBinary()
if err != nil {
t.Error(err)
}
if primitives.AreBytesEqual(m1, m2) == false {
t.Error("Blocks are not equal")
}
}
示例2: TestECBlockHashingConsistency
func TestECBlockHashingConsistency(t *testing.T) {
ecb := createECBlock()
h1, err := ecb.Hash()
if err != nil {
t.Error(err)
}
k1, err := ecb.HeaderHash()
if err != nil {
t.Error(err)
}
h2, err := ecb.Hash()
if err != nil {
t.Error(err)
}
k2, err := ecb.HeaderHash()
if err != nil {
t.Error(err)
}
if primitives.AreBytesEqual(h1.Bytes(), h2.Bytes()) == false {
t.Error("ecb.Hash()es are not equal")
}
if primitives.AreBytesEqual(k1.Bytes(), k2.Bytes()) == false {
t.Error("ecb.HeaderHash()es are not equal")
}
}
示例3: TestInsertFetch
func TestInsertFetch(t *testing.T) {
dbo := createOverlay()
defer dbo.Close()
b := NewDBTestObject()
b.Data = []byte{0x00, 0x01, 0x02, 0x03}
err := dbo.Insert(TestBucket, b)
if err != nil {
t.Error(err)
}
index := b.DatabasePrimaryIndex()
b2 := NewDBTestObject()
resp, err := dbo.FetchBlock(TestBucket, index, b2)
if err != nil {
t.Error(err)
}
if resp == nil {
t.Error("Response is nil while it shouldn't be.")
}
bResp := resp.(*DBTestObject)
bytes1 := b.Data
bytes2 := bResp.Data
if primitives.AreBytesEqual(bytes1, bytes2) == false {
t.Errorf("Bytes are not equal - %x vs %x", bytes1, bytes2)
}
}
示例4: TestSignature
func TestSignature(t *testing.T) {
pub, priv, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Error(err)
}
t.Logf("priv, pub - %x, %x", *priv, *pub)
testData := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}
sig := ed25519.Sign(priv, testData)
ok := ed25519.Verify(pub, testData, sig)
if ok == false {
t.Error("Signature could not be verified")
}
pub2, err := primitives.PrivateKeyToPublicKey(priv[:])
if err != nil {
t.Error(err)
}
t.Logf("pub1 - %x", pub)
t.Logf("pub2 - %x", pub2)
if primitives.AreBytesEqual(pub[:], pub2[:]) == false {
t.Error("Public keys are not equal")
}
}
示例5: TestAppendExtIDs
func TestAppendExtIDs(t *testing.T) {
ids := [][]byte{
[]byte{0x01, 0x02},
[]byte{0x03, 0x04},
[]byte{0x05, 0x06},
[]byte{0x07, 0x08},
[]byte{0x09, 0x0a},
}
appended := []byte{
0x03, 0x04,
0x05, 0x06,
0x07, 0x08,
0x09, 0x0a,
}
resp, err := AppendExtIDs(ids, 1, 4)
if err != nil {
t.Errorf("%v", err)
}
if primitives.AreBytesEqual(resp, appended) == false {
t.Errorf("AppendExtIDs are not equal - %x vs %x", resp, appended)
}
resp, err = AppendExtIDs(ids, 1, 5)
if err == nil {
t.Error("Err is not when it should not be")
}
if resp != nil {
t.Error("Resp is not nil when it should be")
}
}
示例6: TestFetchECTransactionByHash
func TestFetchECTransactionByHash(t *testing.T) {
blocks := CreateFullTestBlockSet()
dbo := CreateAndPopulateTestDatabaseOverlay()
for _, block := range blocks {
for _, tx := range block.ECBlock.GetEntries() {
if tx.ECID() != entryCreditBlock.ECIDChainCommit && tx.ECID() != entryCreditBlock.ECIDEntryCommit || tx.ECID() == entryCreditBlock.ECIDBalanceIncrease {
continue
}
dTx, err := dbo.FetchECTransaction(tx.Hash())
if err != nil {
t.Errorf("%v", err)
}
if dTx == nil {
t.Errorf("Tx %v not found!", tx.Hash().String())
continue
}
h1, err := tx.MarshalBinary()
if err != nil {
t.Errorf("%v", err)
}
h2, err := dTx.MarshalBinary()
if err != nil {
t.Errorf("%v", err)
}
if primitives.AreBytesEqual(h1, h2) == false {
t.Error("Returned transactions are not equal")
}
}
}
}
示例7: TestMarshalUnmarshalAnchorRecordV2
func TestMarshalUnmarshalAnchorRecordV2(t *testing.T) {
record := `{"AnchorRecordVer":1,"DBHeight":5,"KeyMR":"980ab6d50d9fad574ad4df6dba06a8c02b1c67288ee5beab3fbfde2723f73ef6","RecordHeight":6,"Bitcoin":{"Address":"1K2SXgApmo9uZoyahvsbSanpVWbzZWVVMF","TXID":"e2ac71c9c0fd8edc0be8c0ba7098b77fb7d90dcca755d5b9348116f3f9d9f951","BlockHeight":372576,"BlockHash":"000000000000000003059382ed4dd82b2086e99ec78d1b6e811ebb9d53d8656d","Offset":1144}}`
ar, err := UnmarshalAnchorRecord([]byte(record))
if err != nil {
t.Error(err)
}
priv := "ec9f1cefa00406b80d46135a53504f1f4182d4c0f3fed6cca9281bc020eff973"
pk1, err := primitives.NewPrivateKeyFromHex(priv)
if err != nil {
t.Error(err)
}
data, sig, err := ar.MarshalAndSignV2(pk1)
if err != nil {
t.Error(err)
}
if primitives.AreBytesEqual([]byte(record), data) == false {
t.Errorf("Anchors are not equal\n%s\nvs\n%s", record, string(data))
}
ar, valid, err := UnmarshalAndValidateAnchorRecordV2(data, [][]byte{sig}, pk1.Pub)
if err != nil {
t.Error(err)
}
if valid != true {
t.Errorf("Anchor record is not valid")
}
if ar == nil {
t.Errorf("No anchor record returned!")
}
}
示例8: TestFetchFactoidTransactionByHash
func TestFetchFactoidTransactionByHash(t *testing.T) {
blocks := CreateFullTestBlockSet()
dbo := CreateAndPopulateTestDatabaseOverlay()
for _, block := range blocks {
for _, tx := range block.FBlock.GetTransactions() {
dTx, err := dbo.FetchFactoidTransaction(tx.GetHash())
if err != nil {
t.Errorf("%v", err)
}
if dTx == nil {
t.Errorf("Tx %v not found!", tx.GetHash().String())
continue
}
h1, err := tx.MarshalBinary()
if err != nil {
t.Errorf("%v", err)
}
h2, err := dTx.MarshalBinary()
if err != nil {
t.Errorf("%v", err)
}
if primitives.AreBytesEqual(h1, h2) == false {
t.Error("Returned transactions are not equal")
}
}
}
}
示例9: TestRCDAddress
func TestRCDAddress(t *testing.T) {
priv := NewPrivKey(0)
rcd := NewFactoidRCDAddress(0)
pub := rcd.(*factoid.RCD_1).GetPublicKey()
//pub2 := [32]byte{}
//copy(pub2[:], pub)
pub3 := PrivateKeyToEDPub(priv)
if primitives.AreBytesEqual(pub, pub3) == false {
t.Error("RCD public keys are not equal")
}
}
示例10: TestCommitMarshalUnmarshal
func TestCommitMarshalUnmarshal(t *testing.T) {
blocks := testHelper.CreateFullTestBlockSet()
for _, block := range blocks {
for _, tx := range block.ECBlock.GetEntries() {
h1, err := tx.MarshalBinary()
if err != nil {
t.Errorf("Error marshalling - %v", err)
}
var h2 []byte
var e interfaces.BinaryMarshallable
switch tx.ECID() {
case ECIDChainCommit:
e = new(CommitChain)
break
case ECIDEntryCommit:
e = new(CommitEntry)
break
case ECIDBalanceIncrease:
e = new(IncreaseBalance)
break
case ECIDMinuteNumber:
e = new(MinuteNumber)
break
case ECIDServerIndexNumber:
e = new(ServerIndexNumber)
break
default:
t.Error("Wrong ECID")
break
}
h2, err = e.UnmarshalBinaryData(h1)
if err != nil {
t.Logf("Tried to unmarshal %x", h1)
t.Errorf("Error unmarshalling - %v", err)
continue
}
if len(h2) > 0 {
t.Errorf("Leftovers from unmarshalling - %x", h2)
}
h2, err = e.MarshalBinary()
if err != nil {
t.Errorf("Error marshalling2 - %v", err)
continue
}
if primitives.AreBytesEqual(h1, h2) == false {
t.Error("ECEntries are not identical - %x vs %x", h1, h2)
}
}
}
}
示例11: IsEqual
func (d1 *DBTestObject) IsEqual(d2 *DBTestObject) bool {
if d1.DatabaseHeight != d2.DatabaseHeight {
return false
}
if primitives.AreBytesEqual(d1.Data, d2.Data) == false {
return false
}
if primitives.AreBytesEqual(d1.PrimaryIndex.Bytes(), d2.PrimaryIndex.Bytes()) == false {
return false
}
if primitives.AreBytesEqual(d1.SecondaryIndex.Bytes(), d2.SecondaryIndex.Bytes()) == false {
return false
}
if primitives.AreBytesEqual(d1.ChainID.Bytes(), d2.ChainID.Bytes()) == false {
return false
}
return true
}
示例12: IsSameAs
func (a *CommitChain) IsSameAs(b *CommitChain) bool {
if b == nil {
return false
}
bin1, err := a.MarshalBinary()
if err != nil {
return false
}
bin2, err := b.MarshalBinary()
if err != nil {
return false
}
return primitives.AreBytesEqual(bin1, bin2)
}
示例13: TestMarshalUnmarshalAnchorRecord
func TestMarshalUnmarshalAnchorRecord(t *testing.T) {
record := `{"AnchorRecordVer":1,"DBHeight":5,"KeyMR":"980ab6d50d9fad574ad4df6dba06a8c02b1c67288ee5beab3fbfde2723f73ef6","RecordHeight":6,"Bitcoin":{"Address":"1K2SXgApmo9uZoyahvsbSanpVWbzZWVVMF","TXID":"e2ac71c9c0fd8edc0be8c0ba7098b77fb7d90dcca755d5b9348116f3f9d9f951","BlockHeight":372576,"BlockHash":"000000000000000003059382ed4dd82b2086e99ec78d1b6e811ebb9d53d8656d","Offset":1144}}`
ar, err := UnmarshalAnchorRecord([]byte(record))
if err != nil {
t.Error(err)
}
data, err := ar.Marshal()
if err != nil {
t.Error(err)
}
if primitives.AreBytesEqual([]byte(record), data) == false {
t.Errorf("Anchors are not equal\n%s\nvs\n%s", record, string(data))
}
}
示例14: TestMarshalUnmarshal
func TestMarshalUnmarshal(t *testing.T) {
rawStr := "000000000000000000000000000000000000000000000000000000000000000f16a82932aa64e6ad45b2749f2abb871fcf3353ab9d4e163c9bd90e5bbd745b59a164ccbb77a21904edc4f2bb753aa60635fb2b60279c06ae01aa211f375417362fb170f73c3961d4218ff806dd75e6e348ca1798a5fc7a99d443fbe2ff939d9900000000000a2be8000000010000000002000000c702014f8a7fcd1b00000002014f8a851657010001e397a1607d4f56c528ab09da5bbf7b37b0b453f43db303730e28e9ebe02657dff431d4f7dfaf840017ef7a21d1a616d65e6b73f3c6a7ad5c49340a6c2592872020ec60767ff00d7d01a5be79b6ada79c0af4d6b7f91234ff321f3b647ed01e02ccbbc0fe9dcc63293482f22455b9756ee4b4db411a5d00e31b689c1bd1abe1d1e887cf4c52e67fc51fe4d9594c24643a91009c6ea91701b5b6df240248c2f39453162b61d71b98270100000000000000000000"
raw, err := hex.DecodeString(rawStr)
if err != nil {
t.Errorf("%v", err)
}
f := new(FBlock)
rest, err := f.UnmarshalBinaryData(raw)
if err != nil {
t.Errorf("%v", err)
}
if len(rest) > 0 {
t.Errorf("Returned too much data - %x", rest)
}
b, err := f.MarshalBinary()
if err != nil {
t.Errorf("%v", err)
}
if primitives.AreBytesEqual(raw, b) == false {
t.Errorf("Marshalled bytes are not equal - %x vs %x", raw, b)
}
//f.CalculateHashes()
if f.DatabasePrimaryIndex().String() != "aa100f203f159e4369081bb366f6816b302387ec19a4f8b9c98495d97fbe3527" {
t.Errorf("Wrong PrimaryIndex - %v vs %v", f.DatabasePrimaryIndex().String(), "aa100f203f159e4369081bb366f6816b302387ec19a4f8b9c98495d97fbe3527")
}
if f.DatabaseSecondaryIndex().String() != "5810ed83155dfb7b6039323b8a5572cd03166a37d1c3e86d4538c99907a81757" {
t.Errorf("Wrong SecondaryIndex - %v vs %v", f.DatabaseSecondaryIndex().String(), "5810ed83155dfb7b6039323b8a5572cd03166a37d1c3e86d4538c99907a81757")
}
err = f.Validate()
if err != nil {
t.Errorf("%v", err)
}
}
示例15: IsSameAs
func (a *DataResponse) IsSameAs(b *DataResponse) bool {
if b == nil {
return false
}
if a.Timestamp.GetTimeMilli() != b.Timestamp.GetTimeMilli() {
return false
}
if a.DataType != b.DataType {
return false
}
if a.DataHash == nil && b.DataHash != nil {
return false
}
if a.DataHash != nil {
if a.DataHash.IsSameAs(b.DataHash) == false {
return false
}
}
if a.DataObject == nil && b.DataObject != nil {
return false
}
if a.DataObject != nil {
hex1, err := a.DataObject.MarshalBinary()
if err != nil {
return false
}
hex2, err := b.DataObject.MarshalBinary()
if err != nil {
return false
}
if primitives.AreBytesEqual(hex1, hex2) == false {
return false
}
}
return true
}