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"))
require.NoError(t, err)
var messages map[string]string
for _, fInfo := range testFiles {
if !strings.HasSuffix(fInfo.Name(), "txt") {
if !strings.HasSuffix(fInfo.Name(), "json") {
continue
}
t.Run(fInfo.Name(), func(t *testing.T) {
t.Parallel()
expectedFailure := strings.HasPrefix(fInfo.Name(), "expfail")
expectedWarning := strings.HasPrefix(fInfo.Name(), "expwarn")
message, err := os.ReadFile(filepath.Join("testdata", "siwe", fInfo.Name()))
if !strings.HasPrefix(fInfo.Name(), "valid") {
continue
}
jsonFile, err := os.ReadFile(filepath.Join("testdata", "siwe", fInfo.Name()))
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)
createAccount(control, api, t)
createAccount(control, api, t)
@ -1091,18 +1099,20 @@ func TestSignInWithEtherium(t *testing.T) {
control.inputCh <- "a_long_password"
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)
}
if expectedWarning {
// todo: monitor for warning
}
// 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))
}
})
}
}
}