kaspad/domain/consensus/utils/utxo/serialization_test.go
Svarog 05941a76e7
Make DomainHash and TransactionID read-only structs (#1282)
* Increase size of reachability cache

* Change DomainHash to struct with unexported hashArray

* Fixing compilation errors stemming from new DomainHash structure

* Remove obsolete Read/WriteElement methods in appmessage

* Fix all tests

* Fix all tests

* Add comments

* A few renamings

* go mod tidy
2020-12-24 16:15:23 +02:00

69 lines
2.0 KiB
Go

package utxo
import (
"encoding/hex"
"reflect"
"testing"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
)
func Benchmark_serializeUTXO(b *testing.B) {
scriptPublicKey, err := hex.DecodeString("76a914ad06dd6ddee55cbca9a9e3713bd7587509a3056488ac")
if err != nil {
b.Fatalf("Error decoding scriptPublicKey string: %s", err)
}
entry := NewUTXOEntry(5000000000, scriptPublicKey, false, 1432432)
outpoint := &externalapi.DomainOutpoint{
TransactionID: *externalapi.NewDomainTransactionIDFromByteArray(&[externalapi.DomainHashSize]byte{
0x16, 0x5e, 0x38, 0xe8, 0xb3, 0x91, 0x45, 0x95,
0xd9, 0xc6, 0x41, 0xf3, 0xb8, 0xee, 0xc2, 0xf3,
0x46, 0x11, 0x89, 0x6b, 0x82, 0x1a, 0x68, 0x3b,
0x7a, 0x4e, 0xde, 0xfe, 0x2c, 0x00, 0x00, 0x00,
}),
Index: 0xffffffff,
}
for i := 0; i < b.N; i++ {
_, err := SerializeUTXO(entry, outpoint)
if err != nil {
b.Fatal(err)
}
}
}
func Test_serializeUTXO(t *testing.T) {
scriptPublicKey, err := hex.DecodeString("76a914ad06dd6ddee55cbca9a9e3713bd7587509a3056488ac")
if err != nil {
t.Fatalf("Error decoding scriptPublicKey string: %s", err)
}
entry := NewUTXOEntry(5000000000, scriptPublicKey, false, 1432432)
outpoint := &externalapi.DomainOutpoint{
TransactionID: *externalapi.NewDomainTransactionIDFromByteArray(&[externalapi.DomainHashSize]byte{
0x16, 0x5e, 0x38, 0xe8, 0xb3, 0x91, 0x45, 0x95,
0xd9, 0xc6, 0x41, 0xf3, 0xb8, 0xee, 0xc2, 0xf3,
0x46, 0x11, 0x89, 0x6b, 0x82, 0x1a, 0x68, 0x3b,
0x7a, 0x4e, 0xde, 0xfe, 0x2c, 0x00, 0x00, 0x00,
}),
Index: 0xffffffff,
}
serialized, err := SerializeUTXO(entry, outpoint)
if err != nil {
t.Fatalf("SerializeUTXO: %+v", err)
}
deserializedEntry, deserializedOutpoint, err := DeserializeUTXO(serialized)
if err != nil {
return
}
if !reflect.DeepEqual(deserializedEntry, entry) {
t.Fatalf("deserialized entry is not equal to the original")
}
if !reflect.DeepEqual(deserializedOutpoint, outpoint) {
t.Fatalf("deserialized outpoint is not equal to the original")
}
}