diff --git a/signer/core/api_test.go b/signer/core/api_test.go index 69229dadaf..0e16a1b7fd 100644 --- a/signer/core/api_test.go +++ b/signer/core/api_test.go @@ -18,7 +18,6 @@ package core_test import ( "bytes" - "context" "fmt" "math/big" "os" @@ -97,12 +96,12 @@ func (ui *headlessUi) ApproveNewAccount(request *core.NewAccountRequest) (core.N } func (ui *headlessUi) ShowError(message string) { - //stdout is used by communication + // stdout is used by communication fmt.Fprintln(os.Stderr, message) } func (ui *headlessUi) ShowInfo(message string) { - //stdout is used by communication + // stdout is used by communication fmt.Fprintln(os.Stderr, message) } @@ -128,7 +127,7 @@ func setup(t *testing.T) (*core.SignerAPI, *headlessUi) { func createAccount(ui *headlessUi, api *core.SignerAPI, t *testing.T) { ui.approveCh <- "Y" ui.inputCh <- "a_long_password" - _, err := api.New(context.Background()) + _, err := api.New(t.Context()) if err != nil { t.Fatal(err) } @@ -143,7 +142,7 @@ func failCreateAccountWithPassword(ui *headlessUi, api *core.SignerAPI, password ui.inputCh <- password ui.inputCh <- password - addr, err := api.New(context.Background()) + addr, err := api.New(t.Context()) if err == nil { t.Fatal("Should have returned an error") } @@ -154,7 +153,7 @@ func failCreateAccountWithPassword(ui *headlessUi, api *core.SignerAPI, password func failCreateAccount(ui *headlessUi, api *core.SignerAPI, t *testing.T) { ui.approveCh <- "N" - addr, err := api.New(context.Background()) + addr, err := api.New(t.Context()) if err != core.ErrRequestDenied { t.Fatal(err) } @@ -165,7 +164,7 @@ func failCreateAccount(ui *headlessUi, api *core.SignerAPI, t *testing.T) { func list(ui *headlessUi, api *core.SignerAPI, t *testing.T) ([]common.Address, error) { ui.approveCh <- "A" - return api.List(context.Background()) + return api.List(t.Context()) } func TestNewAcc(t *testing.T) { @@ -199,7 +198,7 @@ func TestNewAcc(t *testing.T) { // Testing listing: // Listing one Account control.approveCh <- "1" - list, err := api.List(context.Background()) + list, err := api.List(t.Context()) if err != nil { t.Fatal(err) } @@ -208,7 +207,7 @@ func TestNewAcc(t *testing.T) { } // Listing denied control.approveCh <- "Nope" - list, err = api.List(context.Background()) + list, err = api.List(t.Context()) if len(list) != 0 { t.Fatalf("List should be empty") } @@ -246,7 +245,7 @@ func TestSignTx(t *testing.T) { api, control := setup(t) createAccount(control, api, t) control.approveCh <- "A" - list, err = api.List(context.Background()) + list, err = api.List(t.Context()) if err != nil { t.Fatal(err) } @@ -260,7 +259,7 @@ func TestSignTx(t *testing.T) { control.approveCh <- "Y" control.inputCh <- "wrongpassword" - res, err = api.SignTransaction(context.Background(), tx, &methodSig) + res, err = api.SignTransaction(t.Context(), tx, &methodSig) if res != nil { t.Errorf("Expected nil-response, got %v", res) } @@ -268,7 +267,7 @@ func TestSignTx(t *testing.T) { t.Errorf("Expected ErrLocked! %v", err) } control.approveCh <- "No way" - res, err = api.SignTransaction(context.Background(), tx, &methodSig) + res, err = api.SignTransaction(t.Context(), tx, &methodSig) if res != nil { t.Errorf("Expected nil-response, got %v", res) } @@ -278,22 +277,21 @@ func TestSignTx(t *testing.T) { // Sign with correct password control.approveCh <- "Y" control.inputCh <- "a_long_password" - res, err = api.SignTransaction(context.Background(), tx, &methodSig) - + res, err = api.SignTransaction(t.Context(), tx, &methodSig) if err != nil { t.Fatal(err) } parsedTx := &types.Transaction{} rlp.DecodeBytes(res.Raw, parsedTx) - //The tx should NOT be modified by the UI + // The tx should NOT be modified by the UI if parsedTx.Value().Cmp(tx.Value.ToInt()) != 0 { t.Errorf("Expected value to be unchanged, expected %v got %v", tx.Value, parsedTx.Value()) } control.approveCh <- "Y" control.inputCh <- "a_long_password" - res2, err = api.SignTransaction(context.Background(), tx, &methodSig) + res2, err = api.SignTransaction(t.Context(), tx, &methodSig) if err != nil { t.Fatal(err) } @@ -301,20 +299,20 @@ func TestSignTx(t *testing.T) { t.Error("Expected tx to be unmodified by UI") } - //The tx is modified by the UI + // The tx is modified by the UI control.approveCh <- "M" control.inputCh <- "a_long_password" - res2, err = api.SignTransaction(context.Background(), tx, &methodSig) + res2, err = api.SignTransaction(t.Context(), tx, &methodSig) if err != nil { t.Fatal(err) } parsedTx2 := &types.Transaction{} - rlp.DecodeBytes(res.Raw, parsedTx2) + rlp.DecodeBytes(res2.Raw, parsedTx2) - //The tx should be modified by the UI - if parsedTx2.Value().Cmp(tx.Value.ToInt()) != 0 { - t.Errorf("Expected value to be unchanged, got %v", parsedTx.Value()) + // The tx should be modified by the UI + if parsedTx2.Value().Cmp(tx.Value.ToInt()) == 0 { + t.Errorf("Expected value to be changed, got %v", parsedTx2.Value()) } if bytes.Equal(res.Raw, res2.Raw) { t.Error("Expected tx to be modified by UI")