kaspad/domain/consensus/utils/utxo/utxo_entry_test.go
talelbaz 8a309a7d2a
Upgradability mechanisms script version (#1313)
* ''

* ''

* ''

* 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>
2021-01-05 17:50:09 +02:00

114 lines
2.5 KiB
Go

package utxo
import (
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
"testing"
)
func TestUTXOEntry_Equal(t *testing.T) {
type testUTXOEntryToCompare struct {
utxoEntry *utxoEntry
expectedResult bool
}
tests := []struct {
baseUTXOEntry *utxoEntry
UTXOEntryToCompareTo []testUTXOEntryToCompare
}{
{
baseUTXOEntry: nil,
UTXOEntryToCompareTo: []testUTXOEntryToCompare{
{
utxoEntry: nil,
expectedResult: true,
},
{
utxoEntry: &utxoEntry{
0xFFFF,
&externalapi.ScriptPublicKey{Script: []byte{0xA1, 0xA2, 0xA3}, Version: 0},
0xFFFF,
false,
},
expectedResult: false,
},
},
}, {
baseUTXOEntry: &utxoEntry{
0xFFFF,
&externalapi.ScriptPublicKey{Script: []byte{0xA1, 0xA2, 0xA3}, Version: 0},
0xFFFF,
true,
},
UTXOEntryToCompareTo: []testUTXOEntryToCompare{
{
utxoEntry: &utxoEntry{
0xFFFF,
&externalapi.ScriptPublicKey{Script: []byte{0xA1, 0xA2, 0xA3}, Version: 0},
0xFFFF,
true,
},
expectedResult: true,
},
{
utxoEntry: nil,
expectedResult: false,
},
{
utxoEntry: &utxoEntry{
0xFFFF,
&externalapi.ScriptPublicKey{Script: []byte{0xA1, 0xA0, 0xA3}, Version: 0}, // Changed
0xFFFF,
true,
},
expectedResult: false,
},
{
utxoEntry: &utxoEntry{
0xFFFF,
&externalapi.ScriptPublicKey{Script: []byte{0xA1, 0xA2, 0xA3}, Version: 0},
0xFFFF,
false, // Changed
},
expectedResult: false,
},
{
utxoEntry: &utxoEntry{
0xFFFF,
&externalapi.ScriptPublicKey{Script: []byte{0xA1, 0xA2, 0xA3}, Version: 0},
0xFFF0, // Changed
true,
},
expectedResult: false,
},
{
utxoEntry: nil,
expectedResult: false,
},
{
utxoEntry: &utxoEntry{
0xFFF0, // Changed
&externalapi.ScriptPublicKey{Script: []byte{0xA1, 0xA2, 0xA3}, Version: 0},
0xFFFF,
true,
},
expectedResult: false,
},
},
},
}
for i, test := range tests {
for j, subTest := range test.UTXOEntryToCompareTo {
var base externalapi.UTXOEntry = test.baseUTXOEntry
result1 := base.Equal(subTest.utxoEntry)
if result1 != subTest.expectedResult {
t.Fatalf("Test #%d:%d: Expected %t but got %t", i, j, subTest.expectedResult, result1)
}
result2 := subTest.utxoEntry.Equal(base)
if result2 != subTest.expectedResult {
t.Fatalf("Test #%d:%d: Expected %t but got %t", i, j, subTest.expectedResult, result2)
}
}
}
}