mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
wip porting siwe project test cases
This commit is contained in:
parent
1e87ef23da
commit
dc936dceca
4 changed files with 39 additions and 29 deletions
|
|
@ -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))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue