github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/validate/trans_integration_test.go (about)

     1  //go:build integration
     2  // +build integration
     3  
     4  package validate
     5  
     6  import (
     7  	"fmt"
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/colors"
    12  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/identifiers"
    13  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
    14  )
    15  
    16  func Test_TransactionIds(t *testing.T) {
    17  	for i, item := range testTxs {
    18  		if !item.enabled {
    19  			continue
    20  		}
    21  		// if strings.Contains(item.input, ":next") || strings.Contains(item.input, ":prev") {
    22  		// 	continue
    23  		// }
    24  		fmt.Println("-----", i, "----->", item.input)
    25  		inputs := strings.Split(item.input, " ")
    26  		expecteds := strings.Split(item.expected, " ")
    27  		for i, e := range expecteds {
    28  			fmt.Println(i, e)
    29  		}
    30  		var results []identifiers.Identifier
    31  		var err error
    32  		err = ValidateIdentifiers(
    33  			"mainnet",
    34  			inputs,
    35  			ValidTransId,
    36  			100,
    37  			&results,
    38  		)
    39  		if err != nil {
    40  			// we're not testing validation here, so there won't be any errors here, but if
    41  			// there is we want to know about them so we can fix the test
    42  			fmt.Println(colors.Red, item.input, err, colors.Off)
    43  			continue
    44  		}
    45  
    46  		for i, br := range results {
    47  			fmt.Println(br)
    48  			txIds, err := br.ResolveTxs(utils.GetTestChain())
    49  			if err != nil {
    50  				t.Error(colors.Red, br)
    51  				t.Error(err, colors.Off)
    52  			}
    53  			for j, tx := range txIds {
    54  				res := fmt.Sprintf("%d.%d", tx.BlockNumber, tx.TransactionIndex)
    55  				index := i
    56  				if len(expecteds) > 1 && j > 0 {
    57  					index = j
    58  				}
    59  				fmt.Println(res, expecteds[index], res == expecteds[index])
    60  				if res != expecteds[index] {
    61  					fmt.Printf("%sgot: %d.%d expected: %s%s", colors.Red, tx.BlockNumber, tx.TransactionIndex, expecteds[index], colors.Off)
    62  				} else {
    63  					fmt.Printf("%s%d.%d%s", colors.Green, tx.BlockNumber, tx.TransactionIndex, colors.Off)
    64  					if len(results) > 0 {
    65  						fmt.Println()
    66  					}
    67  				}
    68  			}
    69  			if len(txIds) == 0 {
    70  				fmt.Printf("%sgot: nothing expected: %s%s", colors.Red, expecteds[i], colors.Off)
    71  			}
    72  			fmt.Println()
    73  		}
    74  	}
    75  }
    76  
    77  var testTxs = []testCase{
    78  	{
    79  		input:    "1001001.0",
    80  		expected: "1001001.0",
    81  		enabled:  true,
    82  	},
    83  	{
    84  		input:    "0x0b4c6fb75ded4b90218cf0346b0885e442878f104e1b60bf75d5b6860eeacd53.2",
    85  		expected: "1001001.2",
    86  		enabled:  true,
    87  	},
    88  	{
    89  		input:    "0xc20a01b9d0bc87268376d189044e2c76cb2b34dda31e5525cbef45b3c30849e6",
    90  		expected: "1001000.2",
    91  		enabled:  true,
    92  	},
    93  	{
    94  		input:    "0x730724cb08a6eb17bf6b3296359d261570d343ea7944a17a9d7287d77900db08 0xef2ea39c20ba09553b2f3cf02380406ac766039ca56612937eed5e7f3503fb3a 0xc20a01b9d0bc87268376d189044e2c76cb2b34dda31e5525cbef45b3c30849e6 0x5352c80aa2073e21ce6c4aa5488c38455f3519955ece7dca5af3e326797bcc63",
    95  		expected: "1001001.0 1001001.1 1001000.2 1001001.2",
    96  		enabled:  true,
    97  	},
    98  	{
    99  		input:    "1001001.*",
   100  		expected: "1001001.0 1001001.1 1001001.2 1001001.3",
   101  		enabled:  true,
   102  	},
   103  	{
   104  		input:    "0x0b4c6fb75ded4b90218cf0346b0885e442878f104e1b60bf75d5b6860eeacd53.*",
   105  		expected: "1001001.0 1001001.1 1001001.2 1001001.3",
   106  		enabled:  true,
   107  	},
   108  	// TODO: next and previous skip markers - search for this to find other things related
   109  	// {
   110  	// 	input:    "1001001.0:next",
   111  	// 	expected: "1001001.1",
   112  	// 	enabled:  false,
   113  	// },
   114  	// {
   115  	// 	input:    "1001001.0:prev",
   116  	// 	expected: "1001000.2",
   117  	// 	enabled:  true,
   118  	// },
   119  	// {
   120  	// 	input:    "0xc20a01b9d0bc87268376d189044e2c76cb2b34dda31e5525cbef45b3c30849e6:next",
   121  	// 	expected: "1001001.0",
   122  	// 	enabled:  true,
   123  	// },
   124  	// {
   125  	// 	input:    "1001001.0 1001001.0:next 1001001.0:prev 1001001.2",
   126  	// 	expected: "1001001.0 1001001.1 1001000.2 1001001.2",
   127  	// 	enabled:  true,
   128  	// },
   129  }