diff --git a/signer/core/api_test.go b/signer/core/api_test.go index 800020b0cf..48d0c4f967 100644 --- a/signer/core/api_test.go +++ b/signer/core/api_test.go @@ -119,17 +119,18 @@ func tmpDirName(t *testing.T) string { return d } -func setup(t *testing.T) (*core.SignerAPI, *headlessUi) { +func setup(ksLoc string, t *testing.T) (*core.SignerAPI, *headlessUi) { db, err := fourbyte.New() if err != nil { t.Fatal(err.Error()) } ui := &headlessUi{make(chan string, 20), make(chan string, 20)} - am := core.StartClefAccountManager(tmpDirName(t), true, true, "") + am := core.StartClefAccountManager(ksLoc, true, true, "") api := core.NewSignerAPI(am, 1337, true, ui, db, true, &storage.NoStorage{}) return api, ui } + func createAccount(ui *headlessUi, api *core.SignerAPI, t *testing.T) { ui.approveCh <- "Y" ui.inputCh <- "a_long_password" @@ -175,8 +176,7 @@ func list(ui *headlessUi, api *core.SignerAPI, t *testing.T) ([]common.Address, } -func TestNewAcc(t *testing.T) { - api, control := setup(t) +func testNewAcc(api *core.SignerAPI, control *headlessUi, t *testing.T) { verifyNum := func(num int) { list, err := list(control, api, t) if err != nil { @@ -223,6 +223,18 @@ func TestNewAcc(t *testing.T) { } } +func TestNewAcc(t *testing.T) { + // test filesystem keystore + tmpDir := tmpDirName(t) + api, control := setup(tmpDir, t) + testNewAcc(api, control, t) + + // test db keystore + ksLoc := "sqlite3#" + filepath.Join(tmpDir, "test_new_account.db") + api, control = setup(ksLoc, t) + testNewAcc(api, control, t) +} + func mkTestTx(from common.MixedcaseAddress) core.SendTxArgs { to := common.NewMixedcaseAddress(common.HexToAddress("0x1337")) gas := hexutil.Uint64(21000) @@ -241,14 +253,13 @@ func mkTestTx(from common.MixedcaseAddress) core.SendTxArgs { return tx } -func TestSignTx(t *testing.T) { +func testSignTx(api *core.SignerAPI, control *headlessUi, t *testing.T) { var ( list []common.Address res, res2 *ethapi.SignTransactionResult err error ) - api, control := setup(t) createAccount(control, api, t) control.approveCh <- "A" list, err = api.List(context.Background()) @@ -321,5 +332,16 @@ func TestSignTx(t *testing.T) { if bytes.Equal(res.Raw, res2.Raw) { t.Error("Expected tx to be modified by UI") } - +} + +func TestSignTx(t *testing.T) { + // test filesystem keystore + tmpDir := tmpDirName(t) + api, control := setup(tmpDir, t) + testSignTx(api, control, t) + + // test db keystore + ksLoc := "sqlite3#" + filepath.Join(tmpDir, "test_sign_tx.db") + api, control = setup(ksLoc, t) + testSignTx(api, control, t) } diff --git a/signer/core/signed_data_test.go b/signer/core/signed_data_test.go index e5f4780890..69194ca5da 100644 --- a/signer/core/signed_data_test.go +++ b/signer/core/signed_data_test.go @@ -22,6 +22,7 @@ import ( "fmt" "io/ioutil" "path" + "path/filepath" "strings" "testing" @@ -179,8 +180,7 @@ var typedData = core.TypedData{ Message: messageStandard, } -func TestSignData(t *testing.T) { - api, control := setup(t) +func testSignData(api *core.SignerAPI, control *headlessUi, t *testing.T) { //Create two accounts createAccount(control, api, t) createAccount(control, api, t) @@ -230,6 +230,18 @@ func TestSignData(t *testing.T) { } } +func TestSignData(t *testing.T) { + // test filesystem keystore + tmpDir := tmpDirName(t) + api, control := setup(tmpDir, t) + testSignData(api, control, t) + + // test db keystore + ksLoc := "sqlite3#" + filepath.Join(tmpDir, "test_new_account.db") + api, control = setup(ksLoc, t) + testSignData(api, control, t) +} + func TestDomainChainId(t *testing.T) { withoutChainID := core.TypedData{ Types: core.Types{