From 6484cf931333a5df4f70b295ba3c2af5eb76958e Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Tue, 3 Mar 2020 18:39:56 -0500 Subject: [PATCH] fix integration tests ref #165 --- src/cli/integration/integration_test.go | 16 +++- src/skywallet/mock_devicer_test.go | 114 ++++++++++++++++++------ src/skywallet/skywallet_test.go | 2 +- 3 files changed, 99 insertions(+), 33 deletions(-) diff --git a/src/cli/integration/integration_test.go b/src/cli/integration/integration_test.go index 33cf533..9384e25 100644 --- a/src/cli/integration/integration_test.go +++ b/src/cli/integration/integration_test.go @@ -10,6 +10,7 @@ import ( "path/filepath" "runtime" "strings" + "sync" "testing" "time" @@ -532,7 +533,10 @@ func TestRecovery(t *testing.T) { var fail = false var stdInDone = false + wg := sync.WaitGroup{} go func() { + wg.Add(1) + defer wg.Done() scanner := bufio.NewScanner(stdoutPipe) scanner.Split(bufio.ScanWords) @@ -545,7 +549,7 @@ func TestRecovery(t *testing.T) { stdInDone = true } else if stdInDone { - if m == "Wrong" || m == "Word" { + if m == "Wrong" || m == "word" { fail = true break } @@ -554,14 +558,20 @@ func TestRecovery(t *testing.T) { }() go func() { + wg.Add(1) + defer wg.Done() scanner := bufio.NewScanner(stderrPipe) scanner.Split(bufio.ScanWords) for scanner.Scan() { - log.Errorln(scanner.Text()) + m := scanner.Text() + if m == "Wrong" || m == "word" || m == `error="Word` { + fail = true + break + } } }() - err = cmd.Wait() + wg.Wait() require.NoError(t, err) require.True(t, fail) } diff --git a/src/skywallet/mock_devicer_test.go b/src/skywallet/mock_devicer_test.go index a63c19b..65e26b4 100644 --- a/src/skywallet/mock_devicer_test.go +++ b/src/skywallet/mock_devicer_test.go @@ -11,20 +11,20 @@ type MockDevicer struct { mock.Mock } -// AddressGen provides a mock function with given fields: addressN, startIndex, confirmAddress -func (_m *MockDevicer) AddressGen(addressN uint32, startIndex uint32, confirmAddress bool) (wire.Message, error) { - ret := _m.Called(addressN, startIndex, confirmAddress) +// AddressGen provides a mock function with given fields: addressN, startIndex, confirmAddress, walletType +func (_m *MockDevicer) AddressGen(addressN uint32, startIndex uint32, confirmAddress bool, walletType string) (wire.Message, error) { + ret := _m.Called(addressN, startIndex, confirmAddress, walletType) var r0 wire.Message - if rf, ok := ret.Get(0).(func(uint32, uint32, bool) wire.Message); ok { - r0 = rf(addressN, startIndex, confirmAddress) + if rf, ok := ret.Get(0).(func(uint32, uint32, bool, string) wire.Message); ok { + r0 = rf(addressN, startIndex, confirmAddress, walletType) } else { r0 = ret.Get(0).(wire.Message) } var r1 error - if rf, ok := ret.Get(1).(func(uint32, uint32, bool) error); ok { - r1 = rf(addressN, startIndex, confirmAddress) + if rf, ok := ret.Get(1).(func(uint32, uint32, bool, string) error); ok { + r1 = rf(addressN, startIndex, confirmAddress, walletType) } else { r1 = ret.Error(1) } @@ -177,6 +177,20 @@ func (_m *MockDevicer) Close() { _m.Called() } +// Connect provides a mock function with given fields: +func (_m *MockDevicer) Connect() error { + ret := _m.Called() + + var r0 error + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() + } else { + r0 = ret.Error(0) + } + + return r0 +} + // Connected provides a mock function with given fields: func (_m *MockDevicer) Connected() bool { ret := _m.Called() @@ -191,13 +205,13 @@ func (_m *MockDevicer) Connected() bool { return r0 } -// FirmwareUpload provides a mock function with given fields: payload, hash -func (_m *MockDevicer) FirmwareUpload(payload []byte, hash [32]byte) error { - ret := _m.Called(payload, hash) +// Disconnect provides a mock function with given fields: +func (_m *MockDevicer) Disconnect() error { + ret := _m.Called() var r0 error - if rf, ok := ret.Get(0).(func([]byte, [32]byte) error); ok { - r0 = rf(payload, hash) + if rf, ok := ret.Get(0).(func() error); ok { + r0 = rf() } else { r0 = ret.Error(0) } @@ -205,6 +219,27 @@ func (_m *MockDevicer) FirmwareUpload(payload []byte, hash [32]byte) error { return r0 } +// EraseFirmware provides a mock function with given fields: length +func (_m *MockDevicer) EraseFirmware(length uint32) (wire.Message, error) { + ret := _m.Called(length) + + var r0 wire.Message + if rf, ok := ret.Get(0).(func(uint32) wire.Message); ok { + r0 = rf(length) + } else { + r0 = ret.Get(0).(wire.Message) + } + + var r1 error + if rf, ok := ret.Get(1).(func(uint32) error); ok { + r1 = rf(length) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + // GenerateMnemonic provides a mock function with given fields: wordCount, usePassphrase func (_m *MockDevicer) GenerateMnemonic(wordCount uint32, usePassphrase bool) (wire.Message, error) { ret := _m.Called(wordCount, usePassphrase) @@ -290,18 +325,18 @@ func (_m *MockDevicer) PinMatrixAck(p string) (wire.Message, error) { } // Recovery provides a mock function with given fields: wordCount, usePassphrase, dryRun -func (_m *MockDevicer) Recovery(wordCount uint32, usePassphrase bool, dryRun bool) (wire.Message, error) { +func (_m *MockDevicer) Recovery(wordCount uint32, usePassphrase *bool, dryRun bool) (wire.Message, error) { ret := _m.Called(wordCount, usePassphrase, dryRun) var r0 wire.Message - if rf, ok := ret.Get(0).(func(uint32, bool, bool) wire.Message); ok { + if rf, ok := ret.Get(0).(func(uint32, *bool, bool) wire.Message); ok { r0 = rf(wordCount, usePassphrase, dryRun) } else { r0 = ret.Get(0).(wire.Message) } var r1 error - if rf, ok := ret.Get(1).(func(uint32, bool, bool) error); ok { + if rf, ok := ret.Get(1).(func(uint32, *bool, bool) error); ok { r1 = rf(wordCount, usePassphrase, dryRun) } else { r1 = ret.Error(1) @@ -345,20 +380,41 @@ func (_m *MockDevicer) SetMnemonic(mnemonic string) (wire.Message, error) { return r0, r1 } -// SignMessage provides a mock function with given fields: addressIndex, message -func (_m *MockDevicer) SignMessage(addressIndex int, message string) (wire.Message, error) { - ret := _m.Called(addressIndex, message) +// SignMessage provides a mock function with given fields: addressN, addressIndex, message, walletType +func (_m *MockDevicer) SignMessage(addressN int, addressIndex int, message string, walletType string) (wire.Message, error) { + ret := _m.Called(addressN, addressIndex, message, walletType) + + var r0 wire.Message + if rf, ok := ret.Get(0).(func(int, int, string, string) wire.Message); ok { + r0 = rf(addressN, addressIndex, message, walletType) + } else { + r0 = ret.Get(0).(wire.Message) + } + + var r1 error + if rf, ok := ret.Get(1).(func(int, int, string, string) error); ok { + r1 = rf(addressN, addressIndex, message, walletType) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TransactionSign provides a mock function with given fields: inputs, outputs, walletType +func (_m *MockDevicer) TransactionSign(inputs []*messages.SkycoinTransactionInput, outputs []*messages.SkycoinTransactionOutput, walletType string) (wire.Message, error) { + ret := _m.Called(inputs, outputs, walletType) var r0 wire.Message - if rf, ok := ret.Get(0).(func(int, string) wire.Message); ok { - r0 = rf(addressIndex, message) + if rf, ok := ret.Get(0).(func([]*messages.SkycoinTransactionInput, []*messages.SkycoinTransactionOutput, string) wire.Message); ok { + r0 = rf(inputs, outputs, walletType) } else { r0 = ret.Get(0).(wire.Message) } var r1 error - if rf, ok := ret.Get(1).(func(int, string) error); ok { - r1 = rf(addressIndex, message) + if rf, ok := ret.Get(1).(func([]*messages.SkycoinTransactionInput, []*messages.SkycoinTransactionOutput, string) error); ok { + r1 = rf(inputs, outputs, walletType) } else { r1 = ret.Error(1) } @@ -366,20 +422,20 @@ func (_m *MockDevicer) SignMessage(addressIndex int, message string) (wire.Messa return r0, r1 } -// TransactionSign provides a mock function with given fields: inputs, outputs -func (_m *MockDevicer) TransactionSign(inputs []*messages.SkycoinTransactionInput, outputs []*messages.SkycoinTransactionOutput) (wire.Message, error) { - ret := _m.Called(inputs, outputs) +// UploadFirmware provides a mock function with given fields: payload, hash +func (_m *MockDevicer) UploadFirmware(payload []byte, hash [32]byte) (wire.Message, error) { + ret := _m.Called(payload, hash) var r0 wire.Message - if rf, ok := ret.Get(0).(func([]*messages.SkycoinTransactionInput, []*messages.SkycoinTransactionOutput) wire.Message); ok { - r0 = rf(inputs, outputs) + if rf, ok := ret.Get(0).(func([]byte, [32]byte) wire.Message); ok { + r0 = rf(payload, hash) } else { r0 = ret.Get(0).(wire.Message) } var r1 error - if rf, ok := ret.Get(1).(func([]*messages.SkycoinTransactionInput, []*messages.SkycoinTransactionOutput) error); ok { - r1 = rf(inputs, outputs) + if rf, ok := ret.Get(1).(func([]byte, [32]byte) error); ok { + r1 = rf(payload, hash) } else { r1 = ret.Error(1) } diff --git a/src/skywallet/skywallet_test.go b/src/skywallet/skywallet_test.go index d923d95..8505940 100644 --- a/src/skywallet/skywallet_test.go +++ b/src/skywallet/skywallet_test.go @@ -190,7 +190,7 @@ func (suite *devicerSuit) TestFirmwareUpload() { for _, tc := range tt { driverMock.On("DeviceType").Return(tc.deviceType) - err := device.FirmwareUpload([]byte{}, [32]byte{}) + _, err := device.UploadFirmware([]byte{}, [32]byte{}) suite.Equal(err, tc.err) }