55 "testing"
66
77 "github.com/qubic/go-node-connector/types"
8+ "github.com/stretchr/testify/require"
89)
910
1011// helper to build a minimal transaction with known source/dest public keys
@@ -22,9 +23,7 @@ func TestValidate_HappyPath(t *testing.T) {
2223 txs := types.Transactions {tx }
2324
2425 digest , err := tx .Digest ()
25- if err != nil {
26- t .Fatalf ("computing digest: %v" , err )
27- }
26+ require .NoError (t , err )
2827
2928 txStatus := types.TransactionStatus {
3029 CurrentTickOfNode : 1000 ,
@@ -34,18 +33,10 @@ func TestValidate_HappyPath(t *testing.T) {
3433 TransactionDigests : [][32 ]byte {digest },
3534 }
3635
37- result , err := Validate (context .Background (), txStatus , txs )
38- if err != nil {
39- t .Fatalf ("unexpected error: %v" , err )
40- }
41-
42- if len (result .Transactions ) != 1 {
43- t .Fatalf ("expected 1 transaction status, got %d" , len (result .Transactions ))
44- }
45-
46- if ! result .Transactions [0 ].MoneyFlew {
47- t .Error ("expected moneyFlew to be true" )
48- }
36+ result , err := ValidateAndConvert (context .Background (), txStatus , txs , false )
37+ require .NoError (t , err )
38+ require .Len (t , result .Transactions , 1 )
39+ require .True (t , result .Transactions [0 ].MoneyFlew )
4940}
5041
5142func TestValidate_TxCountMismatch (t * testing.T ) {
@@ -61,10 +52,8 @@ func TestValidate_TxCountMismatch(t *testing.T) {
6152 TransactionDigests : nil ,
6253 }
6354
64- _ , err := Validate (context .Background (), txStatus , txs )
65- if err == nil {
66- t .Fatal ("expected error for TxCount mismatch, got nil" )
67- }
55+ _ , err := ValidateAndConvert (context .Background (), txStatus , txs , true )
56+ require .Error (t , err )
6857}
6958
7059func TestValidate_DigestMismatch (t * testing.T ) {
@@ -80,10 +69,8 @@ func TestValidate_DigestMismatch(t *testing.T) {
8069 TransactionDigests : [][32 ]byte {{99 , 99 , 99 }}, // wrong digest
8170 }
8271
83- _ , err := Validate (context .Background (), txStatus , txs )
84- if err == nil {
85- t .Fatal ("expected error for digest mismatch, got nil" )
86- }
72+ _ , err := ValidateAndConvert (context .Background (), txStatus , txs , true )
73+ require .Error (t , err )
8774}
8875
8976func TestValidate_EmptyTick (t * testing.T ) {
@@ -97,12 +84,26 @@ func TestValidate_EmptyTick(t *testing.T) {
9784 TransactionDigests : nil ,
9885 }
9986
100- result , err := Validate (context .Background (), txStatus , txs )
101- if err != nil {
102- t . Fatalf ( "unexpected error for empty tick: %v" , err )
103- }
87+ result , err := ValidateAndConvert (context .Background (), txStatus , txs , false )
88+ require . NoError ( t , err )
89+ require . Empty ( t , result . Transactions )
90+ }
10491
105- if len (result .Transactions ) != 0 {
106- t .Fatalf ("expected 0 transaction statuses, got %d" , len (result .Transactions ))
92+ func TestValidateAndConvert_NoValidation (t * testing.T ) {
93+ tx := makeTransaction ([32 ]byte {1 }, [32 ]byte {2 }, 100 , 1000 )
94+ txs := types.Transactions {tx }
95+
96+ // data that would fail validation
97+ txStatus := types.TransactionStatus {
98+ CurrentTickOfNode : 12345 ,
99+ Tick : 12345 ,
100+ TxCount : 1 , // any count
101+ MoneyFlew : [128 ]byte {}, // no tx status data
102+ TransactionDigests : nil , // no tx status digests
107103 }
104+
105+ // should pass because validate=false
106+ result , err := ValidateAndConvert (t .Context (), txStatus , txs , false )
107+ require .NoError (t , err )
108+ require .Empty (t , result .Transactions )
108109}
0 commit comments