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,17 +1068,25 @@ 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)
err = json.Unmarshal(jsonFile, &messages)
require.NoError(t, err)
for testName, message := range messages {
t.Run(testName, func(t *testing.T) {
t.Parallel()
api, control := setup(t, true) api, control := setup(t, true)
createAccount(control, api, t) createAccount(control, api, t)
createAccount(control, api, t) createAccount(control, api, t)
@ -1091,18 +1099,20 @@ func TestSignInWithEtherium(t *testing.T) {
control.inputCh <- "a_long_password" control.inputCh <- "a_long_password"
signature, err := api.SignData(context.Background(), apitypes.TextPlain.Mime, a, hexutil.Encode([]byte(message))) signature, err := api.SignData(context.Background(), apitypes.TextPlain.Mime, a, hexutil.Encode([]byte(message)))
if expectedFailure {
require.Error(t, err)
return
} else {
require.NoError(t, err) require.NoError(t, err)
} // if expectedFailure {
if expectedWarning { // require.Error(t, err)
// todo: monitor for warning // return
} // } else {
// require.NoError(t, err)
// }
// if expectedWarning {
// // todo: monitor for warning
// }
if signature == nil || len(signature) != 65 { if signature == nil || len(signature) != 65 {
t.Errorf("Expected 65 byte signature (got %d bytes)", len(signature)) t.Errorf("Expected 65 byte signature (got %d bytes)", len(signature))
} }
}) })
} }
}
} }