wip porting siwe project test cases

This commit is contained in:
shwoop 2025-06-28 21:55:18 +02:00
parent 1e87ef23da
commit dc936dceca
No known key found for this signature in database
GPG key ID: 95A35B68C1E5F95A
4 changed files with 39 additions and 29 deletions

View file

@ -1068,41 +1068,51 @@ func TestSignInWithEtherium(t *testing.T) {
testFiles, err := os.ReadDir(filepath.Join("testdata", "siwe")) testFiles, err := os.ReadDir(filepath.Join("testdata", "siwe"))
require.NoError(t, err) require.NoError(t, err)
var messages map[string]string
for _, fInfo := range testFiles { for _, fInfo := range testFiles {
if !strings.HasSuffix(fInfo.Name(), "txt") { if !strings.HasSuffix(fInfo.Name(), "json") {
continue continue
} }
t.Run(fInfo.Name(), func(t *testing.T) { if !strings.HasPrefix(fInfo.Name(), "valid") {
t.Parallel() continue
expectedFailure := strings.HasPrefix(fInfo.Name(), "expfail") }
expectedWarning := strings.HasPrefix(fInfo.Name(), "expwarn") jsonFile, err := os.ReadFile(filepath.Join("testdata", "siwe", fInfo.Name()))
message, err := os.ReadFile(filepath.Join("testdata", "siwe", fInfo.Name())) require.NoError(t, err)
require.NoError(t, err)
api, control := setup(t, true) err = json.Unmarshal(jsonFile, &messages)
createAccount(control, api, t) require.NoError(t, err)
createAccount(control, api, t)
control.approveCh <- "1"
list, err := api.List(context.Background())
require.NoError(t, err)
a := common.NewMixedcaseAddress(list[0])
control.approveCh <- "Y" for testName, message := range messages {
control.inputCh <- "a_long_password" t.Run(testName, func(t *testing.T) {
signature, err := api.SignData(context.Background(), apitypes.TextPlain.Mime, a, hexutil.Encode([]byte(message))) t.Parallel()
if expectedFailure { api, control := setup(t, true)
require.Error(t, err) createAccount(control, api, t)
return createAccount(control, api, t)
} else { control.approveCh <- "1"
list, err := api.List(context.Background())
require.NoError(t, err) require.NoError(t, err)
} a := common.NewMixedcaseAddress(list[0])
if expectedWarning {
// todo: monitor for warning control.approveCh <- "Y"
} control.inputCh <- "a_long_password"
if signature == nil || len(signature) != 65 { signature, err := api.SignData(context.Background(), apitypes.TextPlain.Mime, a, hexutil.Encode([]byte(message)))
t.Errorf("Expected 65 byte signature (got %d bytes)", len(signature))
} require.NoError(t, err)
}) // if expectedFailure {
// require.Error(t, err)
// return
// } else {
// require.NoError(t, err)
// }
// if expectedWarning {
// // todo: monitor for warning
// }
if signature == nil || len(signature) != 65 {
t.Errorf("Expected 65 byte signature (got %d bytes)", len(signature))
}
})
}
} }
} }