Skip to content

Commit

Permalink
refactor(util): remove GenericError code (#1454)
Browse files Browse the repository at this point in the history
  • Loading branch information
b00f authored Sep 23, 2024
1 parent 9306bef commit 459c7d4
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
5 changes: 1 addition & 4 deletions crypto/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,10 @@ func (addr Address) String() string {
return treasuryAddressString
}

str, err := bech32m.EncodeFromBase256WithType(
str, _ := bech32m.EncodeFromBase256WithType(
AddressHRP,
addr[0],
addr[1:])
if err != nil {
panic(err.Error())
}

return str
}
Expand Down
9 changes: 0 additions & 9 deletions state/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/types/vote"
"github.com/pactus-project/pactus/util/errors"
"github.com/pactus-project/pactus/util/testsuite"
)

Expand Down Expand Up @@ -233,18 +232,10 @@ func (m *MockState) PendingTx(id tx.ID) *tx.Tx {
}

func (m *MockState) AddPendingTx(trx *tx.Tx) error {
if m.TestPool.HasTx(trx.ID()) {
return errors.Error(errors.ErrGeneric)
}

return m.TestPool.AppendTx(trx)
}

func (m *MockState) AddPendingTxAndBroadcast(trx *tx.Tx) error {
if m.TestPool.HasTx(trx.ID()) {
return errors.Error(errors.ErrGeneric)
}

return m.TestPool.AppendTxAndBroadcast(trx)
}

Expand Down
7 changes: 4 additions & 3 deletions txpool/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var _ TxPool = &MockTxPool{}

// MockTxPool is a testing mock.
type MockTxPool struct {
Txs []*tx.Tx
Txs []*tx.Tx
AppendError error
}

func MockingTxPool() *MockTxPool {
Expand Down Expand Up @@ -59,13 +60,13 @@ func (*MockTxPool) String() string {
func (m *MockTxPool) AppendTx(trx *tx.Tx) error {
m.Txs = append(m.Txs, trx)

return nil
return m.AppendError
}

func (m *MockTxPool) AppendTxAndBroadcast(trx *tx.Tx) error {
m.Txs = append(m.Txs, trx)

return nil
return m.AppendError
}

func (m *MockTxPool) RemoveTx(id hash.Hash) {
Expand Down
9 changes: 4 additions & 5 deletions wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/util/errors"
"github.com/pactus-project/pactus/util/testsuite"
"github.com/pactus-project/pactus/wallet"
"github.com/pactus-project/pactus/www/grpc"
Expand Down Expand Up @@ -366,7 +365,7 @@ func TestMakeTransferTx(t *testing.T) {
td.Close()

_, err := td.wallet.MakeTransferTx(td.RandAccAddress().String(), receiverInfo.String(), amt)
assert.Equal(t, errors.ErrGeneric, errors.Code(err))
assert.Error(t, err)
})
}

Expand Down Expand Up @@ -491,7 +490,7 @@ func TestMakeBondTx(t *testing.T) {
td.Close()

_, err := td.wallet.MakeBondTx(td.RandAccAddress().String(), receiver.Address().String(), "", amt)
assert.Equal(t, errors.ErrGeneric, errors.Code(err))
assert.Error(t, err)
})
}

Expand Down Expand Up @@ -535,7 +534,7 @@ func TestMakeUnbondTx(t *testing.T) {
td.Close()

_, err := td.wallet.MakeUnbondTx(td.RandAccAddress().String())
assert.Equal(t, errors.ErrGeneric, errors.Code(err))
assert.Error(t, err)
})
}

Expand Down Expand Up @@ -585,7 +584,7 @@ func TestMakeWithdrawTx(t *testing.T) {
td.Close()

_, err := td.wallet.MakeWithdrawTx(td.RandAccAddress().String(), receiverInfo.Address, amt)
assert.Equal(t, errors.ErrGeneric, errors.Code(err))
assert.Error(t, err)
})
}

Expand Down
4 changes: 3 additions & 1 deletion www/grpc/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grpc
import (
"context"
"encoding/hex"
"fmt"
"testing"

"github.com/pactus-project/pactus/types/amount"
Expand Down Expand Up @@ -111,7 +112,8 @@ func TestSendRawTransaction(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, res)
})
t.Run("Should fail, Not Broadcasted", func(t *testing.T) {
t.Run("Should fail and not broadcast", func(t *testing.T) {
td.mockState.TestPool.AppendError = fmt.Errorf("some error")
res, err := client.BroadcastTransaction(context.Background(),
&pactus.BroadcastTransactionRequest{SignedRawTransaction: hex.EncodeToString(data)})
assert.Error(t, err)
Expand Down

0 comments on commit 459c7d4

Please sign in to comment.