mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +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>
81 lines
3.2 KiB
Go
81 lines
3.2 KiB
Go
package ruleerrors
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
)
|
|
|
|
func TestNewErrMissingTxOut(t *testing.T) {
|
|
outer := NewErrMissingTxOut(
|
|
[]*externalapi.DomainOutpoint{
|
|
{
|
|
TransactionID: *externalapi.NewDomainTransactionIDFromByteArray(&[externalapi.DomainHashSize]byte{255, 255, 255}),
|
|
Index: 5,
|
|
},
|
|
})
|
|
expectedOuterErr := "ErrMissingTxOut: missing the following outpoint: [(ffffff0000000000000000000000000000000000000000000000000000000000: 5)]"
|
|
inner := &ErrMissingTxOut{}
|
|
if !errors.As(outer, inner) {
|
|
t.Fatal("TestWrapInRuleError: Outer should contain ErrMissingTxOut in it")
|
|
}
|
|
|
|
if len(inner.MissingOutpoints) != 1 {
|
|
t.Fatalf("TestWrapInRuleError: Expected len(inner.MissingOutpoints) 1, found: %d", len(inner.MissingOutpoints))
|
|
}
|
|
if inner.MissingOutpoints[0].Index != 5 {
|
|
t.Fatalf("TestWrapInRuleError: Expected 5. found: %d", inner.MissingOutpoints[0].Index)
|
|
}
|
|
|
|
rule := &RuleError{}
|
|
if !errors.As(outer, rule) {
|
|
t.Fatal("TestWrapInRuleError: Outer should contain RuleError in it")
|
|
}
|
|
if rule.message != "ErrMissingTxOut" {
|
|
t.Fatalf("TestWrapInRuleError: Expected message = 'ErrMissingTxOut', found: '%s'", rule.message)
|
|
}
|
|
if errors.Is(rule.inner, inner) {
|
|
t.Fatal("TestWrapInRuleError: rule.inner should contain the ErrMissingTxOut in it")
|
|
}
|
|
|
|
if outer.Error() != expectedOuterErr {
|
|
t.Fatalf("TestWrapInRuleError: Expected %s. found: %s", expectedOuterErr, outer.Error())
|
|
}
|
|
}
|
|
|
|
func TestNewErrInvalidTransactionsInNewBlock(t *testing.T) {
|
|
outer := NewErrInvalidTransactionsInNewBlock([]InvalidTransaction{{&externalapi.DomainTransaction{Fee: 1337}, ErrNoTxInputs}})
|
|
//TODO: Implement Stringer for `DomainTransaction`
|
|
expectedOuterErr := "ErrInvalidTransactionsInNewBlock: [(bbf6e84f5a6333948063aa45ea02ff5bb0355e11e41becf20245791f61179db1: ErrNoTxInputs)]"
|
|
inner := &ErrInvalidTransactionsInNewBlock{}
|
|
if !errors.As(outer, inner) {
|
|
t.Fatal("TestNewErrInvalidTransactionsInNewBlock: Outer should contain ErrInvalidTransactionsInNewBlock in it")
|
|
}
|
|
|
|
if len(inner.InvalidTransactions) != 1 {
|
|
t.Fatalf("TestNewErrInvalidTransactionsInNewBlock: Expected len(inner.MissingOutpoints) 1, found: %d", len(inner.InvalidTransactions))
|
|
}
|
|
if inner.InvalidTransactions[0].err != ErrNoTxInputs {
|
|
t.Fatalf("TestNewErrInvalidTransactionsInNewBlock: Expected ErrNoTxInputs. found: %v", inner.InvalidTransactions[0].err)
|
|
}
|
|
if inner.InvalidTransactions[0].Transaction.Fee != 1337 {
|
|
t.Fatalf("TestNewErrInvalidTransactionsInNewBlock: Expected 1337. found: %v", inner.InvalidTransactions[0].Transaction.Fee)
|
|
}
|
|
|
|
rule := &RuleError{}
|
|
if !errors.As(outer, rule) {
|
|
t.Fatal("TestNewErrInvalidTransactionsInNewBlock: Outer should contain RuleError in it")
|
|
}
|
|
if rule.message != "ErrInvalidTransactionsInNewBlock" {
|
|
t.Fatalf("TestNewErrInvalidTransactionsInNewBlock: Expected message = 'ErrInvalidTransactionsInNewBlock', found: '%s'", rule.message)
|
|
}
|
|
if errors.Is(rule.inner, inner) {
|
|
t.Fatal("TestNewErrInvalidTransactionsInNewBlock: rule.inner should contain the ErrInvalidTransactionsInNewBlock in it")
|
|
}
|
|
|
|
if outer.Error() != expectedOuterErr {
|
|
t.Fatalf("TestNewErrInvalidTransactionsInNewBlock: Expected %s. found: %s", expectedOuterErr, outer.Error())
|
|
}
|
|
}
|