mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-24 07:46:45 +00:00

* '' * '' * '' * Changes genesis block version to 0. * a * a * All tests are done. * All tests passed for changed block version from int32 to uint16 * Adds validation of rejecting blocks with unknown versions. * Changes txn version from int32 to uint16. * . * Adds comments to exported functions. * Change functions name from ConvertFromRpcScriptPubKeyToRPCScriptPubKey to ConvertFromAppMsgRPCScriptPubKeyToRPCScriptPubKey and from ConvertFromRPCScriptPubKeyToRpcScriptPubKey to ConvertFromRPCScriptPubKeyToAppMsgRPCScriptPubKey * change comment to "ScriptPublicKey represents a Kaspad ScriptPublicKey" * delete part (tx.Version < 0) that cannot be exist on the if statement. * Revert protobuf version. * Fix a comment. * Fix a comment. * Rename a variable. * Rename a variable. * Remove a const. * Rename a type. * Rename a field. * Rename a field. * Remove commented-out code. * Remove dangerous nil case in DomainTransactionOutput.Clone(). * Remove a constant. * Fix a string. * Fix wrong totalScriptPubKeySize in transactionMassStandalonePart. * Remove a constant. * Remove an unused error. * Fix a serialization error. * Specify version types to be uint16 explicitly. * Use constants.ScriptPublicKeyVersion. * Fix a bad test. * Remove some whitespace. * Add a case to utxoEntry.Equal(). * Rename scriptPubKey to scriptPublicKey. * Remove a TODO. * Rename constants. * Rename a variable. * Add version to parseShortForm. Co-authored-by: tal <tal@daglabs.com> Co-authored-by: stasatdaglabs <stas@daglabs.com>
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package utxo
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
)
|
|
|
|
func Benchmark_serializeUTXO(b *testing.B) {
|
|
script, err := hex.DecodeString("76a914ad06dd6ddee55cbca9a9e3713bd7587509a3056488ac")
|
|
if err != nil {
|
|
b.Fatalf("Error decoding scriptPublicKey string: %s", err)
|
|
}
|
|
scriptPublicKey := &externalapi.ScriptPublicKey{script, 0}
|
|
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) {
|
|
script, err := hex.DecodeString("76a914ad06dd6ddee55cbca9a9e3713bd7587509a3056488ac")
|
|
if err != nil {
|
|
t.Fatalf("Error decoding scriptPublicKey script string: %s", err)
|
|
}
|
|
scriptPublicKey := &externalapi.ScriptPublicKey{Script: script, Version: 0}
|
|
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")
|
|
}
|
|
}
|