github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/systests/cryptocurrency_test.go (about)

     1  package systests
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/keybase/client/go/engine"
     7  	"github.com/keybase/client/go/libkb"
     8  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestBech32FeatureFlag(t *testing.T) {
    13  	tt := newTeamTester(t)
    14  	defer tt.cleanup()
    15  	jan := tt.addUser("abc")
    16  	runEngine := func() error {
    17  		eng := engine.NewCryptocurrencyEngine(jan.MetaContext().G(), keybase1.RegisterAddressArg{
    18  			Address: "bc1qcerjvfmt8qr8xlp6pv4htjhwlj2wgdjnayc3cc",
    19  			Force:   true,
    20  		})
    21  		err := engine.RunEngine2(jan.MetaContext().WithUIs(libkb.UIs{
    22  			LogUI:    jan.MetaContext().G().Log,
    23  			SecretUI: jan.newSecretUI(),
    24  		}), eng)
    25  		return err
    26  	}
    27  	err := runEngine()
    28  	require.NoError(t, err)
    29  }
    30  
    31  func TestProveCapitalizedBech32Address(t *testing.T) {
    32  	tt := newTeamTester(t)
    33  	defer tt.cleanup()
    34  	alice := tt.addUser("abc")
    35  
    36  	bech32Test := []struct {
    37  		address string
    38  		valid   bool
    39  	}{
    40  		{"bc1qcerjvfmt8qr8xlp6pv4htjhwlj2wgdjnayc3cc", true},
    41  		{"BC1QCERJVFMT8QR8XLP6PV4HTJHWLJ2WGDJNAYC3CC", true},  // uppercase is accepted
    42  		{"BC1qcerJVFMt8qr8XLP6PV4HTJHWLJ2WGDJNAYC3CC", false}, // mixed case is not
    43  		{"zs1x2q4pej08shm9pd5fx8jvl97f8f7t8sej8lsgp08jsczxsucr5gkff0yasc0gc43dtv3wczerv5", true},
    44  		{"ZS1X2Q4PEJ08SHM9PD5FX8JVL97F8F7T8SEJ8LSGP08JSCZXSUCR5GKFF0YASC0GC43DTV3WCZERV5", true},
    45  		{"zs1X2Q4PEJ08SHM9Pd5fx8JVL97F8F7T8SEJ8LSGP08JSCZXSUCR5GKFF0YASC0GC43DTV3wczerv5", false},
    46  	}
    47  	for _, testAddr := range bech32Test {
    48  		eng := engine.NewCryptocurrencyEngine(alice.MetaContext().G(), keybase1.RegisterAddressArg{
    49  			Address: testAddr.address,
    50  			Force:   true,
    51  		})
    52  		err := engine.RunEngine2(alice.MetaContext().WithUIs(libkb.UIs{
    53  			LogUI:    alice.MetaContext().G().Log,
    54  			SecretUI: alice.newSecretUI(),
    55  		}), eng)
    56  		if testAddr.valid {
    57  			require.NoError(t, err)
    58  		} else {
    59  			require.Error(t, err)
    60  		}
    61  	}
    62  }