github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/stdlibs/std/crypto_test.gno (about)

     1  package std
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestValid(t *testing.T) {
     8  	type test struct {
     9  		inputAddress Address
    10  		expected     bool
    11  	}
    12  
    13  	testCases := []test{
    14  		{inputAddress: "g1f4v282mwyhu29afke4vq5r2xzcm6z3ftnugcnv", expected: true},
    15  		{inputAddress: "g127jydsh6cms3lrtdenydxsckh23a8d6emqcvfa", expected: true},
    16  		{inputAddress: "g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq", expected: true},
    17  		{inputAddress: "g14da4n9hcynyzz83q607uu8keuh9hwlv42ra6fa", expected: true},
    18  
    19  		// Bech32 doesn't allow '1', 'b', 'i', 'o' for data part
    20  		//
    21  		// 	https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#bech32
    22  		{inputAddress: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5", expected: true},
    23  		{inputAddress: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf1", expected: false},
    24  		{inputAddress: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqfb", expected: false},
    25  		{inputAddress: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqfi", expected: false},
    26  		{inputAddress: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqfo", expected: false},
    27  
    28  		{inputAddress: "g1u0000000000000000000000000000000000000", expected: false},
    29  		{inputAddress: "", expected: false},
    30  		{inputAddress: "000000000000", expected: false},
    31  		{inputAddress: "0000000000000000000000000000000000000000000000000000000000000000000000", expected: false},
    32  	}
    33  
    34  	for _, tc := range testCases {
    35  		result := tc.inputAddress.IsValid()
    36  
    37  		if result != tc.expected {
    38  			t.Fatalf("Expected: %t, got: %t", tc.expected, result)
    39  		}
    40  	}
    41  }