From 4edfc49d1bca2b28bc1d55411b8c5506bb508dd2 Mon Sep 17 00:00:00 2001 From: vincentysc Date: Sun, 1 Dec 2024 20:29:06 +0800 Subject: [PATCH] fix lint --- projection/account/account_test.go | 12 +- .../account_message/account_message_test.go | 76 +-- .../account_raw_transaction_test.go | 16 +- .../bridge_activity_matcher_test.go | 28 +- .../bridge_pending_activity_test.go | 36 +- projection/ibc_channel/ibc_channel.go | 8 +- projection/ibc_channel/ibc_channel_test.go | 54 +- projection/proposal/proposal_test.go | 80 +-- .../raw_transaction/raw_transaction_test.go | 12 +- projection/transaction/transaction_test.go | 16 +- projection/validatorstats/validatorstats.go | 2 +- usecase/coin/coin.go | 226 ++++---- usecase/coin/coin_benchmark_test.go | 8 +- usecase/coin/coin_test.go | 482 +++++++++--------- usecase/coin/dec_coin.go | 44 +- usecase/coin/dec_coin_test.go | 156 +++--- usecase/coin/decimal.go | 156 +++--- usecase/coin/decimal_test.go | 116 ++--- usecase/coin/denom.go | 24 +- usecase/coin/int.go | 108 ++-- usecase/coin/int_test.go | 55 +- usecase/coin/uint.go | 68 +-- usecase/coin/uint_test.go | 34 +- ...ty_ethereum_send_to_cosmos_handled_test.go | 2 +- usecase/event/msg_create_validator_test.go | 4 +- usecase/event/msgbeginredelegate_test.go | 8 +- usecase/event/msgdelegate_test.go | 8 +- usecase/event/msgundelegate_test.go | 8 +- ...ts_ethereum_send_to_cosmos_handled_test.go | 4 +- usecase/parser/genesis.go | 2 +- usecase/parser/msg.go | 12 +- usecase/parser/msg_begin_redelegate_test.go | 2 +- usecase/parser/msg_submit_proposal_test.go | 6 +- usecase/parser/msg_undelegate_test.go | 2 +- usecase/parser/utils/tx.go | 4 +- 35 files changed, 937 insertions(+), 942 deletions(-) diff --git a/projection/account/account_test.go b/projection/account/account_test.go index 4e675070e..269648116 100644 --- a/projection/account/account_test.go +++ b/projection/account/account_test.go @@ -14,8 +14,8 @@ import ( account_view "github.com/crypto-com/chain-indexing/projection/account/view" "github.com/crypto-com/chain-indexing/usecase/coin" event_usecase "github.com/crypto-com/chain-indexing/usecase/event" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" ) func NewAccountProjection(rdbConn rdb.Conn, client cosmosapp.Client) *account.Account { @@ -118,7 +118,7 @@ func TestAccount_HandleEvents(t *testing.T) { coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, nil, @@ -145,7 +145,7 @@ func TestAccount_HandleEvents(t *testing.T) { Balance: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -194,7 +194,7 @@ func TestAccount_HandleEvents(t *testing.T) { coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, nil, @@ -212,7 +212,7 @@ func TestAccount_HandleEvents(t *testing.T) { Balance: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, }, @@ -237,7 +237,7 @@ func TestAccount_HandleEvents(t *testing.T) { projection := NewAccountProjection(mockRDbConn, mockClient) err := projection.HandleEvents(1, tc.Events) - require.NoError(t, err) + assert.NoError(t, err) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/account_message/account_message_test.go b/projection/account_message/account_message_test.go index 0495afe8d..8d6eb55cc 100644 --- a/projection/account_message/account_message_test.go +++ b/projection/account_message/account_message_test.go @@ -19,8 +19,8 @@ import ( "github.com/crypto-com/chain-indexing/usecase/model" usecase_model "github.com/crypto-com/chain-indexing/usecase/model" ibc_model "github.com/crypto-com/chain-indexing/usecase/model/ibc" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" ) func NewAccountMessageProjection(rdbConn rdb.Conn) *account_message.AccountMessage { @@ -101,7 +101,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -173,7 +173,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -225,7 +225,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -236,7 +236,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -311,7 +311,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -322,7 +322,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -492,7 +492,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -555,7 +555,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -608,7 +608,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -670,7 +670,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -721,7 +721,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -780,7 +780,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -844,7 +844,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { InitialDeposit: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -918,7 +918,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { InitialDeposit: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -975,7 +975,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -983,7 +983,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { InitialDeposit: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1049,7 +1049,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1057,7 +1057,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { InitialDeposit: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1115,7 +1115,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { InitialDeposit: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1182,7 +1182,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { InitialDeposit: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1234,7 +1234,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1294,7 +1294,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { Amount: coin.Coins{ { Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1459,7 +1459,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { TendermintPubkey: "TendermintPubkey", Amount: coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1531,7 +1531,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { TendermintPubkey: "TendermintPubkey", Amount: coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1693,11 +1693,11 @@ func TestAccountMessage_HandleEvents(t *testing.T) { }), Amount: coin.Coin{ Denom: "AmountDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, AutoClaimedRewards: coin.Coin{ Denom: "AutoClaimedRewardsDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, DelegatorAddress: "DelegatorAddress", ValidatorAddress: "ValidatorAddress", @@ -1755,11 +1755,11 @@ func TestAccountMessage_HandleEvents(t *testing.T) { }, Amount: coin.Coin{ Denom: "AmountDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, AutoClaimedRewards: coin.Coin{ Denom: "AutoClaimedRewardsDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, DelegatorAddress: "DelegatorAddress", ValidatorAddress: "ValidatorAddress", @@ -1808,11 +1808,11 @@ func TestAccountMessage_HandleEvents(t *testing.T) { }), Amount: coin.Coin{ Denom: "AmountDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, AutoClaimedRewards: coin.Coin{ Denom: "AutoClaimedRewardsDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, DelegatorAddress: "DelegatorAddress", ValidatorAddress: "ValidatorAddress", @@ -1871,11 +1871,11 @@ func TestAccountMessage_HandleEvents(t *testing.T) { }, Amount: coin.Coin{ Denom: "AmountDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, AutoClaimedRewards: coin.Coin{ Denom: "AutoClaimedRewardsDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, DelegatorAddress: "DelegatorAddress", ValidatorAddress: "ValidatorAddress", @@ -1925,11 +1925,11 @@ func TestAccountMessage_HandleEvents(t *testing.T) { }), Amount: coin.Coin{ Denom: "AmountDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, AutoClaimedRewards: coin.Coin{ Denom: "AutoClaimedRewardsDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, DelegatorAddress: "DelegatorAddress", ValidatorSrcAddress: "ValidatorSrcAddress", @@ -1988,11 +1988,11 @@ func TestAccountMessage_HandleEvents(t *testing.T) { }, Amount: coin.Coin{ Denom: "AmountDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, AutoClaimedRewards: coin.Coin{ Denom: "AutoClaimedRewardsDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, DelegatorAddress: "DelegatorAddress", ValidatorSrcAddress: "ValidatorSrcAddress", @@ -5001,7 +5001,7 @@ func TestAccountMessage_HandleEvents(t *testing.T) { projection := NewAccountMessageProjection(mockRDbConn) err := projection.HandleEvents(1, tc.Events) - require.NoError(t, err) + assert.NoError(t, err) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/account_raw_transaction/account_raw_transaction_test.go b/projection/account_raw_transaction/account_raw_transaction_test.go index 17714f9ae..dad453ecd 100644 --- a/projection/account_raw_transaction/account_raw_transaction_test.go +++ b/projection/account_raw_transaction/account_raw_transaction_test.go @@ -8,8 +8,8 @@ import ( "github.com/crypto-com/chain-indexing/external/primptr" "github.com/crypto-com/chain-indexing/projection/account_raw_transaction" account_raw_transaction_view "github.com/crypto-com/chain-indexing/projection/account_raw_transaction/view" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/crypto-com/chain-indexing/appinterface/rdb" "github.com/crypto-com/chain-indexing/appinterface/rdb/test" @@ -108,7 +108,7 @@ func TestAccountRawTransaction_HandleEvents(t *testing.T) { AccountSequence: 0, }, }, - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -148,7 +148,7 @@ func TestAccountRawTransaction_HandleEvents(t *testing.T) { Success: true, Code: 0, Log: "Log", - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -189,7 +189,7 @@ func TestAccountRawTransaction_HandleEvents(t *testing.T) { Success: true, Code: 0, Log: "Log", - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -291,7 +291,7 @@ func TestAccountRawTransaction_HandleEvents(t *testing.T) { AccountSequence: 0, }, }, - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -331,7 +331,7 @@ func TestAccountRawTransaction_HandleEvents(t *testing.T) { Success: false, Code: 0, Log: "Log", - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -372,7 +372,7 @@ func TestAccountRawTransaction_HandleEvents(t *testing.T) { Success: false, Code: 0, Log: "Log", - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -444,7 +444,7 @@ func TestAccountRawTransaction_HandleEvents(t *testing.T) { projection := NewAccountRawTransactionProjection(mockRDbConn) err := projection.HandleEvents(1, tc.Events) - require.NoError(t, err) + assert.NoError(t, err) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/bridge_activity/bridge_activity_matcher/bridge_activity_matcher_test.go b/projection/bridge_activity/bridge_activity_matcher/bridge_activity_matcher_test.go index a8ddd0e0b..2b1c3a9c2 100644 --- a/projection/bridge_activity/bridge_activity_matcher/bridge_activity_matcher_test.go +++ b/projection/bridge_activity/bridge_activity_matcher/bridge_activity_matcher_test.go @@ -5,8 +5,8 @@ import ( "testing" sq "github.com/Masterminds/squirrel" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/crypto-com/chain-indexing/appinterface/rdb" "github.com/crypto-com/chain-indexing/appinterface/rdb/test" @@ -105,7 +105,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { ToAddress: "to-address", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -239,7 +239,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { ToAddress: "to-address", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -397,7 +397,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { ToAddress: "to-address", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -562,7 +562,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { ToAddress: "to-address", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -588,7 +588,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { ToAddress: "to-address", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-1"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -761,7 +761,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { MaybeDestinationSmartContractAddress: nil, MaybeChannelId: nil, LinkId: "link-id", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -956,7 +956,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { MaybeDestinationSmartContractAddress: nil, MaybeChannelId: nil, LinkId: "link-id", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1010,7 +1010,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { MaybeDestinationSmartContractAddress: nil, MaybeChannelId: nil, LinkId: "link-id-2", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1229,7 +1229,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { MaybeDestinationSmartContractAddress: nil, MaybeChannelId: nil, LinkId: "link-id", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1401,7 +1401,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { MaybeDestinationSmartContractAddress: nil, MaybeChannelId: nil, LinkId: "link-id", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1543,7 +1543,7 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { MaybeDestinationSmartContractAddress: nil, MaybeChannelId: nil, LinkId: "link-id", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1618,10 +1618,10 @@ func TestBridgeActivityMatcher_HandleEvents(t *testing.T) { projection := NewBridgeActivityMatcherProjection(mockThisRDbConn, tc.Config) onInitErr := projection.OnInit() - require.NoError(t, onInitErr) + assert.NoError(t, onInitErr) execErr := projection.Exec() - require.NoError(t, execErr) + assert.NoError(t, execErr) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/bridge_activity/bridge_pending_activity/bridge_pending_activity_test.go b/projection/bridge_activity/bridge_pending_activity/bridge_pending_activity_test.go index 7127fb1f8..d8335d56a 100644 --- a/projection/bridge_activity/bridge_pending_activity/bridge_pending_activity_test.go +++ b/projection/bridge_activity/bridge_pending_activity/bridge_pending_activity_test.go @@ -6,8 +6,8 @@ import ( "testing" sq "github.com/Masterminds/squirrel" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/crypto-com/chain-indexing/appinterface/rdb" "github.com/crypto-com/chain-indexing/appinterface/rdb/test" @@ -240,7 +240,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -261,7 +261,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-1"), - Amount: *coin.NewInt(200), + Amount: coin.NewInt(200), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -373,7 +373,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -485,7 +485,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -721,7 +721,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -916,7 +916,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -937,7 +937,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-1"), - Amount: *coin.NewInt(2000), + Amount: coin.NewInt(2000), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1068,7 +1068,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1298,7 +1298,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1424,7 +1424,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1609,7 +1609,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1630,7 +1630,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-1"), - Amount: *coin.NewInt(2000), + Amount: coin.NewInt(2000), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1816,7 +1816,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1957,7 +1957,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-0"), - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -1978,7 +1978,7 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { ToAddress: "to", MaybeToSmartContractAddress: nil, MaybeChannelId: primptr.String("channel-1"), - Amount: *coin.NewInt(200), + Amount: coin.NewInt(200), MaybeDenom: primptr.String("basecro"), MaybeBridgeFeeAmount: nil, MaybeBridgeFeeDenom: nil, @@ -2131,10 +2131,10 @@ func TestBridgePendingActivity_HandleEvents(t *testing.T) { projection := NewBridgePendingActivityProjection(mockRDbConn, tc.Config) onInitErr := projection.OnInit() - require.NoError(t, onInitErr) + assert.NoError(t, onInitErr) handleErr := projection.HandleEvents(1, tc.Events) - require.NoError(t, handleErr) + assert.NoError(t, handleErr) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/ibc_channel/ibc_channel.go b/projection/ibc_channel/ibc_channel.go index 214824a38..4f9f81399 100644 --- a/projection/ibc_channel/ibc_channel.go +++ b/projection/ibc_channel/ibc_channel.go @@ -1109,7 +1109,7 @@ func subtractTokenOnThisChain( ) error { for i, token := range bondedTokens.OnThisChain { if token.Denom == newToken.Denom { - bondedTokens.OnThisChain[i].Amount = *bondedTokens.OnThisChain[i].Amount.Sub(&newToken.Amount) + bondedTokens.OnThisChain[i].Amount = bondedTokens.OnThisChain[i].Amount.Sub(newToken.Amount) if bondedTokens.OnThisChain[i].Amount.IsZero() { bondedTokens.OnThisChain = append(bondedTokens.OnThisChain[:i], bondedTokens.OnThisChain[i+1:]...) } @@ -1125,7 +1125,7 @@ func subtractTokenOnCounterpartyChain( ) error { for i, token := range bondedTokens.OnCounterpartyChain { if token.Denom == newToken.Denom { - bondedTokens.OnCounterpartyChain[i].Amount = *bondedTokens.OnCounterpartyChain[i].Amount.Sub(&newToken.Amount) + bondedTokens.OnCounterpartyChain[i].Amount = bondedTokens.OnCounterpartyChain[i].Amount.Sub(newToken.Amount) if bondedTokens.OnCounterpartyChain[i].Amount.IsZero() { bondedTokens.OnCounterpartyChain = append(bondedTokens.OnCounterpartyChain[:i], bondedTokens.OnCounterpartyChain[i+1:]...) } @@ -1143,7 +1143,7 @@ func addTokenOnCounterpartyChain( for i, token := range bondedTokens.OnCounterpartyChain { if token.Denom == newToken.Denom { // This token already has a record on bondedTokens.OnCounterpartyChain - bondedTokens.OnCounterpartyChain[i].Amount = *bondedTokens.OnCounterpartyChain[i].Amount.Add(&newToken.Amount) + bondedTokens.OnCounterpartyChain[i].Amount = bondedTokens.OnCounterpartyChain[i].Amount.Add(newToken.Amount) return } } @@ -1158,7 +1158,7 @@ func addTokenOnThisChain( for i, token := range bondedTokens.OnThisChain { if token.Denom == newToken.Denom { // This token already has a record on bondedTokens.OnThisChain - bondedTokens.OnThisChain[i].Amount = *bondedTokens.OnThisChain[i].Amount.Add(&newToken.Amount) + bondedTokens.OnThisChain[i].Amount = bondedTokens.OnThisChain[i].Amount.Add(newToken.Amount) return } } diff --git a/projection/ibc_channel/ibc_channel_test.go b/projection/ibc_channel/ibc_channel_test.go index 14195c50d..9601cd80c 100644 --- a/projection/ibc_channel/ibc_channel_test.go +++ b/projection/ibc_channel/ibc_channel_test.go @@ -11,8 +11,8 @@ import ( "github.com/crypto-com/chain-indexing/external/utctime" ibc_channel_view "github.com/crypto-com/chain-indexing/projection/ibc_channel/view" "github.com/crypto-com/chain-indexing/usecase/coin" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/crypto-com/chain-indexing/appinterface/rdb" "github.com/crypto-com/chain-indexing/appinterface/rdb/test" @@ -773,13 +773,13 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, }, @@ -793,17 +793,17 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, { Denom: "DestinationPort/DestinationChannel/DENOM", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -890,13 +890,13 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, }, @@ -927,17 +927,17 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, { Denom: "DestinationPort/DestinationChannel/DENOM", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, }, @@ -1160,17 +1160,17 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, { Denom: "DestinationPort/DestinationChannel/DENOM", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1184,13 +1184,13 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, }, @@ -1269,17 +1269,17 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, { Denom: "DestinationPort/DestinationChannel/DENOM", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1293,13 +1293,13 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, }, @@ -1378,17 +1378,17 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, { Denom: "DestinationPort/DestinationChannel/DENOM", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -1402,13 +1402,13 @@ func TestIBCChannel_HandleEvents(t *testing.T) { OnThisChain: []ibc_channel_view.BondedToken{ { Denom: "OnThisChainDenom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, OnCounterpartyChain: []ibc_channel_view.BondedToken{ { Denom: "OnCounterpartyChainDenom", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, }, @@ -1539,7 +1539,7 @@ func TestIBCChannel_HandleEvents(t *testing.T) { projection := NewIBCChannelProjection(mockRDbConn) err := projection.HandleEvents(1, tc.Events) - require.NoError(t, err) + assert.NoError(t, err) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/proposal/proposal_test.go b/projection/proposal/proposal_test.go index 966a8fe69..03e198899 100644 --- a/projection/proposal/proposal_test.go +++ b/projection/proposal/proposal_test.go @@ -8,8 +8,8 @@ import ( "time" sq "github.com/Masterminds/squirrel" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/crypto-com/chain-indexing/appinterface/cosmosapp" "github.com/crypto-com/chain-indexing/appinterface/projection/rdbparambase" @@ -95,7 +95,7 @@ func TestProposal_HandleEvents(t *testing.T) { }, ProposerAddress: "ProposerAddress", InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }, }, @@ -148,10 +148,10 @@ func TestProposal_HandleEvents(t *testing.T) { MaybeProposerOperatorAddress: primptr.String("ProposerOperatorAddress"), Data: nil, InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalVote: big.NewInt(0), TransactionHash: "TxHash", @@ -181,7 +181,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -235,7 +235,7 @@ func TestProposal_HandleEvents(t *testing.T) { }, ProposerAddress: "ProposerAddress", InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }, }, @@ -301,10 +301,10 @@ func TestProposal_HandleEvents(t *testing.T) { }, }, InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalVote: big.NewInt(0), TransactionHash: "TxHash", @@ -334,7 +334,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -380,12 +380,12 @@ func TestProposal_HandleEvents(t *testing.T) { Type: "Type", RecipientAddress: "RecipientAddress", Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 1000), + coin.NewInt64Coin("DENOM", 1000), }, }, ProposerAddress: "ProposerAddress", InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }, }, @@ -443,15 +443,15 @@ func TestProposal_HandleEvents(t *testing.T) { Type: "Type", RecipientAddress: "RecipientAddress", Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 1000), + coin.NewInt64Coin("DENOM", 1000), }, }, }, InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalVote: big.NewInt(0), TransactionHash: "TxHash", @@ -481,7 +481,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -534,7 +534,7 @@ func TestProposal_HandleEvents(t *testing.T) { }, ProposerAddress: "ProposerAddress", InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }, }, @@ -599,10 +599,10 @@ func TestProposal_HandleEvents(t *testing.T) { }, }, InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalVote: big.NewInt(0), TransactionHash: "TxHash", @@ -632,7 +632,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -679,7 +679,7 @@ func TestProposal_HandleEvents(t *testing.T) { }, ProposerAddress: "ProposerAddress", InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }, }, @@ -732,10 +732,10 @@ func TestProposal_HandleEvents(t *testing.T) { MaybeProposerOperatorAddress: primptr.String("ProposerOperatorAddress"), Data: nil, InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalVote: big.NewInt(0), TransactionHash: "TxHash", @@ -765,7 +765,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -820,7 +820,7 @@ func TestProposal_HandleEvents(t *testing.T) { }, }, InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, Metadata: "Metadata", }, @@ -886,10 +886,10 @@ func TestProposal_HandleEvents(t *testing.T) { }, }, InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalVote: big.NewInt(0), TransactionHash: "TxHash", @@ -921,7 +921,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -963,7 +963,7 @@ func TestProposal_HandleEvents(t *testing.T) { MaybeProposalId: primptr.String("MaybeProposalId"), Proposer: "Proposer", InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, Metadata: "Metadata", Messages: []interface{}{ @@ -1028,10 +1028,10 @@ func TestProposal_HandleEvents(t *testing.T) { }, }, InitialDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, TotalVote: big.NewInt(0), TransactionHash: "TxHash", @@ -1062,7 +1062,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -1414,7 +1414,7 @@ func TestProposal_HandleEvents(t *testing.T) { ProposalId: "ProposalId", Depositor: "Depositor", Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }, }, @@ -1428,7 +1428,7 @@ func TestProposal_HandleEvents(t *testing.T) { ProposalRow: view.ProposalRow{ ProposalId: "ProposalId", TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 200), + coin.NewInt64Coin("DENOM", 200), }, }, }, nil) @@ -1436,7 +1436,7 @@ func TestProposal_HandleEvents(t *testing.T) { On("Update", &view.ProposalRow{ ProposalId: "ProposalId", TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 300), + coin.NewInt64Coin("DENOM", 300), }, }). Return(nil) @@ -1475,7 +1475,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -1516,7 +1516,7 @@ func TestProposal_HandleEvents(t *testing.T) { ProposalId: "ProposalId", Depositor: "Depositor", Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }, }, @@ -1529,7 +1529,7 @@ func TestProposal_HandleEvents(t *testing.T) { ProposalRow: view.ProposalRow{ ProposalId: "ProposalId", TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 200), + coin.NewInt64Coin("DENOM", 200), }, }, }, nil) @@ -1537,7 +1537,7 @@ func TestProposal_HandleEvents(t *testing.T) { On("Update", &view.ProposalRow{ ProposalId: "ProposalId", TotalDeposit: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 300), + coin.NewInt64Coin("DENOM", 300), }, }). Return(nil) @@ -1576,7 +1576,7 @@ func TestProposal_HandleEvents(t *testing.T) { DepositAtBlockHeight: 1, DepositAtBlockTime: utctime.UTCTime{}, Amount: []coin.Coin{ - *coin.NewInt64Coin("DENOM", 100), + coin.NewInt64Coin("DENOM", 100), }, }). Return(nil) @@ -2618,7 +2618,7 @@ func TestProposal_HandleEvents(t *testing.T) { projection := NewProposalProjection(mockRDbConn, mockClient) err := projection.HandleEvents(1, tc.Events) - require.NoError(t, err) + assert.NoError(t, err) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/raw_transaction/raw_transaction_test.go b/projection/raw_transaction/raw_transaction_test.go index a1a2e5971..a8e81779f 100644 --- a/projection/raw_transaction/raw_transaction_test.go +++ b/projection/raw_transaction/raw_transaction_test.go @@ -8,8 +8,8 @@ import ( "github.com/crypto-com/chain-indexing/external/primptr" "github.com/crypto-com/chain-indexing/projection/raw_transaction" raw_transaction_view "github.com/crypto-com/chain-indexing/projection/raw_transaction/view" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/crypto-com/chain-indexing/appinterface/rdb" "github.com/crypto-com/chain-indexing/appinterface/rdb/test" @@ -107,7 +107,7 @@ func TestRawTransaction_HandleEvents(t *testing.T) { AccountSequence: 0, }, }, - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -147,7 +147,7 @@ func TestRawTransaction_HandleEvents(t *testing.T) { Success: true, Code: 0, Log: "Log", - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -249,7 +249,7 @@ func TestRawTransaction_HandleEvents(t *testing.T) { AccountSequence: 0, }, }, - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -289,7 +289,7 @@ func TestRawTransaction_HandleEvents(t *testing.T) { Success: false, Code: 0, Log: "Log", - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -361,7 +361,7 @@ func TestRawTransaction_HandleEvents(t *testing.T) { projection := NewRawTransactionProjection(mockRDbConn) err := projection.HandleEvents(1, tc.Events) - require.NoError(t, err) + assert.NoError(t, err) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/transaction/transaction_test.go b/projection/transaction/transaction_test.go index 51ad5630e..885d443eb 100644 --- a/projection/transaction/transaction_test.go +++ b/projection/transaction/transaction_test.go @@ -6,8 +6,8 @@ import ( sq "github.com/Masterminds/squirrel" "github.com/crypto-com/chain-indexing/external/primptr" + "github.com/stretchr/testify/assert" testify_mock "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/crypto-com/chain-indexing/appinterface/rdb" "github.com/crypto-com/chain-indexing/appinterface/rdb/test" @@ -109,7 +109,7 @@ func TestTransaction_HandleEvents(t *testing.T) { }, }, Senders: []model_usecase.TransactionSigner{}, - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -133,7 +133,7 @@ func TestTransaction_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -161,7 +161,7 @@ func TestTransaction_HandleEvents(t *testing.T) { Success: true, Code: 0, Log: "Log", - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -261,7 +261,7 @@ func TestTransaction_HandleEvents(t *testing.T) { }, }, Senders: []model_usecase.TransactionSigner{}, - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -285,7 +285,7 @@ func TestTransaction_HandleEvents(t *testing.T) { Amount: coin.Coins{ coin.Coin{ Denom: "Denom", - Amount: *coin.NewInt(100), + Amount: coin.NewInt(100), }, }, }, @@ -313,7 +313,7 @@ func TestTransaction_HandleEvents(t *testing.T) { Success: false, Code: 0, Log: "Log", - Fee: coin.Coins{*coin.MustNewCoinFromString("basetcro", "1")}, + Fee: coin.Coins{coin.MustNewCoinFromString("basetcro", "1")}, FeePayer: "FeePayer", FeeGranter: "FeeGranter", GasWanted: 200, @@ -381,7 +381,7 @@ func TestTransaction_HandleEvents(t *testing.T) { projection := NewTransactionProjection(mockRDbConn) err := projection.HandleEvents(1, tc.Events) - require.NoError(t, err) + assert.NoError(t, err) for _, m := range mocks { m.AssertExpectations(t) diff --git a/projection/validatorstats/validatorstats.go b/projection/validatorstats/validatorstats.go index 0dea392e4..c33f7a073 100644 --- a/projection/validatorstats/validatorstats.go +++ b/projection/validatorstats/validatorstats.go @@ -133,7 +133,7 @@ func (projection *ValidatorStats) HandleEvents(height int64, events []event_enti return fmt.Errorf("error adding delegate: %v", err) } } else if undelegateEvent, ok := event.(*event_usecase.MsgUndelegate); ok { - totalDelegate = totalDelegate.Add(*undelegateEvent.Amount.Neg()) + totalDelegate = totalDelegate.Add(undelegateEvent.Amount.Neg()) if err != nil { return fmt.Errorf("error subtracting delegate: %v", err) } diff --git a/usecase/coin/coin.go b/usecase/coin/coin.go index 935663250..e7b51c867 100644 --- a/usecase/coin/coin.go +++ b/usecase/coin/coin.go @@ -17,7 +17,7 @@ type Coin struct { // MustNewCoin returns a new coin with a denomination and amount. It will panic // if the amount is negative or if the denomination is invalid. -func MustNewCoin(denom string, amount Int) *Coin { +func MustNewCoin(denom string, amount Int) Coin { result, err := NewCoin(denom, amount) if err != nil { panic(err) @@ -27,22 +27,22 @@ func MustNewCoin(denom string, amount Int) *Coin { // NewCoin returns a new coin with a denomination and amount. It returns error // if the amount is negative or if the denomination is invalid. -func NewCoin(denom string, amount Int) (*Coin, error) { +func NewCoin(denom string, amount Int) (Coin, error) { coin := Coin{ Denom: denom, Amount: amount, } if err := coin.Validate(); err != nil { - return &Coin{}, err + return Coin{}, err } - return &coin, nil + return coin, nil } // MustNewCoinFromString returns a new coin from calling NewCoinFromString. It // behaves the same except it will panic on any error. -func MustNewCoinFromString(denom string, amountStr string) *Coin { +func MustNewCoinFromString(denom string, amountStr string) Coin { amount, err := NewCoinFromString(denom, amountStr) if err != nil { panic(err) @@ -53,18 +53,18 @@ func MustNewCoinFromString(denom string, amountStr string) *Coin { // NewCoinFromString returns a new coin with a denomination and string amount. // It returns an error if the amount is non-integer, negative or if the denom // is invalid. -func NewCoinFromString(denom string, amountStr string) (*Coin, error) { +func NewCoinFromString(denom string, amountStr string) (Coin, error) { amount, ok := NewIntFromString(amountStr) if !ok { - return &Coin{}, fmt.Errorf("invalid coin amount: %s", amountStr) + return Coin{}, fmt.Errorf("invalid coin amount: %s", amountStr) } return NewCoin(denom, amount) } // NewInt64Coin returns a new coin with a denomination and amount. It will panic // if the amount is negative. -func NewInt64Coin(denom string, amount int64) *Coin { - result, err := NewCoin(denom, *NewInt(amount)) +func NewInt64Coin(denom string, amount int64) Coin { + result, err := NewCoin(denom, NewInt(amount)) // TODO: Return error instead of panic if err != nil { panic(err) @@ -75,27 +75,27 @@ func NewInt64Coin(denom string, amount int64) *Coin { // NewZeroCoin returns a new coin with zero unit of denomination. It will panic // if the denomination is invalid. -func NewZeroCoin(denom string) *Coin { +func NewZeroCoin(denom string) Coin { coin := Coin{ Denom: denom, - Amount: *NewInt(0), + Amount: NewInt(0), } if err := coin.Validate(); err != nil { panic(err) } - return &coin + return coin } // String provides a human-readable representation of a coin -func (coin *Coin) String() string { - return fmt.Sprintf("%v%v", &coin.Amount, coin.Denom) +func (coin Coin) String() string { + return fmt.Sprintf("%v%v", coin.Amount, coin.Denom) } // Validate returns an error if the Coin has a negative amount or if // the denom is invalid. -func (coin *Coin) Validate() error { +func (coin Coin) Validate() error { if err := ValidateDenom(coin.Denom); err != nil { return err } @@ -108,88 +108,88 @@ func (coin *Coin) Validate() error { } // IsValid returns true if the Coin has a non-negative amount and the denom is valid. -func (coin *Coin) IsValid() bool { +func (coin Coin) IsValid() bool { return coin.Validate() == nil } // IsZero returns if this represents no money -func (coin *Coin) IsZero() bool { +func (coin Coin) IsZero() bool { return coin.Amount.IsZero() } // IsGTE returns true if they are the same type and the receiver is // an equal or greater value -func (coin *Coin) IsGTE(other *Coin) bool { +func (coin Coin) IsGTE(other Coin) bool { if coin.Denom != other.Denom { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, other.Denom)) } - return !coin.Amount.LT(&other.Amount) + return !coin.Amount.LT(other.Amount) } // IsLT returns true if they are the same type and the receiver is // a smaller value -func (coin *Coin) IsLT(other *Coin) bool { +func (coin Coin) IsLT(other Coin) bool { if coin.Denom != other.Denom { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, other.Denom)) } - return coin.Amount.LT(&other.Amount) + return coin.Amount.LT(other.Amount) } // IsEqual returns true if the two sets of Coins have the same value -func (coin *Coin) IsEqual(other *Coin) bool { +func (coin Coin) IsEqual(other Coin) bool { if coin.Denom != other.Denom { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, other.Denom)) } - return coin.Amount.Equal(&other.Amount) + return coin.Amount.Equal(other.Amount) } // Add adds amounts of two coins with same denom. If the coins differ in denom then // it panics. -func (coin *Coin) Add(coinB *Coin) *Coin { +func (coin Coin) Add(coinB Coin) Coin { if coin.Denom != coinB.Denom { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, coinB.Denom)) } - return &Coin{coin.Denom, *coin.Amount.Add(&coinB.Amount)} + return Coin{coin.Denom, coin.Amount.Add(coinB.Amount)} } // Sub subtracts amounts of two coins with same denom. If the coins differ in denom // then it panics. -func (coin *Coin) Sub(coinB *Coin) *Coin { +func (coin Coin) Sub(coinB Coin) Coin { if coin.Denom != coinB.Denom { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, coinB.Denom)) } - res := Coin{coin.Denom, *coin.Amount.Sub(&coinB.Amount)} + res := Coin{coin.Denom, coin.Amount.Sub(coinB.Amount)} if res.IsNegative() { panic("negative coin amount") } - return &res + return res } // Neg negates the amount and return a new Coin -func (coin *Coin) Neg() *Coin { - return &Coin{ +func (coin Coin) Neg() Coin { + return Coin{ Denom: coin.Denom, - Amount: *coin.Amount.Neg(), + Amount: coin.Amount.Neg(), } } // IsPositive returns true if coin amount is positive. // // TODO: Remove once unsigned integers are used. -func (coin *Coin) IsPositive() bool { +func (coin Coin) IsPositive() bool { return coin.Amount.Sign() == 1 } // IsNegative returns true if the coin amount is negative and false otherwise. // // TODO: Remove once unsigned integers are used. -func (coin *Coin) IsNegative() bool { +func (coin Coin) IsNegative() bool { return coin.Amount.Sign() == -1 } @@ -201,7 +201,7 @@ type Coins []Coin // MustNewCoins constructs a new coin set. The provided coins will be sanitized byremoving // zero coins and sorting the coin set. A panic will occur if the coin set is not valid. -func MustNewCoins(coins ...Coin) *Coins { +func MustNewCoins(coins ...Coin) Coins { result, err := NewCoins(coins...) if err != nil { panic(err) @@ -212,7 +212,7 @@ func MustNewCoins(coins ...Coin) *Coins { // NewCoins constructs a new coin set. The provided coins will be sanitized by removing // zero coins and sorting the coin set. A panic will occur if the coin set is not valid. -func NewCoins(coins ...Coin) (*Coins, error) { +func NewCoins(coins ...Coin) (Coins, error) { newCoins := sanitizeCoins(coins) if err := newCoins.Validate(); err != nil { return nil, fmt.Errorf("invalid coin set %s: %w", newCoins, err) @@ -226,10 +226,10 @@ func NewEmptyCoins() Coins { return Coins{} } -func sanitizeCoins(coins []Coin) *Coins { +func sanitizeCoins(coins []Coin) Coins { newCoins := removeZeroCoins(coins) if len(newCoins) == 0 { - return &Coins{} + return Coins{} } return newCoins.Sort() @@ -239,12 +239,12 @@ type coinsJSON Coins // MarshalJSON implements a custom JSON marshaller for the Coins type to allow // nil Coins to be encoded as an empty array. -func (coins *Coins) MarshalJSON() ([]byte, error) { - if *coins == nil { +func (coins Coins) MarshalJSON() ([]byte, error) { + if coins == nil { return json.Marshal(coinsJSON(Coins{})) } - return json.Marshal(coinsJSON(*coins)) + return json.Marshal(coinsJSON(coins)) } // UnmarshalJSON implements a custom JSON unmarshaller for the Coins type to allow @@ -266,13 +266,13 @@ func (coins *Coins) UnmarshalJSON(data []byte) error { return nil } -func (coins *Coins) String() string { - if len(*coins) == 0 { +func (coins Coins) String() string { + if len(coins) == 0 { return "" } out := "" - for _, coin := range *coins { + for _, coin := range coins { out += fmt.Sprintf("%v,", coin.String()) } return out[:len(out)-1] @@ -280,31 +280,31 @@ func (coins *Coins) String() string { // Validate checks that the Coins are sorted, have positive amount, with a valid and unique // denomination (i.e no duplicates). Otherwise, it returns an error. -func (coins *Coins) Validate() error { - switch len(*coins) { +func (coins Coins) Validate() error { + switch len(coins) { case 0: return nil case 1: - if err := ValidateDenom((*coins)[0].Denom); err != nil { + if err := ValidateDenom(coins[0].Denom); err != nil { return err } - if !(*coins)[0].IsPositive() { - return fmt.Errorf("coin %s amount is not positive", (*coins)[0].String()) + if !coins[0].IsPositive() { + return fmt.Errorf("coin %s amount is not positive", coins[0]) } return nil default: // check single coin case - if err := (&Coins{(*coins)[0]}).Validate(); err != nil { + if err := (Coins{coins[0]}).Validate(); err != nil { return err } - lowDenom := (*coins)[0].Denom + lowDenom := coins[0].Denom seenDenoms := make(map[string]bool) seenDenoms[lowDenom] = true - for _, coin := range (*coins)[1:] { + for _, coin := range coins[1:] { if seenDenoms[coin.Denom] { return fmt.Errorf("duplicate denomination %s", coin.Denom) } @@ -329,7 +329,7 @@ func (coins *Coins) Validate() error { // IsValid calls Validate and returns true when the Coins are sorted, have positive amount, with a // valid and unique denomination (i.e no duplicates). -func (coins *Coins) IsValid() bool { +func (coins Coins) IsValid() bool { return coins.Validate() == nil } @@ -344,7 +344,7 @@ func (coins *Coins) IsValid() bool { // // CONTRACT: Add will never return Coins where one Coin has a non-positive // amount. In otherwords, IsValid will always return true. -func (coins *Coins) Add(coinsB ...Coin) Coins { +func (coins Coins) Add(coinsB ...Coin) Coins { return coins.safeAdd(coinsB) } @@ -353,10 +353,10 @@ func (coins *Coins) Add(coinsB ...Coin) Coins { // other set is returned. Otherwise, the coins are compared in order of their // denomination and addition only occurs when the denominations match, otherwise // the coin is simply added to the sum assuming it's not zero. -func (coins *Coins) safeAdd(coinsB Coins) Coins { +func (coins Coins) safeAdd(coinsB Coins) Coins { sum := ([]Coin)(nil) indexA, indexB := 0, 0 - lenA, lenB := len(*coins), len(coinsB) + lenA, lenB := len(coins), len(coinsB) for { if indexA == lenA { @@ -369,10 +369,10 @@ func (coins *Coins) safeAdd(coinsB Coins) Coins { return append(sum, removeZeroCoins(coinsB[indexB:])...) } else if indexB == lenB { // return set A (excluding zero coins) if set B is empty - return append(sum, removeZeroCoins((*coins)[indexA:])...) + return append(sum, removeZeroCoins(coins[indexA:])...) } - coinA, coinB := (*coins)[indexA], coinsB[indexB] + coinA, coinB := coins[indexA], coinsB[indexB] switch strings.Compare(coinA.Denom, coinB.Denom) { case -1: // coin A denom < coin B denom @@ -383,9 +383,9 @@ func (coins *Coins) safeAdd(coinsB Coins) Coins { indexA++ case 0: // coin A denom == coin B denom - res := coinA.Add(&coinB) + res := coinA.Add(coinB) if !res.IsZero() { - sum = append(sum, *res) + sum = append(sum, res) } indexA++ @@ -403,13 +403,13 @@ func (coins *Coins) safeAdd(coinsB Coins) Coins { // DenomsSubsetOf returns true if receiver's denom set // is subset of coinsB's denoms. -func (coins *Coins) DenomsSubsetOf(coinsB Coins) bool { +func (coins Coins) DenomsSubsetOf(coinsB Coins) bool { // more denoms in B than in receiver - if len(*coins) > len(coinsB) { + if len(coins) > len(coinsB) { return false } - for _, coin := range *coins { + for _, coin := range coins { if coinsB.AmountOf(coin.Denom).IsZero() { return false } @@ -427,7 +427,7 @@ func (coins *Coins) DenomsSubsetOf(coinsB Coins) bool { // // CONTRACT: Sub will never return Coins where one Coin has a non-positive // amount. In otherwords, IsValid will always return true. -func (coins *Coins) Sub(coinsB Coins) Coins { +func (coins Coins) Sub(coinsB Coins) Coins { diff, hasNeg := coins.SafeSub(coinsB) if hasNeg { panic("negative coin amount") @@ -438,15 +438,15 @@ func (coins *Coins) Sub(coinsB Coins) Coins { // SafeSub performs the same arithmetic as Sub but returns a boolean if any // negative coin amount was returned. -func (coins *Coins) SafeSub(coinsB Coins) (Coins, bool) { +func (coins Coins) SafeSub(coinsB Coins) (Coins, bool) { diff := coins.safeAdd(coinsB.negative()) return diff, diff.IsAnyNegative() } // IsAllGT returns true if for every denom in coinsB, // the denom is present at a greater amount in coins. -func (coins *Coins) IsAllGT(coinsB Coins) bool { - if len(*coins) == 0 { +func (coins Coins) IsAllGT(coinsB Coins) bool { + if len(coins) == 0 { return false } @@ -454,13 +454,13 @@ func (coins *Coins) IsAllGT(coinsB Coins) bool { return true } - if !coinsB.DenomsSubsetOf(*coins) { + if !coinsB.DenomsSubsetOf(coins) { return false } for _, coinB := range coinsB { amountA, amountB := coins.AmountOf(coinB.Denom), coinB.Amount - if !amountA.GT(&amountB) { + if !amountA.GT(amountB) { return false } } @@ -471,12 +471,12 @@ func (coins *Coins) IsAllGT(coinsB Coins) bool { // IsAllGTE returns false if for any denom in coinsB, // the denom is present at a smaller amount in coins; // else returns true. -func (coins *Coins) IsAllGTE(coinsB Coins) bool { +func (coins Coins) IsAllGTE(coinsB Coins) bool { if len(coinsB) == 0 { return true } - if len(*coins) == 0 { + if len(coins) == 0 { return false } @@ -491,14 +491,14 @@ func (coins *Coins) IsAllGTE(coinsB Coins) bool { // IsAllLT returns True iff for every denom in coins, the denom is present at // a smaller amount in coinsB. -func (coins *Coins) IsAllLT(coinsB Coins) bool { - return coinsB.IsAllGT(*coins) +func (coins Coins) IsAllLT(coinsB Coins) bool { + return coinsB.IsAllGT(coins) } // IsAllLTE returns true iff for every denom in coins, the denom is present at // a smaller or equal amount in coinsB. -func (coins *Coins) IsAllLTE(coinsB Coins) bool { - return coinsB.IsAllGTE(*coins) +func (coins Coins) IsAllLTE(coinsB Coins) bool { + return coinsB.IsAllGTE(coins) } // IsAnyGT returns true iff for any denom in coins, the denom is present at a @@ -509,12 +509,12 @@ func (coins *Coins) IsAllLTE(coinsB Coins) bool { // {2A, 3B}.IsAnyGT{5C} = false // {}.IsAnyGT{5C} = false // {2A, 3B}.IsAnyGT{} = false -func (coins *Coins) IsAnyGT(coinsB Coins) bool { +func (coins Coins) IsAnyGT(coinsB Coins) bool { if len(coinsB) == 0 { return false } - for _, coin := range *coins { + for _, coin := range coins { amt := coinsB.AmountOf(coin.Denom) if coin.Amount.GT(amt) && !amt.IsZero() { return true @@ -529,12 +529,12 @@ func (coins *Coins) IsAnyGT(coinsB Coins) bool { // // NOTE: IsAnyGTE operates under the invariant that both coin sets are sorted // by denominations and there exists no zero coins. -func (coins *Coins) IsAnyGTE(coinsB Coins) bool { +func (coins Coins) IsAnyGTE(coinsB Coins) bool { if len(coinsB) == 0 { return false } - for _, coin := range *coins { + for _, coin := range coins { amt := coinsB.AmountOf(coin.Denom) if coin.Amount.GTE(amt) && !amt.IsZero() { return true @@ -545,8 +545,8 @@ func (coins *Coins) IsAnyGTE(coinsB Coins) bool { } // IsZero returns true if there are no coins or all coins are zero. -func (coins *Coins) IsZero() bool { - for _, coin := range *coins { +func (coins Coins) IsZero() bool { + for _, coin := range coins { if !coin.IsZero() { return false } @@ -555,16 +555,16 @@ func (coins *Coins) IsZero() bool { } // IsEqual returns true if the two sets of Coins have the same value -func (coins *Coins) IsEqual(coinsB Coins) bool { - if len(*coins) != len(coinsB) { +func (coins Coins) IsEqual(coinsB Coins) bool { + if len(coins) != len(coinsB) { return false } coins = coins.Sort() - coinsB = *coinsB.Sort() + coinsB = coinsB.Sort() - for i := 0; i < len(*coins); i++ { - if !(*coins)[i].IsEqual(&coinsB[i]) { + for i := 0; i < len(coins); i++ { + if !coins[i].IsEqual(coinsB[i]) { return false } } @@ -573,54 +573,52 @@ func (coins *Coins) IsEqual(coinsB Coins) bool { } // Empty returns true if there are no coins and false otherwise. -func (coins *Coins) Empty() bool { - return len(*coins) == 0 +func (coins Coins) Empty() bool { + return len(coins) == 0 } // AmountOf returns the amount of a denom from coins -func (coins *Coins) AmountOf(denom string) *Int { +func (coins Coins) AmountOf(denom string) Int { mustValidateDenom(denom) - switch len(*coins) { + switch len(coins) { case 0: return ZeroInt() case 1: - coin := (*coins)[0] + coin := coins[0] if coin.Denom == denom { - return &coin.Amount + return coin.Amount } return ZeroInt() default: - midIdx := len(*coins) / 2 // 2:1, 3:1, 4:2 - coin := (*coins)[midIdx] + midIdx := len(coins) / 2 // 2:1, 3:1, 4:2 + coin := coins[midIdx] switch { case denom < coin.Denom: - c := (*coins)[:midIdx] - return c.AmountOf(denom) + return coins[:midIdx].AmountOf(denom) case denom == coin.Denom: - return &coin.Amount + return coin.Amount default: - c := (*coins)[midIdx+1:] - return c.AmountOf(denom) + return coins[midIdx+1:].AmountOf(denom) } } } // GetDenomByIndex returns the Denom of the certain coin to make the findDup generic -func (coins *Coins) GetDenomByIndex(i int) string { - return (*coins)[i].Denom +func (coins Coins) GetDenomByIndex(i int) string { + return coins[i].Denom } // IsAllPositive returns true if there is at least one coin and all currencies // have a positive value. -func (coins *Coins) IsAllPositive() bool { - if len(*coins) == 0 { +func (coins Coins) IsAllPositive() bool { + if len(coins) == 0 { return false } - for _, coin := range *coins { + for _, coin := range coins { if !coin.IsPositive() { return false } @@ -634,8 +632,8 @@ func (coins *Coins) IsAllPositive() bool { // is empty too. // // TODO: Remove once unsigned integers are used. -func (coins *Coins) IsAnyNegative() bool { - for _, coin := range *coins { +func (coins Coins) IsAnyNegative() bool { + for _, coin := range coins { if coin.IsNegative() { return true } @@ -647,13 +645,13 @@ func (coins *Coins) IsAnyNegative() bool { // negative returns a set of coins with all amount negative. // // TODO: Remove once unsigned integers are used. -func (coins *Coins) negative() Coins { - res := make([]Coin, 0, len(*coins)) +func (coins Coins) negative() Coins { + res := make([]Coin, 0, len(coins)) - for _, coin := range *coins { + for _, coin := range coins { res = append(res, Coin{ Denom: coin.Denom, - Amount: *coin.Amount.Neg(), + Amount: coin.Amount.Neg(), }) } @@ -677,18 +675,18 @@ func removeZeroCoins(coins Coins) Coins { // Sort interface // Len implements sort.Interface for Coins -func (coins *Coins) Len() int { return len(*coins) } +func (coins Coins) Len() int { return len(coins) } // Less implements sort.Interface for Coins -func (coins *Coins) Less(i, j int) bool { return (*coins)[i].Denom < (*coins)[j].Denom } +func (coins Coins) Less(i, j int) bool { return coins[i].Denom < coins[j].Denom } // Swap implements sort.Interface for Coins -func (coins *Coins) Swap(i, j int) { (*coins)[i], (*coins)[j] = (*coins)[j], (*coins)[i] } +func (coins Coins) Swap(i, j int) { coins[i], coins[j] = coins[j], coins[i] } -var _ sort.Interface = &Coins{} +var _ sort.Interface = Coins{} // Sort is a helper function to sort the set of coins in-place -func (coins *Coins) Sort() *Coins { +func (coins Coins) Sort() Coins { sort.Sort(coins) return coins } diff --git a/usecase/coin/coin_benchmark_test.go b/usecase/coin/coin_benchmark_test.go index f1d8b8c85..3c0957472 100644 --- a/usecase/coin/coin_benchmark_test.go +++ b/usecase/coin/coin_benchmark_test.go @@ -16,10 +16,10 @@ func BenchmarkCoinsAdditionIntersect(b *testing.B) { coinsB := Coins(make([]Coin, numCoinsB)) for i := 0; i < numCoinsA; i++ { - coinsA[i] = *MustNewCoin(coinName(i), *NewInt(int64(i))) + coinsA[i] = MustNewCoin(coinName(i), NewInt(int64(i))) } for i := 0; i < numCoinsB; i++ { - coinsB[i] = *MustNewCoin(coinName(i), *NewInt(int64(i))) + coinsB[i] = MustNewCoin(coinName(i), NewInt(int64(i))) } b.ResetTimer() @@ -45,10 +45,10 @@ func BenchmarkCoinsAdditionNoIntersect(b *testing.B) { coinsB := Coins(make([]Coin, numCoinsB)) for i := 0; i < numCoinsA; i++ { - coinsA[i] = *MustNewCoin(coinName(numCoinsB+i), *NewInt(int64(i))) + coinsA[i] = MustNewCoin(coinName(numCoinsB+i), NewInt(int64(i))) } for i := 0; i < numCoinsB; i++ { - coinsB[i] = *MustNewCoin(coinName(i), *NewInt(int64(i))) + coinsB[i] = MustNewCoin(coinName(i), NewInt(int64(i))) } b.ResetTimer() diff --git a/usecase/coin/coin_test.go b/usecase/coin/coin_test.go index b7cf6354a..ba6e4dd16 100644 --- a/usecase/coin/coin_test.go +++ b/usecase/coin/coin_test.go @@ -34,22 +34,22 @@ func (s *coinTestSuite) SetupSuite() { func (s *coinTestSuite) TestCoin() { s.Require().Panics(func() { sdk.NewInt64Coin(testDenom1, -1) }) - s.Require().Panics(func() { sdk.MustNewCoin(testDenom1, *sdk.NewInt(-1)) }) - s.Require().Equal(sdk.NewInt(10), &sdk.NewInt64Coin(strings.ToUpper(testDenom1), 10).Amount) - s.Require().Equal(sdk.NewInt(10), &sdk.MustNewCoin(strings.ToUpper(testDenom1), *sdk.NewInt(10)).Amount) - s.Require().Equal(sdk.NewInt(5), &sdk.NewInt64Coin(testDenom1, 5).Amount) - s.Require().Equal(sdk.NewInt(5), &sdk.MustNewCoin(testDenom1, *sdk.NewInt(5)).Amount) + s.Require().Panics(func() { sdk.MustNewCoin(testDenom1, sdk.NewInt(-1)) }) + s.Require().Equal(sdk.NewInt(10), sdk.NewInt64Coin(strings.ToUpper(testDenom1), 10).Amount) + s.Require().Equal(sdk.NewInt(10), sdk.MustNewCoin(strings.ToUpper(testDenom1), sdk.NewInt(10)).Amount) + s.Require().Equal(sdk.NewInt(5), sdk.NewInt64Coin(testDenom1, 5).Amount) + s.Require().Equal(sdk.NewInt(5), sdk.MustNewCoin(testDenom1, sdk.NewInt(5)).Amount) } func (s *coinTestSuite) TestCoin_String() { - coin := sdk.MustNewCoin(testDenom1, *sdk.NewInt(10)) - s.Require().Equal(fmt.Sprintf("10%s", testDenom1), (*coin).String()) + coin := sdk.MustNewCoin(testDenom1, sdk.NewInt(10)) + s.Require().Equal(fmt.Sprintf("10%s", testDenom1), coin.String()) } func (s *coinTestSuite) TestIsEqualCoin() { cases := []struct { - inputOne *sdk.Coin - inputTwo *sdk.Coin + inputOne sdk.Coin + inputTwo sdk.Coin expected bool panics bool }{ @@ -82,16 +82,16 @@ func (s *coinTestSuite) TestCoinIsValid() { coin sdk.Coin expectPass bool }{ - {sdk.Coin{testDenom1, *sdk.NewInt(-1)}, false}, - {sdk.Coin{testDenom1, *sdk.NewInt(0)}, true}, - {sdk.Coin{testDenom1, *sdk.OneInt()}, true}, - {sdk.Coin{"Atom", *sdk.OneInt()}, true}, - {sdk.Coin{"ATOM", *sdk.OneInt()}, true}, - {sdk.Coin{"a", *sdk.OneInt()}, false}, - {sdk.Coin{loremIpsum, *sdk.OneInt()}, false}, - {sdk.Coin{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", *sdk.OneInt()}, true}, - {sdk.Coin{"atOm", *sdk.OneInt()}, true}, - {sdk.Coin{" ", *sdk.OneInt()}, false}, + {sdk.Coin{testDenom1, sdk.NewInt(-1)}, false}, + {sdk.Coin{testDenom1, sdk.NewInt(0)}, true}, + {sdk.Coin{testDenom1, sdk.OneInt()}, true}, + {sdk.Coin{"Atom", sdk.OneInt()}, true}, + {sdk.Coin{"ATOM", sdk.OneInt()}, true}, + {sdk.Coin{"a", sdk.OneInt()}, false}, + {sdk.Coin{loremIpsum, sdk.OneInt()}, false}, + {sdk.Coin{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.OneInt()}, true}, + {sdk.Coin{"atOm", sdk.OneInt()}, true}, + {sdk.Coin{" ", sdk.OneInt()}, false}, } for i, tc := range cases { @@ -110,11 +110,11 @@ func (s *coinTestSuite) TestCustomValidation() { coin sdk.Coin expectPass bool }{ - {sdk.Coin{"🙂", *sdk.NewInt(1)}, true}, - {sdk.Coin{"🙁", *sdk.NewInt(1)}, true}, - {sdk.Coin{"🌶", *sdk.NewInt(1)}, false}, // outside the unicode range listed above - {sdk.Coin{"asdf", *sdk.NewInt(1)}, false}, - {sdk.Coin{"", *sdk.NewInt(1)}, false}, + {sdk.Coin{"🙂", sdk.NewInt(1)}, true}, + {sdk.Coin{"🙁", sdk.NewInt(1)}, true}, + {sdk.Coin{"🌶", sdk.NewInt(1)}, false}, // outside the unicode range listed above + {sdk.Coin{"asdf", sdk.NewInt(1)}, false}, + {sdk.Coin{"", sdk.NewInt(1)}, false}, } for i, tc := range cases { @@ -125,9 +125,9 @@ func (s *coinTestSuite) TestCustomValidation() { func (s *coinTestSuite) TestAddCoin() { cases := []struct { - inputOne *sdk.Coin - inputTwo *sdk.Coin - expected *sdk.Coin + inputOne sdk.Coin + inputTwo sdk.Coin + expected sdk.Coin shouldPanic bool }{ {sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom1, 2), false}, @@ -148,16 +148,16 @@ func (s *coinTestSuite) TestAddCoin() { func (s *coinTestSuite) TestSubCoin() { cases := []struct { - inputOne *sdk.Coin - inputTwo *sdk.Coin - expected *sdk.Coin + inputOne sdk.Coin + inputTwo sdk.Coin + expected sdk.Coin shouldPanic bool }{ {sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom2, 1), sdk.NewInt64Coin(testDenom1, 1), true}, {sdk.NewInt64Coin(testDenom1, 10), sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom1, 9), false}, {sdk.NewInt64Coin(testDenom1, 5), sdk.NewInt64Coin(testDenom1, 3), sdk.NewInt64Coin(testDenom1, 2), false}, {sdk.NewInt64Coin(testDenom1, 5), sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom1, 5), false}, - {sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom1, 5), &sdk.Coin{}, true}, + {sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom1, 5), sdk.Coin{}, true}, } for tcIndex, tc := range cases { @@ -171,8 +171,8 @@ func (s *coinTestSuite) TestSubCoin() { } tc := struct { - inputOne *sdk.Coin - inputTwo *sdk.Coin + inputOne sdk.Coin + inputTwo sdk.Coin expected int64 }{sdk.NewInt64Coin(testDenom1, 1), sdk.NewInt64Coin(testDenom1, 1), 0} res := tc.inputOne.Sub(tc.inputTwo) @@ -181,8 +181,8 @@ func (s *coinTestSuite) TestSubCoin() { func (s *coinTestSuite) TestIsGTECoin() { cases := []struct { - inputOne *sdk.Coin - inputTwo *sdk.Coin + inputOne sdk.Coin + inputTwo sdk.Coin expected bool panics bool }{ @@ -204,8 +204,8 @@ func (s *coinTestSuite) TestIsGTECoin() { func (s *coinTestSuite) TestIsLTCoin() { cases := []struct { - inputOne *sdk.Coin - inputTwo *sdk.Coin + inputOne sdk.Coin + inputTwo sdk.Coin expected bool panics bool }{ @@ -248,11 +248,11 @@ func (s *coinTestSuite) TestFilteredZeroCoins() { { name: "all greater than zero", input: sdk.Coins{ - {"testa", *sdk.OneInt()}, - {"testb", *sdk.NewInt(2)}, - {"testc", *sdk.NewInt(3)}, - {"testd", *sdk.NewInt(4)}, - {"teste", *sdk.NewInt(5)}, + {"testa", sdk.OneInt()}, + {"testb", sdk.NewInt(2)}, + {"testc", sdk.NewInt(3)}, + {"testd", sdk.NewInt(4)}, + {"teste", sdk.NewInt(5)}, }, original: "1testa,2testb,3testc,4testd,5teste", expected: "1testa,2testb,3testc,4testd,5teste", @@ -260,11 +260,11 @@ func (s *coinTestSuite) TestFilteredZeroCoins() { { name: "zero coin in middle", input: sdk.Coins{ - {"testa", *sdk.OneInt()}, - {"testb", *sdk.NewInt(2)}, - {"testc", *sdk.NewInt(0)}, - {"testd", *sdk.NewInt(4)}, - {"teste", *sdk.NewInt(5)}, + {"testa", sdk.OneInt()}, + {"testb", sdk.NewInt(2)}, + {"testc", sdk.NewInt(0)}, + {"testd", sdk.NewInt(4)}, + {"teste", sdk.NewInt(5)}, }, original: "1testa,2testb,0testc,4testd,5teste", expected: "1testa,2testb,4testd,5teste", @@ -272,11 +272,11 @@ func (s *coinTestSuite) TestFilteredZeroCoins() { { name: "zero coin end (unordered)", input: sdk.Coins{ - {"teste", *sdk.NewInt(5)}, - {"testc", *sdk.NewInt(3)}, - {"testa", *sdk.OneInt()}, - {"testd", *sdk.NewInt(4)}, - {"testb", *sdk.NewInt(0)}, + {"teste", sdk.NewInt(5)}, + {"testc", sdk.NewInt(3)}, + {"testa", sdk.OneInt()}, + {"testd", sdk.NewInt(4)}, + {"testb", sdk.NewInt(0)}, }, original: "5teste,3testc,1testa,4testd,0testb", expected: "1testa,3testc,4testd,5teste", @@ -306,15 +306,15 @@ func (s *coinTestSuite) TestCoins_String() { }, { "single coin", - sdk.Coins{{"tree", *sdk.OneInt()}}, + sdk.Coins{{"tree", sdk.OneInt()}}, "1tree", }, { "multiple coins", sdk.Coins{ - {"tree", *sdk.OneInt()}, - {"gas", *sdk.OneInt()}, - {"mineral", *sdk.OneInt()}, + {"tree", sdk.OneInt()}, + {"gas", sdk.OneInt()}, + {"mineral", sdk.OneInt()}, }, "1tree,1gas,1mineral", }, @@ -331,10 +331,10 @@ func (s *coinTestSuite) TestIsZeroCoins() { expected bool }{ {sdk.Coins{}, true}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0)}, true}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0), *sdk.NewInt64Coin(testDenom2, 0)}, true}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 1)}, false}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0), *sdk.NewInt64Coin(testDenom2, 1)}, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, true}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 0)}, true}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 1)}, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, false}, } for _, tc := range cases { @@ -351,12 +351,12 @@ func (s *coinTestSuite) TestEqualCoins() { panics bool }{ {sdk.Coins{}, sdk.Coins{}, true, false}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0)}, true, false}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0), *sdk.NewInt64Coin(testDenom2, 1)}, sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0), *sdk.NewInt64Coin(testDenom2, 1)}, true, false}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{*sdk.NewInt64Coin(testDenom2, 0)}, false, true}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{*sdk.NewInt64Coin(testDenom1, 1)}, false, false}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0), *sdk.NewInt64Coin(testDenom2, 1)}, false, false}, - {sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0), *sdk.NewInt64Coin(testDenom2, 1)}, sdk.Coins{*sdk.NewInt64Coin(testDenom1, 0), *sdk.NewInt64Coin(testDenom2, 1)}, true, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, true, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, true, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom2, 0)}, false, true}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 1)}, false, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, false, false}, + {sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, sdk.Coins{sdk.NewInt64Coin(testDenom1, 0), sdk.NewInt64Coin(testDenom2, 1)}, true, false}, } for tcnum, tc := range cases { @@ -380,11 +380,11 @@ func (s *coinTestSuite) TestAddCoins() { inputTwo sdk.Coins expected sdk.Coins }{ - {sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}, sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}, sdk.Coins{{testDenom1, *two}, {testDenom2, *two}}}, - {sdk.Coins{{testDenom1, *zero}, {testDenom2, *one}}, sdk.Coins{{testDenom1, *zero}, {testDenom2, *zero}}, sdk.Coins{{testDenom2, *one}}}, - {sdk.Coins{{testDenom1, *two}}, sdk.Coins{{testDenom2, *zero}}, sdk.Coins{{testDenom1, *two}}}, - {sdk.Coins{{testDenom1, *one}}, sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}, sdk.Coins{{testDenom1, *two}, {testDenom2, *two}}}, - {sdk.Coins{{testDenom1, *zero}, {testDenom2, *zero}}, sdk.Coins{{testDenom1, *zero}, {testDenom2, *zero}}, sdk.Coins(nil)}, + {sdk.Coins{{testDenom1, one}, {testDenom2, one}}, sdk.Coins{{testDenom1, one}, {testDenom2, one}}, sdk.Coins{{testDenom1, two}, {testDenom2, two}}}, + {sdk.Coins{{testDenom1, zero}, {testDenom2, one}}, sdk.Coins{{testDenom1, zero}, {testDenom2, zero}}, sdk.Coins{{testDenom2, one}}}, + {sdk.Coins{{testDenom1, two}}, sdk.Coins{{testDenom2, zero}}, sdk.Coins{{testDenom1, two}}}, + {sdk.Coins{{testDenom1, one}}, sdk.Coins{{testDenom1, one}, {testDenom2, two}}, sdk.Coins{{testDenom1, two}, {testDenom2, two}}}, + {sdk.Coins{{testDenom1, zero}, {testDenom2, zero}}, sdk.Coins{{testDenom1, zero}, {testDenom2, zero}}, sdk.Coins(nil)}, } for tcIndex, tc := range cases { @@ -405,11 +405,11 @@ func (s *coinTestSuite) TestSubCoins() { expected sdk.Coins shouldPanic bool }{ - {sdk.Coins{{testDenom1, *two}}, sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}, sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}, true}, - {sdk.Coins{{testDenom1, *two}}, sdk.Coins{{testDenom2, *zero}}, sdk.Coins{{testDenom1, *two}}, false}, - {sdk.Coins{{testDenom1, *one}}, sdk.Coins{{testDenom2, *zero}}, sdk.Coins{{testDenom1, *one}}, false}, - {sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}, sdk.Coins{{testDenom1, *one}}, sdk.Coins{{testDenom2, *one}}, false}, - {sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}, sdk.Coins{{testDenom1, *two}}, sdk.Coins{}, true}, + {sdk.Coins{{testDenom1, two}}, sdk.Coins{{testDenom1, one}, {testDenom2, two}}, sdk.Coins{{testDenom1, one}, {testDenom2, two}}, true}, + {sdk.Coins{{testDenom1, two}}, sdk.Coins{{testDenom2, zero}}, sdk.Coins{{testDenom1, two}}, false}, + {sdk.Coins{{testDenom1, one}}, sdk.Coins{{testDenom2, zero}}, sdk.Coins{{testDenom1, one}}, false}, + {sdk.Coins{{testDenom1, one}, {testDenom2, one}}, sdk.Coins{{testDenom1, one}}, sdk.Coins{{testDenom2, one}}, false}, + {sdk.Coins{{testDenom1, one}, {testDenom2, one}}, sdk.Coins{{testDenom1, two}}, sdk.Coins{}, true}, } for i, tc := range testCases { @@ -433,94 +433,94 @@ func (s *coinTestSuite) TestCoins_Validate() { { "valid lowercase coins", sdk.Coins{ - {"gas", *sdk.OneInt()}, - {"mineral", *sdk.OneInt()}, - {"tree", *sdk.OneInt()}, + {"gas", sdk.OneInt()}, + {"mineral", sdk.OneInt()}, + {"tree", sdk.OneInt()}, }, true, }, { "valid uppercase coins", sdk.Coins{ - {"GAS", *sdk.OneInt()}, - {"MINERAL", *sdk.OneInt()}, - {"TREE", *sdk.OneInt()}, + {"GAS", sdk.OneInt()}, + {"MINERAL", sdk.OneInt()}, + {"TREE", sdk.OneInt()}, }, true, }, { "valid uppercase coin", sdk.Coins{ - {"ATOM", *sdk.OneInt()}, + {"ATOM", sdk.OneInt()}, }, true, }, { "valid lower and uppercase coins (1)", sdk.Coins{ - {"GAS", *sdk.OneInt()}, - {"gAs", *sdk.OneInt()}, + {"GAS", sdk.OneInt()}, + {"gAs", sdk.OneInt()}, }, true, }, { "valid lower and uppercase coins (2)", sdk.Coins{ - {"ATOM", *sdk.OneInt()}, - {"Atom", *sdk.OneInt()}, - {"atom", *sdk.OneInt()}, + {"ATOM", sdk.OneInt()}, + {"Atom", sdk.OneInt()}, + {"atom", sdk.OneInt()}, }, true, }, { "mixed case (1)", sdk.Coins{ - {"MineraL", *sdk.OneInt()}, - {"TREE", *sdk.OneInt()}, - {"gAs", *sdk.OneInt()}, + {"MineraL", sdk.OneInt()}, + {"TREE", sdk.OneInt()}, + {"gAs", sdk.OneInt()}, }, true, }, { "mixed case (2)", sdk.Coins{ - {"gAs", *sdk.OneInt()}, - {"mineral", *sdk.OneInt()}, + {"gAs", sdk.OneInt()}, + {"mineral", sdk.OneInt()}, }, true, }, { "mixed case (3)", sdk.Coins{ - {"gAs", *sdk.OneInt()}, + {"gAs", sdk.OneInt()}, }, true, }, { "unicode letters and numbers", sdk.Coins{ - {"𐀀𐀆𐀉Ⅲ", *sdk.OneInt()}, + {"𐀀𐀆𐀉Ⅲ", sdk.OneInt()}, }, false, }, { "emojis", sdk.Coins{ - {"🤑😋🤔", *sdk.OneInt()}, + {"🤑😋🤔", sdk.OneInt()}, }, false, }, { "IBC denominations (ADR 001)", sdk.Coins{ - {"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", *sdk.OneInt()}, - {"ibc/876563AAAACF739EB061C67CDB5EDF2B7C9FD4AA9D876450CC21210807C2820A", *sdk.NewInt(2)}, + {"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.OneInt()}, + {"ibc/876563AAAACF739EB061C67CDB5EDF2B7C9FD4AA9D876450CC21210807C2820A", sdk.NewInt(2)}, }, true, }, { "empty (1)", - *sdk.MustNewCoins(), + sdk.MustNewCoins(), true, }, { @@ -531,61 +531,61 @@ func (s *coinTestSuite) TestCoins_Validate() { { "invalid denomination (1)", sdk.Coins{ - {"MineraL", *sdk.OneInt()}, - {"0TREE", *sdk.OneInt()}, - {"gAs", *sdk.OneInt()}, + {"MineraL", sdk.OneInt()}, + {"0TREE", sdk.OneInt()}, + {"gAs", sdk.OneInt()}, }, false, }, { "invalid denomination (2)", sdk.Coins{ - {"-GAS", *sdk.OneInt()}, - {"gAs", *sdk.OneInt()}, + {"-GAS", sdk.OneInt()}, + {"gAs", sdk.OneInt()}, }, false, }, { "bad sort (1)", sdk.Coins{ - {"tree", *sdk.OneInt()}, - {"gas", *sdk.OneInt()}, - {"mineral", *sdk.OneInt()}, + {"tree", sdk.OneInt()}, + {"gas", sdk.OneInt()}, + {"mineral", sdk.OneInt()}, }, false, }, { "bad sort (2)", sdk.Coins{ - {"gas", *sdk.OneInt()}, - {"tree", *sdk.OneInt()}, - {"mineral", *sdk.OneInt()}, + {"gas", sdk.OneInt()}, + {"tree", sdk.OneInt()}, + {"mineral", sdk.OneInt()}, }, false, }, { "non-positive amount (1)", sdk.Coins{ - {"gas", *sdk.OneInt()}, - {"tree", *sdk.NewInt(0)}, - {"mineral", *sdk.OneInt()}, + {"gas", sdk.OneInt()}, + {"tree", sdk.NewInt(0)}, + {"mineral", sdk.OneInt()}, }, false, }, { "non-positive amount (2)", sdk.Coins{ - {"gas", *sdk.NewInt(-1)}, - {"tree", *sdk.OneInt()}, - {"mineral", *sdk.OneInt()}, + {"gas", sdk.NewInt(-1)}, + {"tree", sdk.OneInt()}, + {"mineral", sdk.OneInt()}, }, false, }, { "duplicate denomination", sdk.Coins{ - {"gas", *sdk.OneInt()}, - {"gas", *sdk.OneInt()}, - {"mineral", *sdk.OneInt()}, + {"gas", sdk.OneInt()}, + {"gas", sdk.OneInt()}, + {"mineral", sdk.OneInt()}, }, false, }, @@ -605,42 +605,42 @@ func (s *coinTestSuite) TestCoinsGT() { one := sdk.OneInt() two := sdk.NewInt(2) - s.Require().False((&sdk.Coins{}).IsAllGT(sdk.Coins{})) - s.Require().True((&sdk.Coins{{testDenom1, *one}}).IsAllGT(sdk.Coins{})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGT(sdk.Coins{{testDenom1, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGT(sdk.Coins{{testDenom2, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}).IsAllGT(sdk.Coins{{testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllGT(sdk.Coins{{testDenom2, *two}})) + s.Require().False(sdk.Coins{}.IsAllGT(sdk.Coins{})) + s.Require().True(sdk.Coins{{testDenom1, one}}.IsAllGT(sdk.Coins{})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGT(sdk.Coins{{testDenom1, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGT(sdk.Coins{{testDenom2, one}})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, two}}.IsAllGT(sdk.Coins{{testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllGT(sdk.Coins{{testDenom2, two}})) } func (s *coinTestSuite) TestCoinsLT() { one := sdk.OneInt() two := sdk.NewInt(2) - s.Require().False((&sdk.Coins{}).IsAllLT(sdk.Coins{})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllLT(sdk.Coins{})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllLT(sdk.Coins{{testDenom1, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllLT(sdk.Coins{{testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllLT(sdk.Coins{{testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllLT(sdk.Coins{{testDenom2, *two}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllLT(sdk.Coins{{testDenom1, *one}, {testDenom2, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllLT(sdk.Coins{{testDenom1, *two}, {testDenom2, *two}})) - s.Require().True((&sdk.Coins{}).IsAllLT(sdk.Coins{{testDenom1, *one}})) + s.Require().False(sdk.Coins{}.IsAllLT(sdk.Coins{})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllLT(sdk.Coins{})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllLT(sdk.Coins{{testDenom1, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllLT(sdk.Coins{{testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllLT(sdk.Coins{{testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllLT(sdk.Coins{{testDenom2, two}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllLT(sdk.Coins{{testDenom1, one}, {testDenom2, one}})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllLT(sdk.Coins{{testDenom1, two}, {testDenom2, two}})) + s.Require().True(sdk.Coins{}.IsAllLT(sdk.Coins{{testDenom1, one}})) } func (s *coinTestSuite) TestCoinsLTE() { one := sdk.OneInt() two := sdk.NewInt(2) - s.Require().True((&sdk.Coins{}).IsAllLTE(sdk.Coins{})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllLTE(sdk.Coins{})) - s.Require().True((&sdk.Coins{{testDenom1, *one}}).IsAllLTE(sdk.Coins{{testDenom1, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllLTE(sdk.Coins{{testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllLTE(sdk.Coins{{testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllLTE(sdk.Coins{{testDenom2, *two}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllLTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllLTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().True((&sdk.Coins{}).IsAllLTE(sdk.Coins{{testDenom1, *one}})) + s.Require().True(sdk.Coins{}.IsAllLTE(sdk.Coins{})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllLTE(sdk.Coins{})) + s.Require().True(sdk.Coins{{testDenom1, one}}.IsAllLTE(sdk.Coins{{testDenom1, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllLTE(sdk.Coins{{testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllLTE(sdk.Coins{{testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllLTE(sdk.Coins{{testDenom2, two}})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllLTE(sdk.Coins{{testDenom1, one}, {testDenom2, one}})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllLTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().True(sdk.Coins{}.IsAllLTE(sdk.Coins{{testDenom1, one}})) } func (s *coinTestSuite) TestParseCoins() { @@ -653,29 +653,29 @@ func (s *coinTestSuite) TestParseCoins() { }{ {"", true, nil}, {"0stake", true, sdk.Coins{}}, // remove zero coins - {"0stake,1foo,99bar", true, sdk.Coins{{"bar", *sdk.NewInt(99)}, {"foo", *one}}}, // remove zero coins - {"1foo", true, sdk.Coins{{"foo", *one}}}, + {"0stake,1foo,99bar", true, sdk.Coins{{"bar", sdk.NewInt(99)}, {"foo", one}}}, // remove zero coins + {"1foo", true, sdk.Coins{{"foo", one}}}, {"10btc,1atom,20btc", false, nil}, - {"10bar", true, sdk.Coins{{"bar", *sdk.NewInt(10)}}}, - {"99bar,1foo", true, sdk.Coins{{"bar", *sdk.NewInt(99)}, {"foo", *one}}}, - {"98 bar , 1 foo ", true, sdk.Coins{{"bar", *sdk.NewInt(98)}, {"foo", *one}}}, - {" 55\t \t bling\n", true, sdk.Coins{{"bling", *sdk.NewInt(55)}}}, - {"2foo, 97 bar", true, sdk.Coins{{"bar", *sdk.NewInt(97)}, {"foo", *sdk.NewInt(2)}}}, - {"5 mycoin,", false, nil}, // no empty coins in a list - {"2 3foo, 97 bar", false, nil}, // 3foo is invalid coin name - {"11me coin, 12you coin", false, nil}, // no spaces in coin names - {"1.2btc", true, sdk.Coins{{"btc", *sdk.NewInt(1)}}}, // amount can be decimal, will get truncated - {"5foo:bar", false, nil}, // invalid separator - {"10atom10", true, sdk.Coins{{"atom10", *sdk.NewInt(10)}}}, - {"200transfer/channelToA/uatom", true, sdk.Coins{{"transfer/channelToA/uatom", *sdk.NewInt(200)}}}, - {"50ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", true, sdk.Coins{{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", *sdk.NewInt(50)}}}, + {"10bar", true, sdk.Coins{{"bar", sdk.NewInt(10)}}}, + {"99bar,1foo", true, sdk.Coins{{"bar", sdk.NewInt(99)}, {"foo", one}}}, + {"98 bar , 1 foo ", true, sdk.Coins{{"bar", sdk.NewInt(98)}, {"foo", one}}}, + {" 55\t \t bling\n", true, sdk.Coins{{"bling", sdk.NewInt(55)}}}, + {"2foo, 97 bar", true, sdk.Coins{{"bar", sdk.NewInt(97)}, {"foo", sdk.NewInt(2)}}}, + {"5 mycoin,", false, nil}, // no empty coins in a list + {"2 3foo, 97 bar", false, nil}, // 3foo is invalid coin name + {"11me coin, 12you coin", false, nil}, // no spaces in coin names + {"1.2btc", true, sdk.Coins{{"btc", sdk.NewInt(1)}}}, // amount can be decimal, will get truncated + {"5foo:bar", false, nil}, // invalid separator + {"10atom10", true, sdk.Coins{{"atom10", sdk.NewInt(10)}}}, + {"200transfer/channelToA/uatom", true, sdk.Coins{{"transfer/channelToA/uatom", sdk.NewInt(200)}}}, + {"50ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", true, sdk.Coins{{"ibc/7F1D3FCF4AE79E1554D670D1AD949A9BA4E4A3C76C63093E17E446A46061A7A2", sdk.NewInt(50)}}}, } for tcIndex, tc := range cases { res, err := sdk.ParseCoinsNormalized(tc.input) if !tc.valid { s.Require().Error(err, "%s: %#v. tc #%d", tc.input, res, tcIndex) - } else if s.NoError(err, "%s: %+v", tc.input, err) { + } else if s.Assert().Nil(err, "%s: %+v", tc.input, err) { s.Require().Equal(tc.expected, res, "coin parsing was incorrect, tc #%d", tcIndex) } } @@ -683,32 +683,32 @@ func (s *coinTestSuite) TestParseCoins() { func (s *coinTestSuite) TestSortCoins() { good := sdk.Coins{ - *sdk.NewInt64Coin("gas", 1), - *sdk.NewInt64Coin("mineral", 1), - *sdk.NewInt64Coin("tree", 1), + sdk.NewInt64Coin("gas", 1), + sdk.NewInt64Coin("mineral", 1), + sdk.NewInt64Coin("tree", 1), } empty := sdk.Coins{ - *sdk.NewInt64Coin("gold", 0), + sdk.NewInt64Coin("gold", 0), } badSort1 := sdk.Coins{ - *sdk.NewInt64Coin("tree", 1), - *sdk.NewInt64Coin("gas", 1), - *sdk.NewInt64Coin("mineral", 1), + sdk.NewInt64Coin("tree", 1), + sdk.NewInt64Coin("gas", 1), + sdk.NewInt64Coin("mineral", 1), } badSort2 := sdk.Coins{ // both are after the first one, but the second and third are in the wrong order - *sdk.NewInt64Coin("gas", 1), - *sdk.NewInt64Coin("tree", 1), - *sdk.NewInt64Coin("mineral", 1), + sdk.NewInt64Coin("gas", 1), + sdk.NewInt64Coin("tree", 1), + sdk.NewInt64Coin("mineral", 1), } badAmt := sdk.Coins{ - *sdk.NewInt64Coin("gas", 1), - *sdk.NewInt64Coin("tree", 0), - *sdk.NewInt64Coin("mineral", 1), + sdk.NewInt64Coin("gas", 1), + sdk.NewInt64Coin("tree", 0), + sdk.NewInt64Coin("mineral", 1), } dup := sdk.Coins{ - *sdk.NewInt64Coin("gas", 1), - *sdk.NewInt64Coin("gas", 1), - *sdk.NewInt64Coin("mineral", 1), + sdk.NewInt64Coin("gas", 1), + sdk.NewInt64Coin("gas", 1), + sdk.NewInt64Coin("mineral", 1), } cases := []struct { @@ -747,19 +747,19 @@ func (s *coinTestSuite) TestSortCoins() { func (s *coinTestSuite) TestAmountOf() { case0 := sdk.Coins{} case1 := sdk.Coins{ - *sdk.NewInt64Coin("gold", 0), + sdk.NewInt64Coin("gold", 0), } case2 := sdk.Coins{ - *sdk.NewInt64Coin("gas", 1), - *sdk.NewInt64Coin("mineral", 1), - *sdk.NewInt64Coin("tree", 1), + sdk.NewInt64Coin("gas", 1), + sdk.NewInt64Coin("mineral", 1), + sdk.NewInt64Coin("tree", 1), } case3 := sdk.Coins{ - *sdk.NewInt64Coin("mineral", 1), - *sdk.NewInt64Coin("tree", 1), + sdk.NewInt64Coin("mineral", 1), + sdk.NewInt64Coin("tree", 1), } case4 := sdk.Coins{ - *sdk.NewInt64Coin("gas", 8), + sdk.NewInt64Coin("gas", 8), } cases := []struct { @@ -790,69 +790,69 @@ func (s *coinTestSuite) TestCoinsIsAnyGTE() { one := sdk.OneInt() two := sdk.NewInt(2) - s.Require().False((&sdk.Coins{}).IsAnyGTE(sdk.Coins{})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAnyGTE(sdk.Coins{})) - s.Require().False((&sdk.Coins{}).IsAnyGTE(sdk.Coins{{testDenom1, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAnyGTE(sdk.Coins{{testDenom1, *two}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAnyGTE(sdk.Coins{{testDenom2, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}).IsAnyGTE(sdk.Coins{{testDenom1, *two}, {testDenom2, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}}).IsAnyGTE(sdk.Coins{{testDenom1, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *two}}).IsAnyGTE(sdk.Coins{{testDenom1, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}}).IsAnyGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().True((&sdk.Coins{{testDenom2, *two}}).IsAnyGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().False((&sdk.Coins{{testDenom2, *one}}).IsAnyGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}).IsAnyGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAnyGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().True((&sdk.Coins{{"xxx", *one}, {"yyy", *one}}).IsAnyGTE(sdk.Coins{{testDenom2, *one}, {"ccc", *one}, {"yyy", *one}, {"zzz", *one}})) + s.Require().False(sdk.Coins{}.IsAnyGTE(sdk.Coins{})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAnyGTE(sdk.Coins{})) + s.Require().False(sdk.Coins{}.IsAnyGTE(sdk.Coins{{testDenom1, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAnyGTE(sdk.Coins{{testDenom1, two}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAnyGTE(sdk.Coins{{testDenom2, one}})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, two}}.IsAnyGTE(sdk.Coins{{testDenom1, two}, {testDenom2, one}})) + s.Require().True(sdk.Coins{{testDenom1, one}}.IsAnyGTE(sdk.Coins{{testDenom1, one}})) + s.Require().True(sdk.Coins{{testDenom1, two}}.IsAnyGTE(sdk.Coins{{testDenom1, one}})) + s.Require().True(sdk.Coins{{testDenom1, one}}.IsAnyGTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().True(sdk.Coins{{testDenom2, two}}.IsAnyGTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().False(sdk.Coins{{testDenom2, one}}.IsAnyGTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, two}}.IsAnyGTE(sdk.Coins{{testDenom1, one}, {testDenom2, one}})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAnyGTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().True(sdk.Coins{{"xxx", one}, {"yyy", one}}.IsAnyGTE(sdk.Coins{{testDenom2, one}, {"ccc", one}, {"yyy", one}, {"zzz", one}})) } func (s *coinTestSuite) TestCoinsIsAllGT() { one := sdk.OneInt() two := sdk.NewInt(2) - s.Require().False((&sdk.Coins{}).IsAllGT(sdk.Coins{})) - s.Require().True((&sdk.Coins{{testDenom1, *one}}).IsAllGT(sdk.Coins{})) - s.Require().False((&sdk.Coins{}).IsAllGT(sdk.Coins{{testDenom1, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGT(sdk.Coins{{testDenom1, *two}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGT(sdk.Coins{{testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}).IsAllGT(sdk.Coins{{testDenom1, *two}, {testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGT(sdk.Coins{{testDenom1, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *two}}).IsAllGT(sdk.Coins{{testDenom1, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGT(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().False((&sdk.Coins{{testDenom2, *two}}).IsAllGT(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().False((&sdk.Coins{{testDenom2, *one}}).IsAllGT(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}).IsAllGT(sdk.Coins{{testDenom1, *one}, {testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllGT(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().False((&sdk.Coins{{"xxx", *one}, {"yyy", *one}}).IsAllGT(sdk.Coins{{testDenom2, *one}, {"ccc", *one}, {"yyy", *one}, {"zzz", *one}})) + s.Require().False(sdk.Coins{}.IsAllGT(sdk.Coins{})) + s.Require().True(sdk.Coins{{testDenom1, one}}.IsAllGT(sdk.Coins{})) + s.Require().False(sdk.Coins{}.IsAllGT(sdk.Coins{{testDenom1, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGT(sdk.Coins{{testDenom1, two}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGT(sdk.Coins{{testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, two}}.IsAllGT(sdk.Coins{{testDenom1, two}, {testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGT(sdk.Coins{{testDenom1, one}})) + s.Require().True(sdk.Coins{{testDenom1, two}}.IsAllGT(sdk.Coins{{testDenom1, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGT(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().False(sdk.Coins{{testDenom2, two}}.IsAllGT(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().False(sdk.Coins{{testDenom2, one}}.IsAllGT(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, two}}.IsAllGT(sdk.Coins{{testDenom1, one}, {testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllGT(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().False(sdk.Coins{{"xxx", one}, {"yyy", one}}.IsAllGT(sdk.Coins{{testDenom2, one}, {"ccc", one}, {"yyy", one}, {"zzz", one}})) } func (s *coinTestSuite) TestCoinsIsAllGTE() { one := sdk.OneInt() two := sdk.NewInt(2) - s.Require().True((&sdk.Coins{}).IsAllGTE(sdk.Coins{})) - s.Require().True((&sdk.Coins{{testDenom1, *one}}).IsAllGTE(sdk.Coins{})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllGTE(sdk.Coins{{testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllGTE(sdk.Coins{{testDenom2, *two}})) - s.Require().False((&sdk.Coins{}).IsAllGTE(sdk.Coins{{testDenom1, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGTE(sdk.Coins{{testDenom1, *two}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGTE(sdk.Coins{{testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}).IsAllGTE(sdk.Coins{{testDenom1, *two}, {testDenom2, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}}).IsAllGTE(sdk.Coins{{testDenom1, *one}})) - s.Require().True((&sdk.Coins{{testDenom1, *two}}).IsAllGTE(sdk.Coins{{testDenom1, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}}).IsAllGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().False((&sdk.Coins{{testDenom2, *two}}).IsAllGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().False((&sdk.Coins{{testDenom2, *one}}).IsAllGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().True((&sdk.Coins{{testDenom1, *one}, {testDenom2, *two}}).IsAllGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *one}})) - s.Require().False((&sdk.Coins{{testDenom1, *one}, {testDenom2, *one}}).IsAllGTE(sdk.Coins{{testDenom1, *one}, {testDenom2, *two}})) - s.Require().False((&sdk.Coins{{"xxx", *one}, {"yyy", *one}}).IsAllGTE(sdk.Coins{{testDenom2, *one}, {"ccc", *one}, {"yyy", *one}, {"zzz", *one}})) + s.Require().True(sdk.Coins{}.IsAllGTE(sdk.Coins{})) + s.Require().True(sdk.Coins{{testDenom1, one}}.IsAllGTE(sdk.Coins{})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllGTE(sdk.Coins{{testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllGTE(sdk.Coins{{testDenom2, two}})) + s.Require().False(sdk.Coins{}.IsAllGTE(sdk.Coins{{testDenom1, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGTE(sdk.Coins{{testDenom1, two}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGTE(sdk.Coins{{testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, two}}.IsAllGTE(sdk.Coins{{testDenom1, two}, {testDenom2, one}})) + s.Require().True(sdk.Coins{{testDenom1, one}}.IsAllGTE(sdk.Coins{{testDenom1, one}})) + s.Require().True(sdk.Coins{{testDenom1, two}}.IsAllGTE(sdk.Coins{{testDenom1, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}}.IsAllGTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().False(sdk.Coins{{testDenom2, two}}.IsAllGTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().False(sdk.Coins{{testDenom2, one}}.IsAllGTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().True(sdk.Coins{{testDenom1, one}, {testDenom2, two}}.IsAllGTE(sdk.Coins{{testDenom1, one}, {testDenom2, one}})) + s.Require().False(sdk.Coins{{testDenom1, one}, {testDenom2, one}}.IsAllGTE(sdk.Coins{{testDenom1, one}, {testDenom2, two}})) + s.Require().False(sdk.Coins{{"xxx", one}, {"yyy", one}}.IsAllGTE(sdk.Coins{{testDenom2, one}, {"ccc", one}, {"yyy", one}, {"zzz", one}})) } func (s *coinTestSuite) TestNewCoins() { tenatom := sdk.NewInt64Coin("atom", 10) tenbtc := sdk.NewInt64Coin("btc", 10) zeroeth := sdk.NewInt64Coin("eth", 0) - invalidCoin := sdk.Coin{"0ETH", *sdk.OneInt()} + invalidCoin := sdk.Coin{"0ETH", sdk.OneInt()} tests := []struct { name string coins sdk.Coins @@ -860,11 +860,11 @@ func (s *coinTestSuite) TestNewCoins() { wantPanic bool }{ {"empty args", []sdk.Coin{}, sdk.Coins{}, false}, - {"one coin", []sdk.Coin{*tenatom}, sdk.Coins{*tenatom}, false}, - {"sort after create", []sdk.Coin{*tenbtc, *tenatom}, sdk.Coins{*tenatom, *tenbtc}, false}, - {"sort and remove zeroes", []sdk.Coin{*zeroeth, *tenbtc, *tenatom}, sdk.Coins{*tenatom, *tenbtc}, false}, - {"panic on dups", []sdk.Coin{*tenatom, *tenatom}, sdk.Coins{}, true}, - {"panic on invalid coin", []sdk.Coin{invalidCoin, *tenatom}, sdk.Coins{}, true}, + {"one coin", []sdk.Coin{tenatom}, sdk.Coins{tenatom}, false}, + {"sort after create", []sdk.Coin{tenbtc, tenatom}, sdk.Coins{tenatom, tenbtc}, false}, + {"sort and remove zeroes", []sdk.Coin{zeroeth, tenbtc, tenatom}, sdk.Coins{tenatom, tenbtc}, false}, + {"panic on dups", []sdk.Coin{tenatom, tenatom}, sdk.Coins{}, true}, + {"panic on invalid coin", []sdk.Coin{invalidCoin, tenatom}, sdk.Coins{}, true}, } for _, tt := range tests { if tt.wantPanic { @@ -891,16 +891,16 @@ func (s *coinTestSuite) TestCoinsIsAnyGT() { expPass bool }{ {"{} ≤ {}", sdk.Coins{}, sdk.Coins{}, false}, - {"{} ≤ 5atom", sdk.Coins{}, sdk.Coins{*fiveAtom}, false}, - {"5atom > 2atom", sdk.Coins{*fiveAtom}, sdk.Coins{*twoAtom}, true}, - {"2atom ≤ 5atom", sdk.Coins{*twoAtom}, sdk.Coins{*fiveAtom}, false}, - {"2atom,6eth > 2btc,5atom,3eth", sdk.Coins{*twoAtom, *sixEth}, sdk.Coins{*twoBtc, *fiveAtom, *threeEth}, true}, - {"2btc,2atom,3eth ≤ 5atom,6eth", sdk.Coins{*twoBtc, *twoAtom, *threeEth}, sdk.Coins{*fiveAtom, *sixEth}, false}, - {"2atom,6eth ≤ 2btc,5atom", sdk.Coins{*twoAtom, *sixEth}, sdk.Coins{*twoBtc, *fiveAtom}, false}, + {"{} ≤ 5atom", sdk.Coins{}, sdk.Coins{fiveAtom}, false}, + {"5atom > 2atom", sdk.Coins{fiveAtom}, sdk.Coins{twoAtom}, true}, + {"2atom ≤ 5atom", sdk.Coins{twoAtom}, sdk.Coins{fiveAtom}, false}, + {"2atom,6eth > 2btc,5atom,3eth", sdk.Coins{twoAtom, sixEth}, sdk.Coins{twoBtc, fiveAtom, threeEth}, true}, + {"2btc,2atom,3eth ≤ 5atom,6eth", sdk.Coins{twoBtc, twoAtom, threeEth}, sdk.Coins{fiveAtom, sixEth}, false}, + {"2atom,6eth ≤ 2btc,5atom", sdk.Coins{twoAtom, sixEth}, sdk.Coins{twoBtc, fiveAtom}, false}, } for _, tc := range tests { - s.Require().Equal(tc.expPass, tc.coinsA.IsAnyGT(tc.coinsB), tc.name) + s.Require().True(tc.expPass == tc.coinsA.IsAnyGT(tc.coinsB), tc.name) } } @@ -912,11 +912,11 @@ func (s *coinTestSuite) TestMarshalJSONCoins() { }{ {"nil coins", nil, `[]`}, {"empty coins", sdk.Coins{}, `[]`}, - {"non-empty coins", *sdk.MustNewCoins(*sdk.NewInt64Coin("foo", 50)), `[{"denom":"foo","amount":"50"}]`}, + {"non-empty coins", sdk.MustNewCoins(sdk.NewInt64Coin("foo", 50)), `[{"denom":"foo","amount":"50"}]`}, } for _, tc := range testCases { - bz, err := tc.input.MarshalJSON() + bz, err := jsoniter.Marshal(tc.input) s.Require().NoError(err) s.Require().Equal(tc.strOutput, string(bz)) diff --git a/usecase/coin/dec_coin.go b/usecase/coin/dec_coin.go index d09eac400..224bdb805 100644 --- a/usecase/coin/dec_coin.go +++ b/usecase/coin/dec_coin.go @@ -23,7 +23,7 @@ func NewDecCoin(denom string, amount Int) DecCoin { return DecCoin{ Denom: coin.Denom, - Amount: *coin.Amount.ToDec(), + Amount: coin.Amount.ToDec(), } } @@ -36,12 +36,13 @@ func NewDecCoinFromString(denom string, amountStr string) (DecCoin, error) { return DecCoin{}, fmt.Errorf("invalid Dec coin amount: %s", amountStr) } - return NewDecCoinFromDec(denom, *amount), nil + return NewDecCoinFromDec(denom, amount), nil } // NewDecCoinFromDec creates a new DecCoin instance from a Dec. func NewDecCoinFromDec(denom string, amount Dec) DecCoin { mustValidateDenom(denom) + if amount.IsNegative() { panic(fmt.Sprintf("negative decimal coin amount: %v\n", amount)) } @@ -60,14 +61,14 @@ func NewDecCoinFromCoin(coin Coin) DecCoin { return DecCoin{ Denom: coin.Denom, - Amount: *coin.Amount.ToDec(), + Amount: coin.Amount.ToDec(), } } // NewInt64DecCoin returns a new DecCoin with a denomination and amount. It will // panic if the amount is negative or denom is invalid. func NewInt64DecCoin(denom string, amount int64) DecCoin { - return NewDecCoin(denom, *NewInt(amount)) + return NewDecCoin(denom, NewInt(amount)) } // IsZero returns if the DecCoin amount is zero. @@ -82,7 +83,7 @@ func (coin DecCoin) IsGTE(other DecCoin) bool { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, other.Denom)) } - return !coin.Amount.LT(&other.Amount) + return !coin.Amount.LT(other.Amount) } // IsLT returns true if they are the same type and the receiver is @@ -92,7 +93,7 @@ func (coin DecCoin) IsLT(other DecCoin) bool { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, other.Denom)) } - return coin.Amount.LT(&other.Amount) + return coin.Amount.LT(other.Amount) } // IsEqual returns true if the two sets of Coins have the same value. @@ -101,7 +102,7 @@ func (coin DecCoin) IsEqual(other DecCoin) bool { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, other.Denom)) } - return coin.Amount.Equal(&other.Amount) + return coin.Amount.Equal(other.Amount) } // Add adds amounts of two decimal coins with same denom. @@ -109,7 +110,7 @@ func (coin DecCoin) Add(coinB DecCoin) DecCoin { if coin.Denom != coinB.Denom { panic(fmt.Sprintf("coin denom different: %v %v\n", coin.Denom, coinB.Denom)) } - return DecCoin{coin.Denom, *coin.Amount.Add(&coinB.Amount)} + return DecCoin{coin.Denom, coin.Amount.Add(coinB.Amount)} } // Sub subtracts amounts of two decimal coins with same denom. @@ -117,7 +118,7 @@ func (coin DecCoin) Sub(coinB DecCoin) DecCoin { if coin.Denom != coinB.Denom { panic(fmt.Sprintf("coin denom different: %v %v\n", coin.Denom, coinB.Denom)) } - res := DecCoin{coin.Denom, *coin.Amount.Sub(&coinB.Amount)} + res := DecCoin{coin.Denom, coin.Amount.Sub(coinB.Amount)} if res.IsNegative() { panic("negative decimal coin amount") } @@ -129,7 +130,7 @@ func (coin DecCoin) Sub(coinB DecCoin) DecCoin { func (coin DecCoin) TruncateDecimal() (Coin, DecCoin) { truncated := coin.Amount.TruncateInt() change := coin.Amount.Sub(truncated.ToDec()) - return *MustNewCoin(coin.Denom, *truncated), NewDecCoinFromDec(coin.Denom, *change) + return MustNewCoin(coin.Denom, truncated), NewDecCoinFromDec(coin.Denom, change) } // IsPositive returns true if coin amount is positive. @@ -149,7 +150,7 @@ func (coin DecCoin) IsNegative() bool { // String implements the Stringer interface for DecCoin. It returns a // human-readable representation of a decimal coin. func (coin DecCoin) String() string { - return fmt.Sprintf("%v%v", &coin.Amount, coin.Denom) + return fmt.Sprintf("%v%v", coin.Amount, coin.Denom) } // Validate returns an error if the DecCoin has a negative amount or if the denom is invalid. @@ -207,7 +208,7 @@ func NewDecCoinsFromCoins(coins ...Coin) DecCoins { decCoins := make(DecCoins, len(coins)) // TODO: Return error from NewCoins.validate() instead of panic newCoins := MustNewCoins(coins...) - for i, coin := range *newCoins { + for i, coin := range newCoins { decCoins[i] = NewDecCoinFromCoin(coin) } @@ -316,7 +317,7 @@ func (coins DecCoins) negative() DecCoins { for _, coin := range coins { res = append(res, DecCoin{ Denom: coin.Denom, - Amount: *coin.Amount.Neg(), + Amount: coin.Amount.Neg(), }) } return res @@ -347,10 +348,9 @@ func (coins DecCoins) SafeSub(coinsB DecCoins) (DecCoins, bool) { func (coins DecCoins) Intersect(coinsB DecCoins) DecCoins { res := make([]DecCoin, len(coins)) for i, coin := range coins { - amount := coinsB.AmountOf(coin.Denom) minCoin := DecCoin{ Denom: coin.Denom, - Amount: *MinDec(&coin.Amount, &amount), + Amount: MinDec(coin.Amount, coinsB.AmountOf(coin.Denom)), } res[i] = minCoin } @@ -385,7 +385,7 @@ func (coins DecCoins) MulDec(d Dec) DecCoins { for _, coin := range coins { product := DecCoin{ Denom: coin.Denom, - Amount: *coin.Amount.Mul(&d), + Amount: coin.Amount.Mul(d), } if !product.IsZero() { @@ -406,7 +406,7 @@ func (coins DecCoins) MulDecTruncate(d Dec) DecCoins { for _, coin := range coins { product := DecCoin{ Denom: coin.Denom, - Amount: *coin.Amount.MulTruncate(&d), + Amount: coin.Amount.MulTruncate(d), } if !product.IsZero() { @@ -429,7 +429,7 @@ func (coins DecCoins) QuoDec(d Dec) DecCoins { for _, coin := range coins { quotient := DecCoin{ Denom: coin.Denom, - Amount: *coin.Amount.Quo(&d), + Amount: coin.Amount.Quo(d), } if !quotient.IsZero() { @@ -453,7 +453,7 @@ func (coins DecCoins) QuoDecTruncate(d Dec) DecCoins { for _, coin := range coins { quotient := DecCoin{ Denom: coin.Denom, - Amount: *coin.Amount.QuoTruncate(&d), + Amount: coin.Amount.QuoTruncate(d), } if !quotient.IsZero() { @@ -475,14 +475,14 @@ func (coins DecCoins) AmountOf(denom string) Dec { switch len(coins) { case 0: - return *ZeroDec() + return ZeroDec() case 1: coin := coins[0] if coin.Denom == denom { return coin.Amount } - return *ZeroDec() + return ZeroDec() default: midIdx := len(coins) / 2 // 2:1, 3:1, 4:2 @@ -666,7 +666,7 @@ func ParseDecCoin(coinStr string) (coin DecCoin, err error) { return DecCoin{}, fmt.Errorf("invalid denom cannot contain upper case characters or spaces: %s", err) } - return NewDecCoinFromDec(denomStr, *amount), nil + return NewDecCoinFromDec(denomStr, amount), nil } // MustParseDecCoins will parse out a list of decimal coins separated by commas. It behaves the same diff --git a/usecase/coin/dec_coin_test.go b/usecase/coin/dec_coin_test.go index b83618469..6a5fec6c2 100644 --- a/usecase/coin/dec_coin_test.go +++ b/usecase/coin/dec_coin_test.go @@ -34,31 +34,31 @@ func (s *decCoinTestSuite) TestNewDecCoin() { func (s *decCoinTestSuite) TestNewDecCoinFromDec() { s.Require().NotPanics(func() { - sdk.NewDecCoinFromDec(testDenom1, *sdk.NewDec(5)) + sdk.NewDecCoinFromDec(testDenom1, sdk.NewDec(5)) }) s.Require().NotPanics(func() { - sdk.NewDecCoinFromDec(testDenom1, *sdk.ZeroDec()) + sdk.NewDecCoinFromDec(testDenom1, sdk.ZeroDec()) }) s.Require().NotPanics(func() { - sdk.NewDecCoinFromDec(strings.ToUpper(testDenom1), *sdk.NewDec(5)) + sdk.NewDecCoinFromDec(strings.ToUpper(testDenom1), sdk.NewDec(5)) }) s.Require().Panics(func() { - sdk.NewDecCoinFromDec(testDenom1, *sdk.NewDec(-5)) + sdk.NewDecCoinFromDec(testDenom1, sdk.NewDec(-5)) }) } func (s *decCoinTestSuite) TestNewDecCoinFromCoin() { s.Require().NotPanics(func() { - sdk.NewDecCoinFromCoin(sdk.Coin{testDenom1, *sdk.NewInt(5)}) + sdk.NewDecCoinFromCoin(sdk.Coin{testDenom1, sdk.NewInt(5)}) }) s.Require().NotPanics(func() { - sdk.NewDecCoinFromCoin(sdk.Coin{testDenom1, *sdk.NewInt(0)}) + sdk.NewDecCoinFromCoin(sdk.Coin{testDenom1, sdk.NewInt(0)}) }) s.Require().NotPanics(func() { - sdk.NewDecCoinFromCoin(sdk.Coin{strings.ToUpper(testDenom1), *sdk.NewInt(5)}) + sdk.NewDecCoinFromCoin(sdk.Coin{strings.ToUpper(testDenom1), sdk.NewInt(5)}) }) s.Require().Panics(func() { - sdk.NewDecCoinFromCoin(sdk.Coin{testDenom1, *sdk.NewInt(-5)}) + sdk.NewDecCoinFromCoin(sdk.Coin{testDenom1, sdk.NewInt(-5)}) }) } @@ -71,9 +71,9 @@ func (s *decCoinTestSuite) TestDecCoinIsPositive() { } func (s *decCoinTestSuite) TestAddDecCoin() { - decCoinA1 := sdk.NewDecCoinFromDec(testDenom1, *sdk.NewDecWithPrec(11, 1)) - decCoinA2 := sdk.NewDecCoinFromDec(testDenom1, *sdk.NewDecWithPrec(22, 1)) - decCoinB1 := sdk.NewDecCoinFromDec(testDenom2, *sdk.NewDecWithPrec(11, 1)) + decCoinA1 := sdk.NewDecCoinFromDec(testDenom1, sdk.NewDecWithPrec(11, 1)) + decCoinA2 := sdk.NewDecCoinFromDec(testDenom1, sdk.NewDecWithPrec(22, 1)) + decCoinB1 := sdk.NewDecCoinFromDec(testDenom2, sdk.NewDecWithPrec(11, 1)) // regular add res := decCoinA1.Add(decCoinA1) @@ -95,9 +95,9 @@ func (s *decCoinTestSuite) TestAddDecCoins() { inputTwo sdk.DecCoins expected sdk.DecCoins }{ - {sdk.DecCoins{{testDenom1, *one}, {testDenom2, *one}}, sdk.DecCoins{{testDenom1, *one}, {testDenom2, *one}}, sdk.DecCoins{{testDenom1, *two}, {testDenom2, *two}}}, - {sdk.DecCoins{{testDenom1, *zero}, {testDenom2, *one}}, sdk.DecCoins{{testDenom1, *zero}, {testDenom2, *zero}}, sdk.DecCoins{{testDenom2, *one}}}, - {sdk.DecCoins{{testDenom1, *zero}, {testDenom2, *zero}}, sdk.DecCoins{{testDenom1, *zero}, {testDenom2, *zero}}, sdk.DecCoins(nil)}, + {sdk.DecCoins{{testDenom1, one}, {testDenom2, one}}, sdk.DecCoins{{testDenom1, one}, {testDenom2, one}}, sdk.DecCoins{{testDenom1, two}, {testDenom2, two}}}, + {sdk.DecCoins{{testDenom1, zero}, {testDenom2, one}}, sdk.DecCoins{{testDenom1, zero}, {testDenom2, zero}}, sdk.DecCoins{{testDenom2, one}}}, + {sdk.DecCoins{{testDenom1, zero}, {testDenom2, zero}}, sdk.DecCoins{{testDenom1, zero}, {testDenom2, zero}}, sdk.DecCoins(nil)}, } for tcIndex, tc := range cases { @@ -116,11 +116,11 @@ func (s *decCoinTestSuite) TestFilteredZeroDecCoins() { { name: "all greater than zero", input: sdk.DecCoins{ - {"testa", *sdk.NewDec(1)}, - {"testb", *sdk.NewDec(2)}, - {"testc", *sdk.NewDec(3)}, - {"testd", *sdk.NewDec(4)}, - {"teste", *sdk.NewDec(5)}, + {"testa", sdk.NewDec(1)}, + {"testb", sdk.NewDec(2)}, + {"testc", sdk.NewDec(3)}, + {"testd", sdk.NewDec(4)}, + {"teste", sdk.NewDec(5)}, }, original: "1.000000000000000000testa,2.000000000000000000testb,3.000000000000000000testc,4.000000000000000000testd,5.000000000000000000teste", expected: "1.000000000000000000testa,2.000000000000000000testb,3.000000000000000000testc,4.000000000000000000testd,5.000000000000000000teste", @@ -128,11 +128,11 @@ func (s *decCoinTestSuite) TestFilteredZeroDecCoins() { { name: "zero coin in middle", input: sdk.DecCoins{ - {"testa", *sdk.NewDec(1)}, - {"testb", *sdk.NewDec(2)}, - {"testc", *sdk.NewDec(0)}, - {"testd", *sdk.NewDec(4)}, - {"teste", *sdk.NewDec(5)}, + {"testa", sdk.NewDec(1)}, + {"testb", sdk.NewDec(2)}, + {"testc", sdk.NewDec(0)}, + {"testd", sdk.NewDec(4)}, + {"teste", sdk.NewDec(5)}, }, original: "1.000000000000000000testa,2.000000000000000000testb,0.000000000000000000testc,4.000000000000000000testd,5.000000000000000000teste", expected: "1.000000000000000000testa,2.000000000000000000testb,4.000000000000000000testd,5.000000000000000000teste", @@ -140,11 +140,11 @@ func (s *decCoinTestSuite) TestFilteredZeroDecCoins() { { name: "zero coin end (unordered)", input: sdk.DecCoins{ - {"teste", *sdk.NewDec(5)}, - {"testc", *sdk.NewDec(3)}, - {"testa", *sdk.NewDec(1)}, - {"testd", *sdk.NewDec(4)}, - {"testb", *sdk.NewDec(0)}, + {"teste", sdk.NewDec(5)}, + {"testc", sdk.NewDec(3)}, + {"testa", sdk.NewDec(1)}, + {"testd", sdk.NewDec(4)}, + {"testb", sdk.NewDec(0)}, }, original: "5.000000000000000000teste,3.000000000000000000testc,1.000000000000000000testa,4.000000000000000000testd,0.000000000000000000testb", expected: "1.000000000000000000testa,3.000000000000000000testc,4.000000000000000000testd,5.000000000000000000teste", @@ -165,22 +165,22 @@ func (s *decCoinTestSuite) TestIsValid() { msg string }{ { - sdk.NewDecCoin("mytoken", *sdk.NewInt(10)), + sdk.NewDecCoin("mytoken", sdk.NewInt(10)), true, "valid coins should have passed", }, { - sdk.DecCoin{Denom: "BTC", Amount: *sdk.NewDec(10)}, + sdk.DecCoin{Denom: "BTC", Amount: sdk.NewDec(10)}, true, "valid uppercase denom", }, { - sdk.DecCoin{Denom: "Bitcoin", Amount: *sdk.NewDec(10)}, + sdk.DecCoin{Denom: "Bitcoin", Amount: sdk.NewDec(10)}, true, "valid mixed case denom", }, { - sdk.DecCoin{Denom: "btc", Amount: *sdk.NewDec(-10)}, + sdk.DecCoin{Denom: "btc", Amount: sdk.NewDec(-10)}, false, "negative amount", }, @@ -203,23 +203,23 @@ func (s *decCoinTestSuite) TestSubDecCoin() { msg string }{ { - sdk.NewDecCoin("mytoken", *sdk.NewInt(20)), + sdk.NewDecCoin("mytoken", sdk.NewInt(20)), true, "valid coins should have passed", }, { - sdk.NewDecCoin("othertoken", *sdk.NewInt(20)), + sdk.NewDecCoin("othertoken", sdk.NewInt(20)), false, "denom mismatch", }, { - sdk.NewDecCoin("mytoken", *sdk.NewInt(9)), + sdk.NewDecCoin("mytoken", sdk.NewInt(9)), false, "negative amount", }, } - decCoin := sdk.NewDecCoin("mytoken", *sdk.NewInt(10)) + decCoin := sdk.NewDecCoin("mytoken", sdk.NewInt(10)) for _, tc := range tests { tc := tc @@ -239,23 +239,23 @@ func (s *decCoinTestSuite) TestSubDecCoins() { msg string }{ { - sdk.NewDecCoinsFromCoins(*sdk.MustNewCoin("mytoken", *sdk.NewInt(10)), *sdk.MustNewCoin("btc", *sdk.NewInt(20)), *sdk.MustNewCoin("eth", *sdk.NewInt(30))), + sdk.NewDecCoinsFromCoins(sdk.MustNewCoin("mytoken", sdk.NewInt(10)), sdk.MustNewCoin("btc", sdk.NewInt(20)), sdk.MustNewCoin("eth", sdk.NewInt(30))), true, "sorted coins should have passed", }, { - sdk.DecCoins{sdk.NewDecCoin("mytoken", *sdk.NewInt(10)), sdk.NewDecCoin("btc", *sdk.NewInt(20)), sdk.NewDecCoin("eth", *sdk.NewInt(30))}, + sdk.DecCoins{sdk.NewDecCoin("mytoken", sdk.NewInt(10)), sdk.NewDecCoin("btc", sdk.NewInt(20)), sdk.NewDecCoin("eth", sdk.NewInt(30))}, false, "unorted coins should panic", }, { - sdk.DecCoins{sdk.DecCoin{Denom: "BTC", Amount: *sdk.NewDec(10)}, sdk.NewDecCoin("eth", *sdk.NewInt(15)), sdk.NewDecCoin("mytoken", *sdk.NewInt(5))}, + sdk.DecCoins{sdk.DecCoin{Denom: "BTC", Amount: sdk.NewDec(10)}, sdk.NewDecCoin("eth", sdk.NewInt(15)), sdk.NewDecCoin("mytoken", sdk.NewInt(5))}, false, "invalid denoms", }, } - decCoins := sdk.NewDecCoinsFromCoins(*sdk.MustNewCoin("btc", *sdk.NewInt(10)), *sdk.MustNewCoin("eth", *sdk.NewInt(15)), *sdk.MustNewCoin("mytoken", *sdk.NewInt(5))) + decCoins := sdk.NewDecCoinsFromCoins(sdk.MustNewCoin("btc", sdk.NewInt(10)), sdk.MustNewCoin("eth", sdk.NewInt(15)), sdk.MustNewCoin("mytoken", sdk.NewInt(5))) for _, tc := range tests { tc := tc @@ -323,16 +323,16 @@ func (s *decCoinTestSuite) TestDecCoinsValidate() { expectedPass bool }{ {sdk.DecCoins{}, true}, - {sdk.DecCoins{sdk.DecCoin{testDenom1, *sdk.NewDec(5)}}, true}, - {sdk.DecCoins{sdk.DecCoin{testDenom1, *sdk.NewDec(5)}, sdk.DecCoin{testDenom2, *sdk.NewDec(100000)}}, true}, - {sdk.DecCoins{sdk.DecCoin{testDenom1, *sdk.NewDec(-5)}}, false}, - {sdk.DecCoins{sdk.DecCoin{"BTC", *sdk.NewDec(5)}}, true}, - {sdk.DecCoins{sdk.DecCoin{"0BTC", *sdk.NewDec(5)}}, false}, - {sdk.DecCoins{sdk.DecCoin{testDenom1, *sdk.NewDec(5)}, sdk.DecCoin{"B", *sdk.NewDec(100000)}}, false}, - {sdk.DecCoins{sdk.DecCoin{testDenom1, *sdk.NewDec(5)}, sdk.DecCoin{testDenom2, *sdk.NewDec(-100000)}}, false}, - {sdk.DecCoins{sdk.DecCoin{testDenom1, *sdk.NewDec(-5)}, sdk.DecCoin{testDenom2, *sdk.NewDec(100000)}}, false}, - {sdk.DecCoins{sdk.DecCoin{"BTC", *sdk.NewDec(5)}, sdk.DecCoin{testDenom2, *sdk.NewDec(100000)}}, true}, - {sdk.DecCoins{sdk.DecCoin{"0BTC", *sdk.NewDec(5)}, sdk.DecCoin{testDenom2, *sdk.NewDec(100000)}}, false}, + {sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(5)}}, true}, + {sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(5)}, sdk.DecCoin{testDenom2, sdk.NewDec(100000)}}, true}, + {sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(-5)}}, false}, + {sdk.DecCoins{sdk.DecCoin{"BTC", sdk.NewDec(5)}}, true}, + {sdk.DecCoins{sdk.DecCoin{"0BTC", sdk.NewDec(5)}}, false}, + {sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(5)}, sdk.DecCoin{"B", sdk.NewDec(100000)}}, false}, + {sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(5)}, sdk.DecCoin{testDenom2, sdk.NewDec(-100000)}}, false}, + {sdk.DecCoins{sdk.DecCoin{testDenom1, sdk.NewDec(-5)}, sdk.DecCoin{testDenom2, sdk.NewDec(100000)}}, false}, + {sdk.DecCoins{sdk.DecCoin{"BTC", sdk.NewDec(5)}, sdk.DecCoin{testDenom2, sdk.NewDec(100000)}}, true}, + {sdk.DecCoins{sdk.DecCoin{"0BTC", sdk.NewDec(5)}, sdk.DecCoin{testDenom2, sdk.NewDec(100000)}}, false}, } for i, tc := range testCases { @@ -352,35 +352,35 @@ func (s *decCoinTestSuite) TestParseDecCoins() { expectedErr bool }{ {"", nil, false}, - {"4stake", sdk.DecCoins{sdk.NewDecCoinFromDec("stake", *sdk.NewDecFromInt(*sdk.NewInt(4)))}, false}, + {"4stake", sdk.DecCoins{sdk.NewDecCoinFromDec("stake", sdk.NewDecFromInt(sdk.NewInt(4)))}, false}, {"5.5atom,4stake", sdk.DecCoins{ - sdk.NewDecCoinFromDec("atom", *sdk.NewDecWithPrec(5500000000000000000, sdk.Precision)), - sdk.NewDecCoinFromDec("stake", *sdk.NewDec(4)), + sdk.NewDecCoinFromDec("atom", sdk.NewDecWithPrec(5500000000000000000, sdk.Precision)), + sdk.NewDecCoinFromDec("stake", sdk.NewDec(4)), }, false}, {"0.0stake", sdk.DecCoins{}, false}, // remove zero coins {"10.0btc,1.0atom,20.0btc", nil, true}, { "0.004STAKE", - sdk.DecCoins{sdk.NewDecCoinFromDec("STAKE", *sdk.NewDecWithPrec(4000000000000000, sdk.Precision))}, + sdk.DecCoins{sdk.NewDecCoinFromDec("STAKE", sdk.NewDecWithPrec(4000000000000000, sdk.Precision))}, false, }, { "0.004stake", - sdk.DecCoins{sdk.NewDecCoinFromDec("stake", *sdk.NewDecWithPrec(4000000000000000, sdk.Precision))}, + sdk.DecCoins{sdk.NewDecCoinFromDec("stake", sdk.NewDecWithPrec(4000000000000000, sdk.Precision))}, false, }, { "5.04atom,0.004stake", sdk.DecCoins{ - sdk.NewDecCoinFromDec("atom", *sdk.NewDecWithPrec(5040000000000000000, sdk.Precision)), - sdk.NewDecCoinFromDec("stake", *sdk.NewDecWithPrec(4000000000000000, sdk.Precision)), + sdk.NewDecCoinFromDec("atom", sdk.NewDecWithPrec(5040000000000000000, sdk.Precision)), + sdk.NewDecCoinFromDec("stake", sdk.NewDecWithPrec(4000000000000000, sdk.Precision)), }, false, }, {"0.0stake,0.004stake,5.04atom", // remove zero coins sdk.DecCoins{ - sdk.NewDecCoinFromDec("atom", *sdk.NewDecWithPrec(5040000000000000000, sdk.Precision)), - sdk.NewDecCoinFromDec("stake", *sdk.NewDecWithPrec(4000000000000000, sdk.Precision)), + sdk.NewDecCoinFromDec("atom", sdk.NewDecWithPrec(5040000000000000000, sdk.Precision)), + sdk.NewDecCoinFromDec("stake", sdk.NewDecWithPrec(4000000000000000, sdk.Precision)), }, false, }, @@ -405,8 +405,8 @@ func (s *decCoinTestSuite) TestDecCoinsString() { {sdk.DecCoins{}, ""}, { sdk.DecCoins{ - sdk.NewDecCoinFromDec("atom", *sdk.NewDecWithPrec(5040000000000000000, sdk.Precision)), - sdk.NewDecCoinFromDec("stake", *sdk.NewDecWithPrec(4000000000000000, sdk.Precision)), + sdk.NewDecCoinFromDec("atom", sdk.NewDecWithPrec(5040000000000000000, sdk.Precision)), + sdk.NewDecCoinFromDec("stake", sdk.NewDecWithPrec(4000000000000000, sdk.Precision)), }, "5.040000000000000000atom,0.004000000000000000stake", }, @@ -449,8 +449,8 @@ func (s *decCoinTestSuite) TestDecCoinsIntersect() { } func (s *decCoinTestSuite) TestDecCoinsTruncateDecimal() { - decCoinA := sdk.NewDecCoinFromDec("bar", *sdk.MustNewDecFromStr("5.41")) - decCoinB := sdk.NewDecCoinFromDec("foo", *sdk.MustNewDecFromStr("6.00")) + decCoinA := sdk.NewDecCoinFromDec("bar", sdk.MustNewDecFromStr("5.41")) + decCoinB := sdk.NewDecCoinFromDec("foo", sdk.MustNewDecFromStr("6.00")) testCases := []struct { input sdk.DecCoins @@ -460,12 +460,12 @@ func (s *decCoinTestSuite) TestDecCoinsTruncateDecimal() { {sdk.DecCoins{}, sdk.Coins(nil), sdk.DecCoins(nil)}, { sdk.DecCoins{decCoinA, decCoinB}, - sdk.Coins{*sdk.NewInt64Coin(decCoinA.Denom, 5), *sdk.NewInt64Coin(decCoinB.Denom, 6)}, - sdk.DecCoins{sdk.NewDecCoinFromDec(decCoinA.Denom, *sdk.MustNewDecFromStr("0.41"))}, + sdk.Coins{sdk.NewInt64Coin(decCoinA.Denom, 5), sdk.NewInt64Coin(decCoinB.Denom, 6)}, + sdk.DecCoins{sdk.NewDecCoinFromDec(decCoinA.Denom, sdk.MustNewDecFromStr("0.41"))}, }, { sdk.DecCoins{decCoinB}, - sdk.Coins{*sdk.NewInt64Coin(decCoinB.Denom, 6)}, + sdk.Coins{sdk.NewInt64Coin(decCoinB.Denom, 6)}, sdk.DecCoins(nil), }, } @@ -493,9 +493,9 @@ func (s *decCoinTestSuite) TestDecCoinsQuoDecTruncate() { result sdk.DecCoins panics bool }{ - {sdk.DecCoins{}, *sdk.ZeroDec(), sdk.DecCoins(nil), true}, - {sdk.DecCoins{sdk.NewDecCoinFromDec("foo", *x)}, *y, sdk.DecCoins(nil), false}, - {sdk.DecCoins{sdk.NewInt64DecCoin("foo", 5)}, *sdk.NewDec(2), sdk.DecCoins{sdk.NewDecCoinFromDec("foo", *sdk.MustNewDecFromStr("2.5"))}, false}, + {sdk.DecCoins{}, sdk.ZeroDec(), sdk.DecCoins(nil), true}, + {sdk.DecCoins{sdk.NewDecCoinFromDec("foo", x)}, y, sdk.DecCoins(nil), false}, + {sdk.DecCoins{sdk.NewInt64DecCoin("foo", 5)}, sdk.NewDec(2), sdk.DecCoins{sdk.NewDecCoinFromDec("foo", sdk.MustNewDecFromStr("2.5"))}, false}, } for i, tc := range testCases { @@ -510,8 +510,8 @@ func (s *decCoinTestSuite) TestDecCoinsQuoDecTruncate() { } func (s *decCoinTestSuite) TestNewDecCoinsWithIsValid() { - fake1 := append(sdk.NewDecCoins(sdk.NewDecCoin("mytoken", *sdk.NewInt(10))), sdk.DecCoin{Denom: "10BTC", Amount: *sdk.NewDec(10)}) - fake2 := append(sdk.NewDecCoins(sdk.NewDecCoin("mytoken", *sdk.NewInt(10))), sdk.DecCoin{Denom: "BTC", Amount: *sdk.NewDec(-10)}) + fake1 := append(sdk.NewDecCoins(sdk.NewDecCoin("mytoken", sdk.NewInt(10))), sdk.DecCoin{Denom: "10BTC", Amount: sdk.NewDec(10)}) + fake2 := append(sdk.NewDecCoins(sdk.NewDecCoin("mytoken", sdk.NewInt(10))), sdk.DecCoin{Denom: "BTC", Amount: sdk.NewDec(-10)}) tests := []struct { coin sdk.DecCoins @@ -519,7 +519,7 @@ func (s *decCoinTestSuite) TestNewDecCoinsWithIsValid() { msg string }{ { - sdk.NewDecCoins(sdk.NewDecCoin("mytoken", *sdk.NewInt(10))), + sdk.NewDecCoins(sdk.NewDecCoin("mytoken", sdk.NewInt(10))), true, "valid coins should have passed", }, @@ -546,8 +546,8 @@ func (s *decCoinTestSuite) TestNewDecCoinsWithIsValid() { } func (s *decCoinTestSuite) TestDecCoins_AddDecCoinWithIsValid() { - lengthTestDecCoins := sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", *sdk.NewInt(10))).Add(sdk.DecCoin{Denom: "BTC", Amount: *sdk.NewDec(10)}) - s.Require().Len(lengthTestDecCoins, 2, "should be 2") + lengthTestDecCoins := sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", sdk.NewInt(10))).Add(sdk.DecCoin{Denom: "BTC", Amount: sdk.NewDec(10)}) + s.Require().Equal(2, len(lengthTestDecCoins), "should be 2") tests := []struct { coin sdk.DecCoins @@ -555,17 +555,17 @@ func (s *decCoinTestSuite) TestDecCoins_AddDecCoinWithIsValid() { msg string }{ { - sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", *sdk.NewInt(10))), + sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", sdk.NewInt(10))), true, "valid coins should have passed", }, { - sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", *sdk.NewInt(10))).Add(sdk.DecCoin{Denom: "0BTC", Amount: *sdk.NewDec(10)}), + sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", sdk.NewInt(10))).Add(sdk.DecCoin{Denom: "0BTC", Amount: sdk.NewDec(10)}), false, "invalid denoms", }, { - sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", *sdk.NewInt(10))).Add(sdk.DecCoin{Denom: "BTC", Amount: *sdk.NewDec(-10)}), + sdk.NewDecCoins().Add(sdk.NewDecCoin("mytoken", sdk.NewInt(10))).Add(sdk.DecCoin{Denom: "BTC", Amount: sdk.NewDec(-10)}), false, "negative amount", }, diff --git a/usecase/coin/decimal.go b/usecase/coin/decimal.go index 397635eed..a22a0e984 100644 --- a/usecase/coin/decimal.go +++ b/usecase/coin/decimal.go @@ -58,9 +58,9 @@ func precisionInt() *big.Int { return new(big.Int).Set(precisionReuse) } -func ZeroDec() *Dec { return &Dec{new(big.Int).Set(zeroInt)} } -func OneDec() *Dec { return &Dec{precisionInt()} } -func SmallestDec() *Dec { return &Dec{new(big.Int).Set(oneInt)} } +func ZeroDec() Dec { return Dec{new(big.Int).Set(zeroInt)} } +func OneDec() Dec { return Dec{precisionInt()} } +func SmallestDec() Dec { return Dec{new(big.Int).Set(oneInt)} } // calculate the precision multiplier func calcPrecisionMultiplier(prec int64) *big.Int { @@ -83,42 +83,42 @@ func precisionMultiplier(prec int64) *big.Int { //______________________________________________________________________________________________ // create a new Dec from integer assuming whole number -func NewDec(i int64) *Dec { +func NewDec(i int64) Dec { return NewDecWithPrec(i, 0) } // create a new Dec from integer with decimal place at prec // CONTRACT: prec <= Precision -func NewDecWithPrec(i, prec int64) *Dec { - return &Dec{ +func NewDecWithPrec(i, prec int64) Dec { + return Dec{ new(big.Int).Mul(big.NewInt(i), precisionMultiplier(prec)), } } // create a new Dec from big integer assuming whole numbers // CONTRACT: prec <= Precision -func NewDecFromBigInt(i *big.Int) *Dec { +func NewDecFromBigInt(i *big.Int) Dec { return NewDecFromBigIntWithPrec(i, 0) } // create a new Dec from big integer assuming whole numbers // CONTRACT: prec <= Precision -func NewDecFromBigIntWithPrec(i *big.Int, prec int64) *Dec { - return &Dec{ +func NewDecFromBigIntWithPrec(i *big.Int, prec int64) Dec { + return Dec{ new(big.Int).Mul(i, precisionMultiplier(prec)), } } // create a new Dec from big integer assuming whole numbers // CONTRACT: prec <= Precision -func NewDecFromInt(i Int) *Dec { +func NewDecFromInt(i Int) Dec { return NewDecFromIntWithPrec(i, 0) } // create a new Dec from big integer with decimal place at prec // CONTRACT: prec <= Precision -func NewDecFromIntWithPrec(i Int, prec int64) *Dec { - return &Dec{ +func NewDecFromIntWithPrec(i Int, prec int64) Dec { + return Dec{ new(big.Int).Mul(i.BigInt(), precisionMultiplier(prec)), } } @@ -139,9 +139,9 @@ func NewDecFromIntWithPrec(i Int, prec int64) *Dec { // are provided in the string than the constant Precision. // // CONTRACT - This function does not mutate the input str. -func NewDecFromStr(str string) (*Dec, error) { +func NewDecFromStr(str string) (Dec, error) { if len(str) == 0 { - return &Dec{}, ErrEmptyDecimalStr + return Dec{}, ErrEmptyDecimalStr } // first extract any negative symbol @@ -152,7 +152,7 @@ func NewDecFromStr(str string) (*Dec, error) { } if len(str) == 0 { - return &Dec{}, ErrEmptyDecimalStr + return Dec{}, ErrEmptyDecimalStr } strs := strings.Split(str, ".") @@ -162,15 +162,15 @@ func NewDecFromStr(str string) (*Dec, error) { if len(strs) == 2 { // has a decimal place lenDecs = len(strs[1]) if lenDecs == 0 || len(combinedStr) == 0 { - return &Dec{}, ErrInvalidDecimalLength + return Dec{}, ErrInvalidDecimalLength } combinedStr += strs[1] } else if len(strs) > 2 { - return &Dec{}, ErrInvalidDecimalStr + return Dec{}, ErrInvalidDecimalStr } if lenDecs > Precision { - return &Dec{}, fmt.Errorf("invalid precision; max: %d, got: %d", Precision, lenDecs) + return Dec{}, fmt.Errorf("invalid precision; max: %d, got: %d", Precision, lenDecs) } // add some extra zero's to correct to the Precision factor @@ -180,17 +180,17 @@ func NewDecFromStr(str string) (*Dec, error) { combined, ok := new(big.Int).SetString(combinedStr, 10) // base 10 if !ok { - return &Dec{}, fmt.Errorf("failed to set decimal string: %s", combinedStr) + return Dec{}, fmt.Errorf("failed to set decimal string: %s", combinedStr) } if neg { combined = new(big.Int).Neg(combined) } - return &Dec{combined}, nil + return Dec{combined}, nil } // Decimal from string, panic on error -func MustNewDecFromStr(s string) *Dec { +func MustNewDecFromStr(s string) Dec { dec, err := NewDecFromStr(s) if err != nil { panic(err) @@ -200,20 +200,20 @@ func MustNewDecFromStr(s string) *Dec { // ______________________________________________________________________________________________ // nolint -func (d *Dec) IsNil() bool { return d.i == nil } // is decimal nil -func (d *Dec) IsZero() bool { return (d.i).Sign() == 0 } // is equal to zero -func (d *Dec) IsNegative() bool { return (d.i).Sign() == -1 } // is negative -func (d *Dec) IsPositive() bool { return (d.i).Sign() == 1 } // is positive -func (d *Dec) Equal(d2 *Dec) bool { return (d.i).Cmp(d2.i) == 0 } // equal decimals -func (d *Dec) GT(d2 *Dec) bool { return (d.i).Cmp(d2.i) > 0 } // greater than -func (d *Dec) GTE(d2 *Dec) bool { return (d.i).Cmp(d2.i) >= 0 } // greater than or equal -func (d *Dec) LT(d2 *Dec) bool { return (d.i).Cmp(d2.i) < 0 } // less than -func (d *Dec) LTE(d2 *Dec) bool { return (d.i).Cmp(d2.i) <= 0 } // less than or equal -func (d *Dec) Neg() *Dec { return &Dec{new(big.Int).Neg(d.i)} } // reverse the decimal sign -func (d *Dec) Abs() *Dec { return &Dec{new(big.Int).Abs(d.i)} } // absolute value +func (d Dec) IsNil() bool { return d.i == nil } // is decimal nil +func (d Dec) IsZero() bool { return (d.i).Sign() == 0 } // is equal to zero +func (d Dec) IsNegative() bool { return (d.i).Sign() == -1 } // is negative +func (d Dec) IsPositive() bool { return (d.i).Sign() == 1 } // is positive +func (d Dec) Equal(d2 Dec) bool { return (d.i).Cmp(d2.i) == 0 } // equal decimals +func (d Dec) GT(d2 Dec) bool { return (d.i).Cmp(d2.i) > 0 } // greater than +func (d Dec) GTE(d2 Dec) bool { return (d.i).Cmp(d2.i) >= 0 } // greater than or equal +func (d Dec) LT(d2 Dec) bool { return (d.i).Cmp(d2.i) < 0 } // less than +func (d Dec) LTE(d2 Dec) bool { return (d.i).Cmp(d2.i) <= 0 } // less than or equal +func (d Dec) Neg() Dec { return Dec{new(big.Int).Neg(d.i)} } // reverse the decimal sign +func (d Dec) Abs() Dec { return Dec{new(big.Int).Abs(d.i)} } // absolute value // BigInt returns a copy of the underlying big.Int. -func (d *Dec) BigInt() *big.Int { +func (d Dec) BigInt() *big.Int { if d.IsNil() { return nil } @@ -223,69 +223,69 @@ func (d *Dec) BigInt() *big.Int { } // addition -func (d *Dec) Add(d2 *Dec) *Dec { +func (d Dec) Add(d2 Dec) Dec { res := new(big.Int).Add(d.i, d2.i) if res.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{res} + return Dec{res} } // subtraction -func (d *Dec) Sub(d2 *Dec) *Dec { +func (d Dec) Sub(d2 Dec) Dec { res := new(big.Int).Sub(d.i, d2.i) if res.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{res} + return Dec{res} } // multiplication -func (d *Dec) Mul(d2 *Dec) *Dec { +func (d Dec) Mul(d2 Dec) Dec { mul := new(big.Int).Mul(d.i, d2.i) chopped := chopPrecisionAndRound(mul) if chopped.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{chopped} + return Dec{chopped} } // multiplication truncate -func (d *Dec) MulTruncate(d2 *Dec) *Dec { +func (d Dec) MulTruncate(d2 Dec) Dec { mul := new(big.Int).Mul(d.i, d2.i) chopped := chopPrecisionAndTruncate(mul) if chopped.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{chopped} + return Dec{chopped} } // multiplication -func (d *Dec) MulInt(i *Int) *Dec { +func (d Dec) MulInt(i Int) Dec { mul := new(big.Int).Mul(d.i, i.i) if mul.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{mul} + return Dec{mul} } // MulInt64 - multiplication with int64 -func (d *Dec) MulInt64(i int64) *Dec { +func (d Dec) MulInt64(i int64) Dec { mul := new(big.Int).Mul(d.i, big.NewInt(i)) if mul.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{mul} + return Dec{mul} } // quotient -func (d *Dec) Quo(d2 *Dec) *Dec { +func (d Dec) Quo(d2 Dec) Dec { // multiply precision twice mul := new(big.Int).Mul(d.i, precisionReuse) mul.Mul(mul, precisionReuse) @@ -296,11 +296,11 @@ func (d *Dec) Quo(d2 *Dec) *Dec { if chopped.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{chopped} + return Dec{chopped} } // quotient truncate -func (d *Dec) QuoTruncate(d2 *Dec) *Dec { +func (d Dec) QuoTruncate(d2 Dec) Dec { // multiply precision twice mul := new(big.Int).Mul(d.i, precisionReuse) mul.Mul(mul, precisionReuse) @@ -311,11 +311,11 @@ func (d *Dec) QuoTruncate(d2 *Dec) *Dec { if chopped.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{chopped} + return Dec{chopped} } // quotient, round up -func (d *Dec) QuoRoundUp(d2 *Dec) *Dec { +func (d Dec) QuoRoundUp(d2 Dec) Dec { // multiply precision twice mul := new(big.Int).Mul(d.i, precisionReuse) mul.Mul(mul, precisionReuse) @@ -326,19 +326,19 @@ func (d *Dec) QuoRoundUp(d2 *Dec) *Dec { if chopped.BitLen() > 255+DecimalPrecisionBits { panic("Int overflow") } - return &Dec{chopped} + return Dec{chopped} } // quotient -func (d *Dec) QuoInt(i *Int) *Dec { +func (d Dec) QuoInt(i Int) Dec { mul := new(big.Int).Quo(d.i, i.i) - return &Dec{mul} + return Dec{mul} } // QuoInt64 - quotient with int64 -func (d *Dec) QuoInt64(i int64) *Dec { +func (d Dec) QuoInt64(i int64) Dec { mul := new(big.Int).Quo(d.i, big.NewInt(i)) - return &Dec{mul} + return Dec{mul} } // ApproxRoot returns an approximate estimation of a Dec's positive real nth root @@ -347,7 +347,7 @@ func (d *Dec) QuoInt64(i int64) *Dec { // approximate answer. It returns `|d|.ApproxRoot() * -1` if input is negative. // A maximum number of 100 iterations is used a backup boundary condition for // cases where the answer never converges enough to satisfy the main condition. -func (d *Dec) ApproxRoot(root uint64) (guess *Dec, err error) { +func (d Dec) ApproxRoot(root uint64) (guess Dec, err error) { defer func() { if r := recover(); r != nil { var ok bool @@ -390,7 +390,7 @@ func (d *Dec) ApproxRoot(root uint64) (guess *Dec, err error) { } // Power returns a the result of raising to a positive integer power -func (d *Dec) Power(power uint64) *Dec { +func (d Dec) Power(power uint64) Dec { if power == 0 { return OneDec() } @@ -411,24 +411,24 @@ func (d *Dec) Power(power uint64) *Dec { // ApproxSqrt is a wrapper around ApproxRoot for the common special case // of finding the square root of a number. It returns -(sqrt(abs(d)) if input is negative. -func (d *Dec) ApproxSqrt() (*Dec, error) { +func (d Dec) ApproxSqrt() (Dec, error) { return d.ApproxRoot(2) } // is integer, e.g. decimals are zero -func (d *Dec) IsInteger() bool { +func (d Dec) IsInteger() bool { return new(big.Int).Rem(d.i, precisionReuse).Sign() == 0 } // format decimal state -func (d *Dec) Format(s fmt.State, verb rune) { +func (d Dec) Format(s fmt.State, verb rune) { _, err := s.Write([]byte(d.String())) if err != nil { panic(err) } } -func (d *Dec) String() string { +func (d Dec) String() string { if d.i == nil { return d.i.String() } @@ -553,7 +553,7 @@ func chopPrecisionAndRoundNonMutative(d *big.Int) *big.Int { } // RoundInt64 rounds the decimal using bankers rounding -func (d *Dec) RoundInt64() int64 { +func (d Dec) RoundInt64() int64 { chopped := chopPrecisionAndRoundNonMutative(d.i) if !chopped.IsInt64() { panic("Int64() out of bound") @@ -562,8 +562,8 @@ func (d *Dec) RoundInt64() int64 { } // RoundInt round the decimal using bankers rounding -func (d *Dec) RoundInt() Int { - return *NewIntFromBigInt(chopPrecisionAndRoundNonMutative(d.i)) +func (d Dec) RoundInt() Int { + return NewIntFromBigInt(chopPrecisionAndRoundNonMutative(d.i)) } //___________________________________________________________________________________ @@ -579,7 +579,7 @@ func chopPrecisionAndTruncateNonMutative(d *big.Int) *big.Int { } // TruncateInt64 truncates the decimals from the number and returns an int64 -func (d *Dec) TruncateInt64() int64 { +func (d Dec) TruncateInt64() int64 { chopped := chopPrecisionAndTruncateNonMutative(d.i) if !chopped.IsInt64() { panic("Int64() out of bound") @@ -588,18 +588,18 @@ func (d *Dec) TruncateInt64() int64 { } // TruncateInt truncates the decimals from the number and returns an Int -func (d *Dec) TruncateInt() *Int { +func (d Dec) TruncateInt() Int { return NewIntFromBigInt(chopPrecisionAndTruncateNonMutative(d.i)) } // TruncateDec truncates the decimals from the number and returns a Dec -func (d *Dec) TruncateDec() *Dec { +func (d Dec) TruncateDec() Dec { return NewDecFromBigInt(chopPrecisionAndTruncateNonMutative(d.i)) } // Ceil returns the smallest interger value (as a decimal) that is greater than // or equal to the given decimal. -func (d *Dec) Ceil() *Dec { +func (d Dec) Ceil() Dec { tmp := new(big.Int).Set(d.i) quo, rem := tmp, big.NewInt(0) @@ -633,8 +633,8 @@ func ValidSortableDec(dec Dec) bool { // SortableDecBytes returns a byte slice representation of a Dec that can be sorted. // Left and right pads with 0s so there are 18 digits to left and right of the decimal point. // For this reason, there is a maximum and minimum value for this, enforced by ValidSortableDec. -func SortableDecBytes(dec *Dec) []byte { - if !ValidSortableDec(*dec) { +func SortableDecBytes(dec Dec) []byte { + if !ValidSortableDec(dec) { panic("dec must be within bounds") } // Instead of adding an extra byte to all sortable decs in order to handle max sortable, we just @@ -669,7 +669,7 @@ func init() { } // MarshalJSON marshals the decimal -func (d *Dec) MarshalJSON() ([]byte, error) { +func (d Dec) MarshalJSON() ([]byte, error) { if d.i == nil { return nilJSON, nil } @@ -699,12 +699,12 @@ func (d *Dec) UnmarshalJSON(bz []byte) error { } // MarshalYAML returns the YAML representation. -func (d *Dec) MarshalYAML() (interface{}, error) { +func (d Dec) MarshalYAML() (interface{}, error) { return d.String(), nil } //// Marshal implements the gogo proto custom type interface. -//func (d *Dec) Marshal() ([]byte, error) { +//func (d Dec) Marshal() ([]byte, error) { // if d.i == nil { // d.i = new(big.Int) // } @@ -760,7 +760,7 @@ func (d *Dec) MarshalYAML() (interface{}, error) { //} //// Override Amino binary serialization by proxying to protobuf. -//func (d *Dec) MarshalAmino() ([]byte, error) { return d.Marshal() } +//func (d Dec) MarshalAmino() ([]byte, error) { return d.Marshal() } //func (d *Dec) UnmarshalAmino(bz []byte) error { return d.Unmarshal(bz) } //func (dp DecProto) String() string { @@ -777,7 +777,7 @@ func DecsEqual(d1s, d2s []Dec) bool { } for i, d1 := range d1s { - if !d1.Equal(&d2s[i]) { + if !d1.Equal(d2s[i]) { return false } } @@ -785,7 +785,7 @@ func DecsEqual(d1s, d2s []Dec) bool { } // minimum decimal between two -func MinDec(d1, d2 *Dec) *Dec { +func MinDec(d1, d2 Dec) Dec { if d1.LT(d2) { return d1 } @@ -793,7 +793,7 @@ func MinDec(d1, d2 *Dec) *Dec { } // maximum decimal between two -func MaxDec(d1, d2 *Dec) *Dec { +func MaxDec(d1, d2 Dec) Dec { if d1.LT(d2) { return d2 } @@ -801,6 +801,6 @@ func MaxDec(d1, d2 *Dec) *Dec { } // intended to be used with require/assert: require.True(DecEq(...)) -func DecEq(t *testing.T, exp, got *Dec) (*testing.T, bool, string, string, string) { +func DecEq(t *testing.T, exp, got Dec) (*testing.T, bool, string, string, string) { return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } diff --git a/usecase/coin/decimal_test.go b/usecase/coin/decimal_test.go index 3939994eb..bc0f2efdb 100644 --- a/usecase/coin/decimal_test.go +++ b/usecase/coin/decimal_test.go @@ -20,7 +20,7 @@ func TestDecimalTestSuite(t *testing.T) { } // create a decimal from a decimal string (ex. "1234.5678") -func (s *decimalTestSuite) mustNewDecFromStr(str string) (d *sdk.Dec) { +func (s *decimalTestSuite) mustNewDecFromStr(str string) (d sdk.Dec) { d, err := sdk.NewDecFromStr(str) s.Require().NoError(err) @@ -36,10 +36,10 @@ func (s *decimalTestSuite) TestNewDecFromStr() { tests := []struct { decimalStr string expErr bool - exp *sdk.Dec + exp sdk.Dec }{ - {"", true, &sdk.Dec{}}, - {"0.-75", true, &sdk.Dec{}}, + {"", true, sdk.Dec{}}, + {"0.-75", true, sdk.Dec{}}, {"0", false, sdk.NewDec(0)}, {"1", false, sdk.NewDec(1)}, {"1.1", false, sdk.NewDecWithPrec(11, 1)}, @@ -51,29 +51,29 @@ func (s *decimalTestSuite) TestNewDecFromStr() { true, sdk.NewDecFromBigIntWithPrec(largeBigInt, 4)}, {"314460551102969314427823434337.1835", false, sdk.NewDecFromBigIntWithPrec(largeBigInt, 4)}, - {".", true, &sdk.Dec{}}, + {".", true, sdk.Dec{}}, {".0", true, sdk.NewDec(0)}, {"1.", true, sdk.NewDec(1)}, - {"foobar", true, &sdk.Dec{}}, - {"0.foobar", true, &sdk.Dec{}}, - {"0.foobar.", true, &sdk.Dec{}}, + {"foobar", true, sdk.Dec{}}, + {"0.foobar", true, sdk.Dec{}}, + {"0.foobar.", true, sdk.Dec{}}, } for tcIndex, tc := range tests { res, err := sdk.NewDecFromStr(tc.decimalStr) if tc.expErr { - s.Require().Error(err, "error expected, decimalStr %v, tc %v", tc.decimalStr, tcIndex) + s.Require().NotNil(err, "error expected, decimalStr %v, tc %v", tc.decimalStr, tcIndex) } else { - s.Require().NoError(err, "unexpected error, decimalStr %v, tc %v", tc.decimalStr, tcIndex) + s.Require().Nil(err, "unexpected error, decimalStr %v, tc %v", tc.decimalStr, tcIndex) s.Require().True(res.Equal(tc.exp), "equality was incorrect, res %v, exp %v, tc %v", res, tc.exp, tcIndex) } // negative tc res, err = sdk.NewDecFromStr("-" + tc.decimalStr) if tc.expErr { - s.Require().Error(err, "error expected, decimalStr %v, tc %v", tc.decimalStr, tcIndex) + s.Require().NotNil(err, "error expected, decimalStr %v, tc %v", tc.decimalStr, tcIndex) } else { - s.Require().NoError(err, "unexpected error, decimalStr %v, tc %v", tc.decimalStr, tcIndex) + s.Require().Nil(err, "unexpected error, decimalStr %v, tc %v", tc.decimalStr, tcIndex) exp := tc.exp.Mul(sdk.NewDec(-1)) s.Require().True(res.Equal(exp), "equality was incorrect, res %v, exp %v, tc %v", res, exp, tcIndex) } @@ -82,7 +82,7 @@ func (s *decimalTestSuite) TestNewDecFromStr() { func (s *decimalTestSuite) TestDecString() { tests := []struct { - d *sdk.Dec + d sdk.Dec want string }{ {sdk.NewDec(0), "0.000000000000000000"}, @@ -101,7 +101,7 @@ func (s *decimalTestSuite) TestDecString() { func (s *decimalTestSuite) TestEqualities() { tests := []struct { - d1, d2 *sdk.Dec + d1, d2 sdk.Dec gt, lt, eq bool }{ {sdk.NewDec(0), sdk.NewDec(0), false, false, true}, @@ -141,15 +141,15 @@ func (s *decimalTestSuite) TestDecsEqual() { d1s, d2s []sdk.Dec eq bool }{ - {[]sdk.Dec{*sdk.NewDec(0)}, []sdk.Dec{*sdk.NewDec(0)}, true}, - {[]sdk.Dec{*sdk.NewDec(0)}, []sdk.Dec{*sdk.NewDec(1)}, false}, - {[]sdk.Dec{*sdk.NewDec(0)}, []sdk.Dec{}, false}, - {[]sdk.Dec{*sdk.NewDec(0), *sdk.NewDec(1)}, []sdk.Dec{*sdk.NewDec(0), *sdk.NewDec(1)}, true}, - {[]sdk.Dec{*sdk.NewDec(1), *sdk.NewDec(0)}, []sdk.Dec{*sdk.NewDec(1), *sdk.NewDec(0)}, true}, - {[]sdk.Dec{*sdk.NewDec(1), *sdk.NewDec(0)}, []sdk.Dec{*sdk.NewDec(0), *sdk.NewDec(1)}, false}, - {[]sdk.Dec{*sdk.NewDec(1), *sdk.NewDec(0)}, []sdk.Dec{*sdk.NewDec(1)}, false}, - {[]sdk.Dec{*sdk.NewDec(1), *sdk.NewDec(2)}, []sdk.Dec{*sdk.NewDec(2), *sdk.NewDec(4)}, false}, - {[]sdk.Dec{*sdk.NewDec(3), *sdk.NewDec(18)}, []sdk.Dec{*sdk.NewDec(1), *sdk.NewDec(6)}, false}, + {[]sdk.Dec{sdk.NewDec(0)}, []sdk.Dec{sdk.NewDec(0)}, true}, + {[]sdk.Dec{sdk.NewDec(0)}, []sdk.Dec{sdk.NewDec(1)}, false}, + {[]sdk.Dec{sdk.NewDec(0)}, []sdk.Dec{}, false}, + {[]sdk.Dec{sdk.NewDec(0), sdk.NewDec(1)}, []sdk.Dec{sdk.NewDec(0), sdk.NewDec(1)}, true}, + {[]sdk.Dec{sdk.NewDec(1), sdk.NewDec(0)}, []sdk.Dec{sdk.NewDec(1), sdk.NewDec(0)}, true}, + {[]sdk.Dec{sdk.NewDec(1), sdk.NewDec(0)}, []sdk.Dec{sdk.NewDec(0), sdk.NewDec(1)}, false}, + {[]sdk.Dec{sdk.NewDec(1), sdk.NewDec(0)}, []sdk.Dec{sdk.NewDec(1)}, false}, + {[]sdk.Dec{sdk.NewDec(1), sdk.NewDec(2)}, []sdk.Dec{sdk.NewDec(2), sdk.NewDec(4)}, false}, + {[]sdk.Dec{sdk.NewDec(3), sdk.NewDec(18)}, []sdk.Dec{sdk.NewDec(1), sdk.NewDec(6)}, false}, } for tcIndex, tc := range tests { @@ -160,10 +160,10 @@ func (s *decimalTestSuite) TestDecsEqual() { func (s *decimalTestSuite) TestArithmetic() { tests := []struct { - d1, d2 *sdk.Dec - expMul, expMulTruncate *sdk.Dec - expQuo, expQuoRoundUp, expQuoTruncate *sdk.Dec - expAdd, expSub *sdk.Dec + d1, d2 sdk.Dec + expMul, expMulTruncate sdk.Dec + expQuo, expQuoRoundUp, expQuoTruncate sdk.Dec + expAdd, expSub sdk.Dec }{ // d1 d2 MUL MulTruncate QUO QUORoundUp QUOTrunctate ADD SUB {sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0)}, @@ -222,7 +222,7 @@ func (s *decimalTestSuite) TestArithmetic() { func (s *decimalTestSuite) TestBankerRoundChop() { tests := []struct { - d1 *sdk.Dec + d1 sdk.Dec exp int64 }{ {s.mustNewDecFromStr("0.25"), 0}, @@ -248,7 +248,7 @@ func (s *decimalTestSuite) TestBankerRoundChop() { func (s *decimalTestSuite) TestTruncate() { tests := []struct { - d1 *sdk.Dec + d1 sdk.Dec exp int64 }{ {s.mustNewDecFromStr("0"), 0}, @@ -287,9 +287,9 @@ func (s *decimalTestSuite) TestStringOverflow() { func (s *decimalTestSuite) TestDecMulInt() { tests := []struct { - sdkDec *sdk.Dec - sdkInt *sdk.Int - want *sdk.Dec + sdkDec sdk.Dec + sdkInt sdk.Int + want sdk.Dec }{ {sdk.NewDec(10), sdk.NewInt(2), sdk.NewDec(20)}, {sdk.NewDec(1000000), sdk.NewInt(100), sdk.NewDec(100000000)}, @@ -304,8 +304,8 @@ func (s *decimalTestSuite) TestDecMulInt() { func (s *decimalTestSuite) TestDecCeil() { testCases := []struct { - input *sdk.Dec - expected *sdk.Dec + input sdk.Dec + expected sdk.Dec }{ {sdk.NewDecWithPrec(1000000000000000, sdk.Precision), sdk.NewDec(1)}, // 0.001 => 1.0 {sdk.NewDecWithPrec(-1000000000000000, sdk.Precision), sdk.ZeroDec()}, // -0.001 => 0.0 @@ -325,16 +325,16 @@ func (s *decimalTestSuite) TestDecCeil() { func (s *decimalTestSuite) TestPower() { testCases := []struct { - input *sdk.Dec + input sdk.Dec power uint64 - expected *sdk.Dec + expected sdk.Dec }{ - {sdk.OneDec(), 10, sdk.OneDec()}, // 1.0 ^ (10) => 1.0 - {sdk.NewDecWithPrec(5, 1), 2, sdk.NewDecWithPrec(25, 2)}, // 0.5 ^ 2 => 0.25 - {sdk.NewDecWithPrec(2, 1), 2, sdk.NewDecWithPrec(4, 2)}, // 0.2 ^ 2 => 0.04 - {sdk.NewDecFromInt(*sdk.NewInt(3)), 3, sdk.NewDecFromInt(*sdk.NewInt(27))}, // 3 ^ 3 => 27 - {sdk.NewDecFromInt(*sdk.NewInt(-3)), 4, sdk.NewDecFromInt(*sdk.NewInt(81))}, // -3 ^ 4 = 81 - {sdk.NewDecWithPrec(1414213562373095049, 18), 2, sdk.NewDecFromInt(*sdk.NewInt(2))}, // 1.414213562373095049 ^ 2 = 2 + {sdk.OneDec(), 10, sdk.OneDec()}, // 1.0 ^ (10) => 1.0 + {sdk.NewDecWithPrec(5, 1), 2, sdk.NewDecWithPrec(25, 2)}, // 0.5 ^ 2 => 0.25 + {sdk.NewDecWithPrec(2, 1), 2, sdk.NewDecWithPrec(4, 2)}, // 0.2 ^ 2 => 0.04 + {sdk.NewDecFromInt(sdk.NewInt(3)), 3, sdk.NewDecFromInt(sdk.NewInt(27))}, // 3 ^ 3 => 27 + {sdk.NewDecFromInt(sdk.NewInt(-3)), 4, sdk.NewDecFromInt(sdk.NewInt(81))}, // -3 ^ 4 = 81 + {sdk.NewDecWithPrec(1414213562373095049, 18), 2, sdk.NewDecFromInt(sdk.NewInt(2))}, // 1.414213562373095049 ^ 2 = 2 } for i, tc := range testCases { @@ -345,16 +345,16 @@ func (s *decimalTestSuite) TestPower() { func (s *decimalTestSuite) TestApproxRoot() { testCases := []struct { - input *sdk.Dec + input sdk.Dec root uint64 - expected *sdk.Dec + expected sdk.Dec }{ {sdk.OneDec(), 10, sdk.OneDec()}, // 1.0 ^ (0.1) => 1.0 {sdk.NewDecWithPrec(25, 2), 2, sdk.NewDecWithPrec(5, 1)}, // 0.25 ^ (0.5) => 0.5 {sdk.NewDecWithPrec(4, 2), 2, sdk.NewDecWithPrec(2, 1)}, // 0.04 ^ (0.5) => 0.2 - {sdk.NewDecFromInt(*sdk.NewInt(27)), 3, sdk.NewDecFromInt(*sdk.NewInt(3))}, // 27 ^ (1/3) => 3 - {sdk.NewDecFromInt(*sdk.NewInt(-81)), 4, sdk.NewDecFromInt(*sdk.NewInt(-3))}, // -81 ^ (0.25) => -3 - {sdk.NewDecFromInt(*sdk.NewInt(2)), 2, sdk.NewDecWithPrec(1414213562373095049, 18)}, // 2 ^ (0.5) => 1.414213562373095049 + {sdk.NewDecFromInt(sdk.NewInt(27)), 3, sdk.NewDecFromInt(sdk.NewInt(3))}, // 27 ^ (1/3) => 3 + {sdk.NewDecFromInt(sdk.NewInt(-81)), 4, sdk.NewDecFromInt(sdk.NewInt(-3))}, // -81 ^ (0.25) => -3 + {sdk.NewDecFromInt(sdk.NewInt(2)), 2, sdk.NewDecWithPrec(1414213562373095049, 18)}, // 2 ^ (0.5) => 1.414213562373095049 {sdk.NewDecWithPrec(1005, 3), 31536000, sdk.MustNewDecFromStr("1.000000000158153904")}, // 1.005 ^ (1/31536000) ≈ 1.00000000016 {sdk.SmallestDec(), 2, sdk.NewDecWithPrec(1, 9)}, // 1e-18 ^ (0.5) => 1e-9 {sdk.SmallestDec(), 3, sdk.MustNewDecFromStr("0.000000999999999997")}, // 1e-18 ^ (1/3) => 1e-6 @@ -374,15 +374,15 @@ func (s *decimalTestSuite) TestApproxRoot() { func (s *decimalTestSuite) TestApproxSqrt() { testCases := []struct { - input *sdk.Dec - expected *sdk.Dec + input sdk.Dec + expected sdk.Dec }{ - {sdk.OneDec(), sdk.OneDec()}, // 1.0 => 1.0 - {sdk.NewDecWithPrec(25, 2), sdk.NewDecWithPrec(5, 1)}, // 0.25 => 0.5 - {sdk.NewDecWithPrec(4, 2), sdk.NewDecWithPrec(2, 1)}, // 0.09 => 0.3 - {sdk.NewDecFromInt(*sdk.NewInt(9)), sdk.NewDecFromInt(*sdk.NewInt(3))}, // 9 => 3 - {sdk.NewDecFromInt(*sdk.NewInt(-9)), sdk.NewDecFromInt(*sdk.NewInt(-3))}, // -9 => -3 - {sdk.NewDecFromInt(*sdk.NewInt(2)), sdk.NewDecWithPrec(1414213562373095049, 18)}, // 2 => 1.414213562373095049 + {sdk.OneDec(), sdk.OneDec()}, // 1.0 => 1.0 + {sdk.NewDecWithPrec(25, 2), sdk.NewDecWithPrec(5, 1)}, // 0.25 => 0.5 + {sdk.NewDecWithPrec(4, 2), sdk.NewDecWithPrec(2, 1)}, // 0.09 => 0.3 + {sdk.NewDecFromInt(sdk.NewInt(9)), sdk.NewDecFromInt(sdk.NewInt(3))}, // 9 => 3 + {sdk.NewDecFromInt(sdk.NewInt(-9)), sdk.NewDecFromInt(sdk.NewInt(-3))}, // -9 => -3 + {sdk.NewDecFromInt(sdk.NewInt(2)), sdk.NewDecWithPrec(1414213562373095049, 18)}, // 2 => 1.414213562373095049 } for i, tc := range testCases { @@ -394,7 +394,7 @@ func (s *decimalTestSuite) TestApproxSqrt() { func (s *decimalTestSuite) TestDecSortableBytes() { tests := []struct { - d *sdk.Dec + d sdk.Dec want []byte }{ {sdk.NewDec(0), []byte("000000000000000000.000000000000000000")}, @@ -419,7 +419,7 @@ func (s *decimalTestSuite) TestDecSortableBytes() { func (s *decimalTestSuite) TestDecEncoding() { testCases := []struct { - input *sdk.Dec + input sdk.Dec rawBz string jsonStr string yamlStr string @@ -466,7 +466,7 @@ func (s *decimalTestSuite) TestDecEncoding() { var bz []byte var err error - var other *sdk.Dec + var other sdk.Dec bz, err = json.Marshal(tc.input) s.Require().NoError(err) s.Require().Equal(tc.jsonStr, string(bz)) diff --git a/usecase/coin/denom.go b/usecase/coin/denom.go index 8079a2385..cf640b13e 100644 --- a/usecase/coin/denom.go +++ b/usecase/coin/denom.go @@ -23,8 +23,8 @@ func RegisterDenom(denom string, unit Dec) error { } denomUnits[denom] = unit - baseDenomUnit := denomUnits[baseDenom] - if baseDenom == "" || unit.LT(&baseDenomUnit) { + + if baseDenom == "" || unit.LT(denomUnits[baseDenom]) { baseDenom = denom } return nil @@ -32,7 +32,7 @@ func RegisterDenom(denom string, unit Dec) error { // GetDenomUnit returns a unit for a given denomination if it exists. A boolean // is returned if the denomination is registered. -func GetDenomUnit(denom string) (*Dec, bool) { +func GetDenomUnit(denom string) (Dec, bool) { if err := ValidateDenom(denom); err != nil { return ZeroDec(), false } @@ -42,7 +42,7 @@ func GetDenomUnit(denom string) (*Dec, bool) { return ZeroDec(), false } - return &unit, true + return unit, true } // GetBaseDenom returns the denom of smallest unit registered @@ -56,26 +56,26 @@ func GetBaseDenom() (string, error) { // ConvertCoin attempts to convert a coin to a given denomination. If the given // denomination is invalid or if neither denomination is registered, an error // is returned. -func ConvertCoin(coin Coin, denom string) (*Coin, error) { +func ConvertCoin(coin Coin, denom string) (Coin, error) { if err := ValidateDenom(denom); err != nil { - return &Coin{}, err + return Coin{}, err } srcUnit, ok := GetDenomUnit(coin.Denom) if !ok { - return &Coin{}, fmt.Errorf("source denom not registered: %s", coin.Denom) + return Coin{}, fmt.Errorf("source denom not registered: %s", coin.Denom) } dstUnit, ok := GetDenomUnit(denom) if !ok { - return &Coin{}, fmt.Errorf("destination denom not registered: %s", denom) + return Coin{}, fmt.Errorf("destination denom not registered: %s", denom) } if srcUnit.Equal(dstUnit) { return NewCoin(denom, coin.Amount) } - return NewCoin(denom, *coin.Amount.ToDec().Mul(srcUnit).Quo(dstUnit).TruncateInt()) + return NewCoin(denom, coin.Amount.ToDec().Mul(srcUnit).Quo(dstUnit).TruncateInt()) } // ConvertDecCoin attempts to convert a decimal coin to a given denomination. If the given @@ -100,17 +100,17 @@ func ConvertDecCoin(coin DecCoin, denom string) (DecCoin, error) { return NewDecCoinFromDec(denom, coin.Amount), nil } - return NewDecCoinFromDec(denom, *coin.Amount.Mul(srcUnit).Quo(dstUnit)), nil + return NewDecCoinFromDec(denom, coin.Amount.Mul(srcUnit).Quo(dstUnit)), nil } // NormalizeCoin try to convert a coin to the smallest unit registered, // returns original one if failed. -func NormalizeCoin(coin *Coin) *Coin { +func NormalizeCoin(coin Coin) Coin { base, err := GetBaseDenom() if err != nil { return coin } - newCoin, err := ConvertCoin(*coin, base) + newCoin, err := ConvertCoin(coin, base) if err != nil { return coin } diff --git a/usecase/coin/int.go b/usecase/coin/int.go index df7978c2b..024d43d6f 100644 --- a/usecase/coin/int.go +++ b/usecase/coin/int.go @@ -73,7 +73,7 @@ type Int struct { } // BigInt converts Int to big.Int -func (i *Int) BigInt() *big.Int { +func (i Int) BigInt() *big.Int { if i.IsNil() { return nil } @@ -81,28 +81,28 @@ func (i *Int) BigInt() *big.Int { } // IsNil returns true if Int is uninitialized -func (i *Int) IsNil() bool { +func (i Int) IsNil() bool { return i.i == nil } // NewInt constructs Int from int64 -func NewInt(n int64) *Int { - return &Int{big.NewInt(n)} +func NewInt(n int64) Int { + return Int{big.NewInt(n)} } // NewIntFromUint64 constructs an Int from a uint64. -func NewIntFromUint64(n uint64) *Int { +func NewIntFromUint64(n uint64) Int { b := big.NewInt(0) b.SetUint64(n) - return &Int{b} + return Int{b} } // NewIntFromBigInt constructs Int from big.Int -func NewIntFromBigInt(i *big.Int) *Int { +func NewIntFromBigInt(i *big.Int) Int { if i.BitLen() > maxBitLen { panic("NewIntFromBigInt() out of bound") } - return &Int{i} + return Int{i} } // NewIntFromString constructs Int from string @@ -121,7 +121,7 @@ func NewIntFromString(s string) (res Int, ok bool) { // NewIntWithDecimal constructs Int with decimal // Result value is n*10^dec -func NewIntWithDecimal(n int64, dec int) *Int { +func NewIntWithDecimal(n int64, dec int) Int { if dec < 0 { panic("NewIntWithDecimal() decimal is negative") } @@ -133,23 +133,23 @@ func NewIntWithDecimal(n int64, dec int) *Int { if i.BitLen() > maxBitLen { panic("NewIntWithDecimal() out of bound") } - return &Int{i} + return Int{i} } // ZeroInt returns Int value with zero -func ZeroInt() *Int { return &Int{big.NewInt(0)} } +func ZeroInt() Int { return Int{big.NewInt(0)} } // OneInt returns Int value with one -func OneInt() *Int { return &Int{big.NewInt(1)} } +func OneInt() Int { return Int{big.NewInt(1)} } // ToDec converts Int to Dec -func (i *Int) ToDec() *Dec { - return NewDecFromInt(*i) +func (i Int) ToDec() Dec { + return NewDecFromInt(i) } // Int64 converts Int to int64 // Panics if the value is out of range -func (i *Int) Int64() int64 { +func (i Int) Int64() int64 { if !i.i.IsInt64() { panic("Int64() out of bound") } @@ -157,13 +157,13 @@ func (i *Int) Int64() int64 { } // IsInt64 returns true if Int64() not panics -func (i *Int) IsInt64() bool { +func (i Int) IsInt64() bool { return i.i.IsInt64() } // Uint64 converts Int to uint64 // Panics if the value is out of range -func (i *Int) Uint64() uint64 { +func (i Int) Uint64() uint64 { if !i.i.IsUint64() { panic("Uint64() out of bounds") } @@ -171,59 +171,59 @@ func (i *Int) Uint64() uint64 { } // IsUint64 returns true if Uint64() not panics -func (i *Int) IsUint64() bool { +func (i Int) IsUint64() bool { return i.i.IsUint64() } // IsZero returns true if Int is zero -func (i *Int) IsZero() bool { +func (i Int) IsZero() bool { return i.i.Sign() == 0 } // IsNegative returns true if Int is negative -func (i *Int) IsNegative() bool { +func (i Int) IsNegative() bool { return i.i.Sign() == -1 } // IsPositive returns true if Int is positive -func (i *Int) IsPositive() bool { +func (i Int) IsPositive() bool { return i.i.Sign() == 1 } // Sign returns sign of Int -func (i *Int) Sign() int { +func (i Int) Sign() int { return i.i.Sign() } // Equal compares two Ints -func (i *Int) Equal(i2 *Int) bool { +func (i Int) Equal(i2 Int) bool { return equal(i.i, i2.i) } // GT returns true if first Int is greater than second -func (i *Int) GT(i2 *Int) bool { +func (i Int) GT(i2 Int) bool { return gt(i.i, i2.i) } // GTE returns true if receiver Int is greater than or equal to the parameter // Int. -func (i *Int) GTE(i2 *Int) bool { +func (i Int) GTE(i2 Int) bool { return gte(i.i, i2.i) } // LT returns true if first Int is lesser than second -func (i *Int) LT(i2 *Int) bool { +func (i Int) LT(i2 Int) bool { return lt(i.i, i2.i) } // LTE returns true if first Int is less than or equal to second -func (i *Int) LTE(i2 *Int) bool { +func (i Int) LTE(i2 Int) bool { return lte(i.i, i2.i) } // Add adds Int from another -func (i *Int) Add(i2 *Int) (res *Int) { - res = &Int{add(i.i, i2.i)} +func (i Int) Add(i2 Int) (res Int) { + res = Int{add(i.i, i2.i)} // Check overflow if res.i.BitLen() > maxBitLen { panic("Int overflow") @@ -232,13 +232,13 @@ func (i *Int) Add(i2 *Int) (res *Int) { } // AddRaw adds int64 to Int -func (i *Int) AddRaw(i2 int64) *Int { +func (i Int) AddRaw(i2 int64) Int { return i.Add(NewInt(i2)) } // Sub subtracts Int from another -func (i *Int) Sub(i2 *Int) (res *Int) { - res = &Int{sub(i.i, i2.i)} +func (i Int) Sub(i2 Int) (res Int) { + res = Int{sub(i.i, i2.i)} // Check overflow if res.i.BitLen() > maxBitLen { panic("Int overflow") @@ -247,17 +247,17 @@ func (i *Int) Sub(i2 *Int) (res *Int) { } // SubRaw subtracts int64 from Int -func (i *Int) SubRaw(i2 int64) *Int { +func (i Int) SubRaw(i2 int64) Int { return i.Sub(NewInt(i2)) } // Mul multiples two Ints -func (i *Int) Mul(i2 *Int) (res *Int) { +func (i Int) Mul(i2 Int) (res Int) { // Check overflow if i.i.BitLen()+i2.i.BitLen()-1 > maxBitLen { panic("Int overflow") } - res = &Int{mul(i.i, i2.i)} + res = Int{mul(i.i, i2.i)} // Check overflow if sign of both are same if res.i.BitLen() > maxBitLen { panic("Int overflow") @@ -266,59 +266,59 @@ func (i *Int) Mul(i2 *Int) (res *Int) { } // MulRaw multipies Int and int64 -func (i *Int) MulRaw(i2 int64) *Int { +func (i Int) MulRaw(i2 int64) Int { return i.Mul(NewInt(i2)) } // Quo divides Int with Int -func (i *Int) Quo(i2 *Int) (res *Int) { +func (i Int) Quo(i2 Int) (res Int) { // Check division-by-zero if i2.i.Sign() == 0 { panic("Division by zero") } - return &Int{div(i.i, i2.i)} + return Int{div(i.i, i2.i)} } // QuoRaw divides Int with int64 -func (i *Int) QuoRaw(i2 int64) *Int { +func (i Int) QuoRaw(i2 int64) Int { return i.Quo(NewInt(i2)) } // Mod returns remainder after dividing with Int -func (i *Int) Mod(i2 *Int) *Int { +func (i Int) Mod(i2 Int) Int { if i2.Sign() == 0 { panic("division-by-zero") } - return &Int{mod(i.i, i2.i)} + return Int{mod(i.i, i2.i)} } // ModRaw returns remainder after dividing with int64 -func (i *Int) ModRaw(i2 int64) *Int { +func (i Int) ModRaw(i2 int64) Int { return i.Mod(NewInt(i2)) } // Neg negates Int -func (i *Int) Neg() (res *Int) { - return &Int{neg(i.i)} +func (i Int) Neg() (res Int) { + return Int{neg(i.i)} } // return the minimum of the ints -func MinInt(i1, i2 *Int) *Int { - return &Int{min(i1.BigInt(), i2.BigInt())} +func MinInt(i1, i2 Int) Int { + return Int{min(i1.BigInt(), i2.BigInt())} } // MaxInt returns the maximum between two integers. -func MaxInt(i, i2 *Int) *Int { - return &Int{max(i.BigInt(), i2.BigInt())} +func MaxInt(i, i2 Int) Int { + return Int{max(i.BigInt(), i2.BigInt())} } // Human readable string -func (i *Int) String() string { +func (i Int) String() string { return i.i.String() } // MarshalJSON defines custom encoding scheme -func (i *Int) MarshalJSON() ([]byte, error) { +func (i Int) MarshalJSON() ([]byte, error) { if i.i == nil { // Necessary since default Uint initialization has i.i as nil i.i = new(big.Int) } @@ -356,12 +356,12 @@ func unmarshalJSON(i *big.Int, bz []byte) error { } // MarshalYAML returns the YAML representation. -func (i *Int) MarshalYAML() (interface{}, error) { +func (i Int) MarshalYAML() (interface{}, error) { return i.String(), nil } //// Marshal implements the gogo proto custom type interface. -//func (i *Int) Marshal() ([]byte, error) { +//func (i Int) Marshal() ([]byte, error) { // if i.i == nil { // i.i = new(big.Int) // } @@ -416,11 +416,11 @@ func (i *Int) MarshalYAML() (interface{}, error) { //} //// Override Amino binary serialization by proxying to protobuf. -//func (i *Int) MarshalAmino() ([]byte, error) { return i.Marshal() } +//func (i Int) MarshalAmino() ([]byte, error) { return i.Marshal() } //func (i *Int) UnmarshalAmino(bz []byte) error { return i.Unmarshal(bz) } // intended to be used with require/assert: require.True(IntEq(...)) -func IntEq(t *testing.T, exp, got *Int) (*testing.T, bool, string, string, string) { +func IntEq(t *testing.T, exp, got Int) (*testing.T, bool, string, string, string) { return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String() } diff --git a/usecase/coin/int_test.go b/usecase/coin/int_test.go index 82e95059b..106d97c55 100644 --- a/usecase/coin/int_test.go +++ b/usecase/coin/int_test.go @@ -27,17 +27,15 @@ func (s *intTestSuite) SetupSuite() { func (s *intTestSuite) TestFromInt64() { for n := 0; n < 20; n++ { r := rand.Int63() - i := sdk.NewInt(r) - s.Require().Equal(r, i.Int64()) + s.Require().Equal(r, sdk.NewInt(r).Int64()) } } func (s *intTestSuite) TestFromUint64() { for n := 0; n < 20; n++ { r := rand.Uint64() - i := sdk.NewIntFromUint64(r) - s.Require().True(i.IsUint64()) - s.Require().Equal(r, i.Uint64()) + s.Require().True(sdk.NewIntFromUint64(r).IsUint64()) + s.Require().Equal(r, sdk.NewIntFromUint64(r).Uint64()) } } @@ -96,7 +94,7 @@ func (s *intTestSuite) TestIntPanic() { // Division-by-zero check s.Require().Panics(func() { i1.Quo(sdk.NewInt(0)) }) - s.Require().NotPanics(func() { (&sdk.Int{}).BigInt() }) + s.Require().NotPanics(func() { sdk.Int{}.BigInt() }) } // Tests below uses randomness @@ -147,7 +145,7 @@ func (s *intTestSuite) TestArithInt() { i2 := sdk.NewInt(n2) cases := []struct { - ires *sdk.Int + ires sdk.Int nres int64 }{ {i1.Add(i2), n1 + n2}, @@ -193,7 +191,7 @@ func (s *intTestSuite) TestCompInt() { } } -func randint() *sdk.Int { +func randint() sdk.Int { return sdk.NewInt(rand.Int63()) } @@ -221,7 +219,7 @@ func (s *intTestSuite) TestImmutabilityAllInt() { ni := sdk.NewInt(n) for opnum, op := range ops { - op(ni) + op(&ni) s.Require().Equal(n, ni.Int64(), "Int is modified by operation. tc #%d", opnum) s.Require().Equal(sdk.NewInt(n), ni, "Int is modified by operation. tc #%d", opnum) @@ -238,47 +236,47 @@ func (s *intTestSuite) TestEncodingTableInt() { rawBz []byte }{ { - *sdk.NewInt(0), + sdk.NewInt(0), []byte("\"0\""), []byte{0x30}, }, { - *sdk.NewInt(100), + sdk.NewInt(100), []byte("\"100\""), []byte{0x31, 0x30, 0x30}, }, { - *sdk.NewInt(-100), + sdk.NewInt(-100), []byte("\"-100\""), []byte{0x2d, 0x31, 0x30, 0x30}, }, { - *sdk.NewInt(51842), + sdk.NewInt(51842), []byte("\"51842\""), []byte{0x35, 0x31, 0x38, 0x34, 0x32}, }, { - *sdk.NewInt(-51842), + sdk.NewInt(-51842), []byte("\"-51842\""), []byte{0x2d, 0x35, 0x31, 0x38, 0x34, 0x32}, }, { - *sdk.NewInt(19513368), + sdk.NewInt(19513368), []byte("\"19513368\""), []byte{0x31, 0x39, 0x35, 0x31, 0x33, 0x33, 0x36, 0x38}, }, { - *sdk.NewInt(-19513368), + sdk.NewInt(-19513368), []byte("\"-19513368\""), []byte{0x2d, 0x31, 0x39, 0x35, 0x31, 0x33, 0x33, 0x36, 0x38}, }, { - *sdk.NewInt(999999999999), + sdk.NewInt(999999999999), []byte("\"999999999999\""), []byte{0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39}, }, { - *sdk.NewInt(-999999999999), + sdk.NewInt(-999999999999), []byte("\"-999999999999\""), []byte{0x2d, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39}, }, @@ -286,11 +284,11 @@ func (s *intTestSuite) TestEncodingTableInt() { for tcnum, tc := range cases { bz, err := tc.i.MarshalJSON() - s.Require().NoError(err, "Error marshaling Int. tc #%d, err %s", tcnum, err) + s.Require().Nil(err, "Error marshaling Int. tc #%d, err %s", tcnum, err) s.Require().Equal(tc.jsonBz, bz, "Marshaled value is different from exported. tc #%d", tcnum) err = (&i).UnmarshalJSON(bz) - s.Require().NoError(err, "Error unmarshaling Int. tc #%d, err %s", tcnum, err) + s.Require().Nil(err, "Error unmarshaling Int. tc #%d, err %s", tcnum, err) s.Require().Equal(tc.i, i, "Unmarshaled value is different from exported. tc #%d", tcnum) //bz, err = tc.i.Marshal() @@ -312,27 +310,27 @@ func (s *intTestSuite) TestEncodingTableUint() { rawBz []byte }{ { - *sdk.NewUint(0), + sdk.NewUint(0), []byte("\"0\""), []byte{0x30}, }, { - *sdk.NewUint(100), + sdk.NewUint(100), []byte("\"100\""), []byte{0x31, 0x30, 0x30}, }, { - *sdk.NewUint(51842), + sdk.NewUint(51842), []byte("\"51842\""), []byte{0x35, 0x31, 0x38, 0x34, 0x32}, }, { - *sdk.NewUint(19513368), + sdk.NewUint(19513368), []byte("\"19513368\""), []byte{0x31, 0x39, 0x35, 0x31, 0x33, 0x33, 0x36, 0x38}, }, { - *sdk.NewUint(999999999999), + sdk.NewUint(999999999999), []byte("\"999999999999\""), []byte{0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39}, }, @@ -340,11 +338,11 @@ func (s *intTestSuite) TestEncodingTableUint() { for tcnum, tc := range cases { bz, err := tc.i.MarshalJSON() - s.Require().NoError(err, "Error marshaling Int. tc #%d, err %s", tcnum, err) + s.Require().Nil(err, "Error marshaling Int. tc #%d, err %s", tcnum, err) s.Require().Equal(tc.jsonBz, bz, "Marshaled value is different from exported. tc #%d", tcnum) err = (&i).UnmarshalJSON(bz) - s.Require().NoError(err, "Error unmarshaling Int. tc #%d, err %s", tcnum, err) + s.Require().Nil(err, "Error unmarshaling Int. tc #%d, err %s", tcnum, err) s.Require().Equal(tc.i, i, "Unmarshaled value is different from exported. tc #%d", tcnum) //bz, err = tc.i.Marshal() @@ -373,8 +371,7 @@ func (s *intTestSuite) TestIntMod() { for _, tt := range tests { if tt.wantPanic { - x := sdk.NewInt(tt.x) - s.Require().Panics(func() { x.Mod(sdk.NewInt(tt.y)) }) + s.Require().Panics(func() { sdk.NewInt(tt.x).Mod(sdk.NewInt(tt.y)) }) s.Require().Panics(func() { sdk.NewInt(tt.x).ModRaw(tt.y) }) return } diff --git a/usecase/coin/uint.go b/usecase/coin/uint.go index c31948bf3..bf1db39b1 100644 --- a/usecase/coin/uint.go +++ b/usecase/coin/uint.go @@ -14,46 +14,46 @@ type Uint struct { } // BigInt converts Uint to big.Int -func (u *Uint) BigInt() *big.Int { +func (u Uint) BigInt() *big.Int { return new(big.Int).Set(u.i) } // NewUintFromBigUint constructs Uint from big.Uint -func NewUintFromBigInt(i *big.Int) *Uint { +func NewUintFromBigInt(i *big.Int) Uint { u, err := checkNewUint(i) if err != nil { panic(fmt.Errorf("overflow: %s", err)) } - return &u + return u } // NewUint constructs Uint from int64 -func NewUint(n uint64) *Uint { +func NewUint(n uint64) Uint { i := new(big.Int) i.SetUint64(n) return NewUintFromBigInt(i) } // NewUintFromString constructs Uint from string -func NewUintFromString(s string) *Uint { +func NewUintFromString(s string) Uint { u, err := ParseUint(s) if err != nil { panic(err) } - return &u + return u } // ZeroUint returns unsigned zero. -func ZeroUint() *Uint { return &Uint{big.NewInt(0)} } +func ZeroUint() Uint { return Uint{big.NewInt(0)} } // OneUint returns Uint value with one. -func OneUint() *Uint { return &Uint{big.NewInt(1)} } +func OneUint() Uint { return Uint{big.NewInt(1)} } //var _ CustomProtobufType = (*Uint)(nil) // Uint64 converts Uint to uint64 // Panics if the value is out of range -func (u *Uint) Uint64() uint64 { +func (u Uint) Uint64() uint64 { if !u.i.IsUint64() { panic("Uint64() out of bound") } @@ -61,79 +61,79 @@ func (u *Uint) Uint64() uint64 { } // IsZero returns 1 if the uint equals to 0. -func (u *Uint) IsZero() bool { return u.Equal(ZeroUint()) } +func (u Uint) IsZero() bool { return u.Equal(ZeroUint()) } // Equal compares two Uints -func (u *Uint) Equal(u2 *Uint) bool { return equal(u.i, u2.i) } +func (u Uint) Equal(u2 Uint) bool { return equal(u.i, u2.i) } // GT returns true if first Uint is greater than second -func (u *Uint) GT(u2 *Uint) bool { return gt(u.i, u2.i) } +func (u Uint) GT(u2 Uint) bool { return gt(u.i, u2.i) } // GTE returns true if first Uint is greater than second -func (u *Uint) GTE(u2 *Uint) bool { return u.GT(u2) || u.Equal(u2) } +func (u Uint) GTE(u2 Uint) bool { return u.GT(u2) || u.Equal(u2) } // LT returns true if first Uint is lesser than second -func (u *Uint) LT(u2 *Uint) bool { return lt(u.i, u2.i) } +func (u Uint) LT(u2 Uint) bool { return lt(u.i, u2.i) } // LTE returns true if first Uint is lesser than or equal to the second -func (u *Uint) LTE(u2 *Uint) bool { return !u.GT(u2) } +func (u Uint) LTE(u2 Uint) bool { return !u.GT(u2) } // Add adds Uint from another -func (u *Uint) Add(u2 *Uint) *Uint { return NewUintFromBigInt(new(big.Int).Add(u.i, u2.i)) } +func (u Uint) Add(u2 Uint) Uint { return NewUintFromBigInt(new(big.Int).Add(u.i, u2.i)) } // Add convert uint64 and add it to Uint -func (u *Uint) AddUint64(u2 uint64) *Uint { return u.Add(NewUint(u2)) } +func (u Uint) AddUint64(u2 uint64) Uint { return u.Add(NewUint(u2)) } // Sub adds Uint from another -func (u *Uint) Sub(u2 *Uint) *Uint { return NewUintFromBigInt(new(big.Int).Sub(u.i, u2.i)) } +func (u Uint) Sub(u2 Uint) Uint { return NewUintFromBigInt(new(big.Int).Sub(u.i, u2.i)) } // SubUint64 adds Uint from another -func (u *Uint) SubUint64(u2 uint64) *Uint { return u.Sub(NewUint(u2)) } +func (u Uint) SubUint64(u2 uint64) Uint { return u.Sub(NewUint(u2)) } // Mul multiplies two Uints -func (u *Uint) Mul(u2 *Uint) (res *Uint) { +func (u Uint) Mul(u2 Uint) (res Uint) { return NewUintFromBigInt(new(big.Int).Mul(u.i, u2.i)) } // Mul multiplies two Uints -func (u *Uint) MulUint64(u2 uint64) (res *Uint) { return u.Mul(NewUint(u2)) } +func (u Uint) MulUint64(u2 uint64) (res Uint) { return u.Mul(NewUint(u2)) } // Quo divides Uint with Uint -func (u *Uint) Quo(u2 *Uint) (res *Uint) { return NewUintFromBigInt(div(u.i, u2.i)) } +func (u Uint) Quo(u2 Uint) (res Uint) { return NewUintFromBigInt(div(u.i, u2.i)) } // Mod returns remainder after dividing with Uint -func (u *Uint) Mod(u2 *Uint) *Uint { +func (u Uint) Mod(u2 Uint) Uint { if u2.IsZero() { panic("division-by-zero") } - return &Uint{mod(u.i, u2.i)} + return Uint{mod(u.i, u2.i)} } // Incr increments the Uint by one. -func (u *Uint) Incr() *Uint { +func (u Uint) Incr() Uint { return u.Add(OneUint()) } // Decr decrements the Uint by one. // Decr will panic if the Uint is zero. -func (u *Uint) Decr() *Uint { +func (u Uint) Decr() Uint { return u.Sub(OneUint()) } // Quo divides Uint with uint64 -func (u *Uint) QuoUint64(u2 uint64) *Uint { return u.Quo(NewUint(u2)) } +func (u Uint) QuoUint64(u2 uint64) Uint { return u.Quo(NewUint(u2)) } // Return the minimum of the Uints -func MinUint(u1, u2 *Uint) *Uint { return NewUintFromBigInt(min(u1.i, u2.i)) } +func MinUint(u1, u2 Uint) Uint { return NewUintFromBigInt(min(u1.i, u2.i)) } // Return the maximum of the Uints -func MaxUint(u1, u2 *Uint) *Uint { return NewUintFromBigInt(max(u1.i, u2.i)) } +func MaxUint(u1, u2 Uint) Uint { return NewUintFromBigInt(max(u1.i, u2.i)) } // Human readable string -func (u *Uint) String() string { return u.i.String() } +func (u Uint) String() string { return u.i.String() } // MarshalJSON defines custom encoding scheme -func (u *Uint) MarshalJSON() ([]byte, error) { +func (u Uint) MarshalJSON() ([]byte, error) { if u.i == nil { // Necessary since default Uint initialization has i.i as nil u.i = new(big.Int) } @@ -149,7 +149,7 @@ func (u *Uint) UnmarshalJSON(bz []byte) error { } //// Marshal implements the gogo proto custom type interface. -//func (u *Uint) Marshal() ([]byte, error) { +//func (u Uint) Marshal() ([]byte, error) { // if u.i == nil { // u.i = new(big.Int) // } @@ -204,7 +204,7 @@ func (u *Uint) UnmarshalJSON(bz []byte) error { //} //// Override Amino binary serialization by proxying to protobuf. -//func (u *Uint) MarshalAmino() ([]byte, error) { return u.Marshal() } +//func (u Uint) MarshalAmino() ([]byte, error) { return u.Marshal() } //func (u *Uint) UnmarshalAmino(bz []byte) error { return u.Unmarshal(bz) } //__________________________________________________________________________ @@ -239,7 +239,7 @@ func checkNewUint(i *big.Int) (Uint, error) { // RelativePow raises x to the power of n, where x (and the result, z) are scaled by factor b // for example, RelativePow(210, 2, 100) = 441 (2.1^2 = 4.41) -func RelativePow(x *Uint, n *Uint, b *Uint) (z *Uint) { +func RelativePow(x Uint, n Uint, b Uint) (z Uint) { if x.IsZero() { if n.IsZero() { z = b // 0^0 = 1 diff --git a/usecase/coin/uint_test.go b/usecase/coin/uint_test.go index e432f9614..7d8b2ae73 100644 --- a/usecase/coin/uint_test.go +++ b/usecase/coin/uint_test.go @@ -99,7 +99,7 @@ func (s *uintTestSuite) TestArithUint() { u2 := sdk.NewUint(n2) cases := []struct { - ures *sdk.Uint + ures sdk.Uint nres uint64 }{ {u1.Add(u2), n1 + n2}, @@ -123,7 +123,7 @@ func (s *uintTestSuite) TestArithUint() { } subs := []struct { - ures *sdk.Uint + ures sdk.Uint nres uint64 }{ {u1.Sub(u2), n1 - n2}, @@ -195,7 +195,7 @@ func (s *uintTestSuite) TestImmutabilityAllUint() { ni := sdk.NewUint(n) for opnum, op := range ops { - op(ni) + op(&ni) s.Require().Equal(n, ni.Uint64(), "Uint is modified by operation. #%d", opnum) s.Require().Equal(sdk.NewUint(n), ni, "Uint is modified by operation. #%d", opnum) @@ -205,7 +205,7 @@ func (s *uintTestSuite) TestImmutabilityAllUint() { func (s *uintTestSuite) TestSafeSub() { testCases := []struct { - x, y *sdk.Uint + x, y sdk.Uint expected uint64 panic bool }{ @@ -240,9 +240,9 @@ func (s *uintTestSuite) TestParseUint() { }{ {"malformed", args{"malformed"}, sdk.Uint{}, true}, {"empty", args{""}, sdk.Uint{}, true}, - {"positive", args{"50"}, *sdk.NewUint(uint64(50)), false}, + {"positive", args{"50"}, sdk.NewUint(uint64(50)), false}, {"negative", args{"-1"}, sdk.Uint{}, true}, - {"zero", args{"0"}, *sdk.ZeroUint(), false}, + {"zero", args{"0"}, sdk.ZeroUint(), false}, } for _, tt := range tests { got, err := sdk.ParseUint(tt.args.s) @@ -251,29 +251,29 @@ func (s *uintTestSuite) TestParseUint() { continue } s.Require().NoError(err) - s.Require().True(got.Equal(&tt.want)) + s.Require().True(got.Equal(tt.want)) } } -func randuint() *sdk.Uint { +func randuint() sdk.Uint { return sdk.NewUint(rand.Uint64()) } func (s *uintTestSuite) TestRelativePow() { tests := []struct { args []sdk.Uint - want *sdk.Uint + want sdk.Uint }{ - {[]sdk.Uint{*sdk.ZeroUint(), *sdk.ZeroUint(), *sdk.OneUint()}, sdk.OneUint()}, - {[]sdk.Uint{*sdk.ZeroUint(), *sdk.ZeroUint(), *sdk.NewUint(10)}, sdk.NewUint(10)}, - {[]sdk.Uint{*sdk.ZeroUint(), *sdk.OneUint(), *sdk.NewUint(10)}, sdk.ZeroUint()}, - {[]sdk.Uint{*sdk.NewUint(10), *sdk.NewUint(2), *sdk.OneUint()}, sdk.NewUint(100)}, - {[]sdk.Uint{*sdk.NewUint(210), *sdk.NewUint(2), *sdk.NewUint(100)}, sdk.NewUint(441)}, - {[]sdk.Uint{*sdk.NewUint(2100), *sdk.NewUint(2), *sdk.NewUint(1000)}, sdk.NewUint(4410)}, - {[]sdk.Uint{*sdk.NewUint(1000000001547125958), *sdk.NewUint(600), *sdk.NewUint(1000000000000000000)}, sdk.NewUint(1000000928276004850)}, + {[]sdk.Uint{sdk.ZeroUint(), sdk.ZeroUint(), sdk.OneUint()}, sdk.OneUint()}, + {[]sdk.Uint{sdk.ZeroUint(), sdk.ZeroUint(), sdk.NewUint(10)}, sdk.NewUint(10)}, + {[]sdk.Uint{sdk.ZeroUint(), sdk.OneUint(), sdk.NewUint(10)}, sdk.ZeroUint()}, + {[]sdk.Uint{sdk.NewUint(10), sdk.NewUint(2), sdk.OneUint()}, sdk.NewUint(100)}, + {[]sdk.Uint{sdk.NewUint(210), sdk.NewUint(2), sdk.NewUint(100)}, sdk.NewUint(441)}, + {[]sdk.Uint{sdk.NewUint(2100), sdk.NewUint(2), sdk.NewUint(1000)}, sdk.NewUint(4410)}, + {[]sdk.Uint{sdk.NewUint(1000000001547125958), sdk.NewUint(600), sdk.NewUint(1000000000000000000)}, sdk.NewUint(1000000928276004850)}, } for i, tc := range tests { - res := sdk.RelativePow(&tc.args[0], &tc.args[1], &tc.args[2]) + res := sdk.RelativePow(tc.args[0], tc.args[1], tc.args[2]) s.Require().Equal(tc.want, res, "unexpected result for test case %d, input: %v, got: %v", i, tc.args, res) } } diff --git a/usecase/event/gravity_ethereum_send_to_cosmos_handled_test.go b/usecase/event/gravity_ethereum_send_to_cosmos_handled_test.go index 7b1c3f146..b942f168f 100644 --- a/usecase/event/gravity_ethereum_send_to_cosmos_handled_test.go +++ b/usecase/event/gravity_ethereum_send_to_cosmos_handled_test.go @@ -22,7 +22,7 @@ var _ = Describe("Event", func() { Module: "Gravity", Sender: "tcro1fmprm0sjy6lz9llv7rltn0v2azzwcwzvk2lsyn", Receiver: "tcrc1j6xhntmfqauwn0rqhqc89yr9a2xqe8vxthedhp", - Amount: *coin.MustNewCoins(*coin.MustNewCoinFromString("basetcro", "1")), + Amount: coin.MustNewCoins(coin.MustNewCoinFromString("basetcro", "1")), BridgeChainId: 338, EthereumTokenContract: "0x564a1c3af089d02d0b6c311c650ea3768424cbfa", Nonce: 2, diff --git a/usecase/event/msg_create_validator_test.go b/usecase/event/msg_create_validator_test.go index 48a878548..46974ea5b 100644 --- a/usecase/event/msg_create_validator_test.go +++ b/usecase/event/msg_create_validator_test.go @@ -44,7 +44,7 @@ var _ = Describe("Event", func() { DelegatorAddress: "tcro1fmprm0sjy6lz9llv7rltn0v2azzwcwzvk2lsyn", ValidatorAddress: "tcrocncl1fmprm0sjy6lz9llv7rltn0v2azzwcwzvr4ufus", TendermintPubkey: "BuuPYme7R4eH/nWs2p+sS1UpCQwy+QJgBZuhGICH8Es=", - Amount: *coin.MustNewCoinFromString("basetcro", "10"), + Amount: coin.MustNewCoinFromString("basetcro", "10"), }, ) @@ -84,7 +84,7 @@ var _ = Describe("Event", func() { DelegatorAddress: "tcro1fmprm0sjy6lz9llv7rltn0v2azzwcwzvk2lsyn", ValidatorAddress: "tcrocncl1fmprm0sjy6lz9llv7rltn0v2azzwcwzvr4ufus", TendermintPubkey: "BuuPYme7R4eH/nWs2p+sS1UpCQwy+QJgBZuhGICH8Es=", - Amount: *coin.MustNewCoinFromString("basetcro", "10"), + Amount: coin.MustNewCoinFromString("basetcro", "10"), }, ) encoded, err := event.ToJSON() diff --git a/usecase/event/msgbeginredelegate_test.go b/usecase/event/msgbeginredelegate_test.go index 81033d4ca..1026bb99c 100644 --- a/usecase/event/msgbeginredelegate_test.go +++ b/usecase/event/msgbeginredelegate_test.go @@ -28,8 +28,8 @@ var _ = Describe("Event", func() { DelegatorAddress: anyDelegatorAddress, ValidatorSrcAddress: anyValidatorSrcAddress, ValidatorDstAddress: anyValidatorDstAddress, - Amount: *anyAmount, - AutoClaimedRewards: *anyAutoClaimedRewards, + Amount: anyAmount, + AutoClaimedRewards: anyAutoClaimedRewards, } event := event_usecase.NewMsgBeginRedelegate(event_usecase.MsgCommonParams{ BlockHeight: anyHeight, @@ -70,8 +70,8 @@ var _ = Describe("Event", func() { DelegatorAddress: anyDelegatorAddress, ValidatorSrcAddress: anyValidatorSrcAddress, ValidatorDstAddress: anyValidatorDstAddress, - Amount: *anyAmount, - AutoClaimedRewards: *anyAutoClaimedRewards, + Amount: anyAmount, + AutoClaimedRewards: anyAutoClaimedRewards, } event := event_usecase.NewMsgBeginRedelegate(event_usecase.MsgCommonParams{ BlockHeight: anyHeight, diff --git a/usecase/event/msgdelegate_test.go b/usecase/event/msgdelegate_test.go index edd6d4ff9..508758a64 100644 --- a/usecase/event/msgdelegate_test.go +++ b/usecase/event/msgdelegate_test.go @@ -26,8 +26,8 @@ var _ = Describe("Event", func() { anyParams := model.MsgDelegateParams{ DelegatorAddress: anyDelegatorAddress, ValidatorAddress: anyValidatorAddress, - Amount: *anyAmount, - AutoClaimedRewards: *anyAutoClaimedRewards, + Amount: anyAmount, + AutoClaimedRewards: anyAutoClaimedRewards, } event := event_usecase.NewMsgDelegate(event_usecase.MsgCommonParams{ BlockHeight: anyHeight, @@ -67,8 +67,8 @@ var _ = Describe("Event", func() { anyParams := model.MsgDelegateParams{ DelegatorAddress: anyDelegatorAddress, ValidatorAddress: anyValidatorAddress, - Amount: *anyAmount, - AutoClaimedRewards: *anyAutoClaimedRewards, + Amount: anyAmount, + AutoClaimedRewards: anyAutoClaimedRewards, } event := event_usecase.NewMsgDelegate(event_usecase.MsgCommonParams{ BlockHeight: anyHeight, diff --git a/usecase/event/msgundelegate_test.go b/usecase/event/msgundelegate_test.go index e30647b2c..be53f9026 100644 --- a/usecase/event/msgundelegate_test.go +++ b/usecase/event/msgundelegate_test.go @@ -26,8 +26,8 @@ var _ = Describe("Event", func() { anyParams := model.MsgUndelegateParams{ DelegatorAddress: anyDelegatorAddress, ValidatorAddress: anyValidatorAddress, - Amount: *anyAmount, - AutoClaimedRewards: *anyAutoClaimedRewards, + Amount: anyAmount, + AutoClaimedRewards: anyAutoClaimedRewards, } event := event_usecase.NewMsgUndelegate(event_usecase.MsgCommonParams{ BlockHeight: anyHeight, @@ -67,8 +67,8 @@ var _ = Describe("Event", func() { anyParams := model.MsgUndelegateParams{ DelegatorAddress: anyDelegatorAddress, ValidatorAddress: anyValidatorAddress, - Amount: *anyAmount, - AutoClaimedRewards: *anyAutoClaimedRewards, + Amount: anyAmount, + AutoClaimedRewards: anyAutoClaimedRewards, } event := event_usecase.NewMsgUndelegate(event_usecase.MsgCommonParams{ BlockHeight: anyHeight, diff --git a/usecase/parser/end_block_events_ethereum_send_to_cosmos_handled_test.go b/usecase/parser/end_block_events_ethereum_send_to_cosmos_handled_test.go index 720cc125a..29446d261 100644 --- a/usecase/parser/end_block_events_ethereum_send_to_cosmos_handled_test.go +++ b/usecase/parser/end_block_events_ethereum_send_to_cosmos_handled_test.go @@ -34,8 +34,8 @@ var _ = Describe("ParseEndBlockEventsCommands", func() { Module: "gravity", Sender: "0x5E44D43F4Aa0B3ED004eaaD4eF21a83DFF2ef6E5", Receiver: "tcrc13yux6z8mh6w5t3v4uq7clewnh35znrgdgye0k2", - Amount: *coin.MustNewCoins( - *coin.MustNewCoin("gravity0x564A1c3AF089D02D0B6C311C650eA3768424cbfa", *coin.NewInt(250)), + Amount: coin.MustNewCoins( + coin.MustNewCoin("gravity0x564A1c3AF089D02D0B6C311C650eA3768424cbfa", coin.NewInt(250)), ), BridgeChainId: 42, EthereumTokenContract: "0x564A1c3AF089D02D0B6C311C650eA3768424cbfa", diff --git a/usecase/parser/genesis.go b/usecase/parser/genesis.go index 1583fb717..881490e24 100644 --- a/usecase/parser/genesis.go +++ b/usecase/parser/genesis.go @@ -70,7 +70,7 @@ func ParseGenesisCommands( ), ValidatorAddress: validator.OperatorAddress, TendermintPubkey: validator.ConsensusPubkey.Key, - Amount: *amount, + Amount: amount, Jailed: validator.Jailed, }, )) diff --git a/usecase/parser/msg.go b/usecase/parser/msg.go index 83e5eaa81..3dcdc5183 100644 --- a/usecase/parser/msg.go +++ b/usecase/parser/msg.go @@ -1119,7 +1119,7 @@ func ParseMsgDelegate( } if autoClaimedRewards.Denom == parsedCoin.Denom { - autoClaimedRewards = autoClaimedRewards.Add(&parsedCoin) + autoClaimedRewards = autoClaimedRewards.Add(parsedCoin) } } } @@ -1131,7 +1131,7 @@ func ParseMsgDelegate( DelegatorAddress: utils.AddressParse(parserParams.Msg["delegator_address"].(string)), ValidatorAddress: utils.AddressParse(parserParams.Msg["validator_address"].(string)), Amount: amount, - AutoClaimedRewards: *autoClaimedRewards, + AutoClaimedRewards: autoClaimedRewards, }, )}, possibleSignerAddresses } @@ -1198,7 +1198,7 @@ func ParseMsgUndelegate( } if autoClaimedRewards.Denom == parsedCoin.Denom { - autoClaimedRewards = autoClaimedRewards.Add(&parsedCoin) + autoClaimedRewards = autoClaimedRewards.Add(parsedCoin) } } } @@ -1211,7 +1211,7 @@ func ParseMsgUndelegate( ValidatorAddress: utils.AddressParse(parserParams.Msg["validator_address"].(string)), MaybeUnbondCompleteAt: &unbondCompletionTime, Amount: amount, - AutoClaimedRewards: *autoClaimedRewards, + AutoClaimedRewards: autoClaimedRewards, }, )}, possibleSignerAddresses } @@ -1267,7 +1267,7 @@ func ParseMsgBeginRedelegate( } if autoClaimedRewards.Denom == parsedCoin.Denom { - autoClaimedRewards = autoClaimedRewards.Add(&parsedCoin) + autoClaimedRewards = autoClaimedRewards.Add(parsedCoin) } } } @@ -1280,7 +1280,7 @@ func ParseMsgBeginRedelegate( ValidatorSrcAddress: utils.AddressParse(parserParams.Msg["validator_src_address"].(string)), ValidatorDstAddress: utils.AddressParse(parserParams.Msg["validator_dst_address"].(string)), Amount: amount, - AutoClaimedRewards: *autoClaimedRewards, + AutoClaimedRewards: autoClaimedRewards, }, )}, possibleSignerAddresses } diff --git a/usecase/parser/msg_begin_redelegate_test.go b/usecase/parser/msg_begin_redelegate_test.go index e0a67887f..06c56179a 100644 --- a/usecase/parser/msg_begin_redelegate_test.go +++ b/usecase/parser/msg_begin_redelegate_test.go @@ -50,7 +50,7 @@ var _ = Describe("ParseMsgCommands", func() { ValidatorSrcAddress: "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", ValidatorDstAddress: "tcrocncl1xwd3k8xterdeft3nxqg92szhpz6vx43qspdpw6", Amount: coin.MustParseCoinNormalized("10000000000basetcro"), - AutoClaimedRewards: *coin.MustNewCoin("basetcro", *coin.NewInt(281334)), + AutoClaimedRewards: coin.MustNewCoin("basetcro", coin.NewInt(281334)), }, )})) Expect(possibleSignerAddresses).To(Equal([]string{"tcro1gs80n8fpc5mc3ywkgfy93l23tg0gdqj5w2ll64"})) diff --git a/usecase/parser/msg_submit_proposal_test.go b/usecase/parser/msg_submit_proposal_test.go index 5255a6471..8f7573bc0 100644 --- a/usecase/parser/msg_submit_proposal_test.go +++ b/usecase/parser/msg_submit_proposal_test.go @@ -58,7 +58,7 @@ var _ = Describe("ParseMsgCommands", func() { InitialDeposit: coin.Coins{ { Denom: "basecro", - Amount: *coin.NewInt(10000), + Amount: coin.NewInt(10000), }, }, Metadata: "ipfs://CID", @@ -122,7 +122,7 @@ var _ = Describe("ParseMsgCommands", func() { InitialDeposit: coin.Coins{ { Denom: "basecro", - Amount: *coin.NewInt(1000), + Amount: coin.NewInt(1000), }, }, Metadata: "ipfs://CID", @@ -179,7 +179,7 @@ var _ = Describe("ParseMsgCommands", func() { InitialDeposit: coin.Coins{ { Denom: "basecro", - Amount: *coin.NewInt(1000000), + Amount: coin.NewInt(1000000), }, }, Metadata: "ipfs://CID", diff --git a/usecase/parser/msg_undelegate_test.go b/usecase/parser/msg_undelegate_test.go index b0c4f89eb..97e557464 100644 --- a/usecase/parser/msg_undelegate_test.go +++ b/usecase/parser/msg_undelegate_test.go @@ -52,7 +52,7 @@ var _ = Describe("ParseMsgCommands", func() { ValidatorAddress: "tcrocncl1j7pej8kplem4wt50p4hfvndhuw5jprxxxtenvr", Amount: coin.MustParseCoinNormalized("1000000000basetcro"), MaybeUnbondCompleteAt: primptr.UTCTime(utctime.FromUnixNano(int64(1605152654000000000))), - AutoClaimedRewards: *coin.MustNewCoin("basetcro", *coin.NewInt(76688)), + AutoClaimedRewards: coin.MustNewCoin("basetcro", coin.NewInt(76688)), }, )})) Expect(possibleSignerAddresses).To(Equal([]string{"tcro1gs80n8fpc5mc3ywkgfy93l23tg0gdqj5w2ll64"})) diff --git a/usecase/parser/utils/tx.go b/usecase/parser/utils/tx.go index 333a49190..72e9e16ae 100644 --- a/usecase/parser/utils/tx.go +++ b/usecase/parser/utils/tx.go @@ -12,12 +12,12 @@ func SumAmount(amounts []model.CosmosTxAuthInfoFeeAmount) (coin.Coins, error) { coins := coin.NewEmptyCoins() for _, amount := range amounts { - var amountCoin *coin.Coin + var amountCoin coin.Coin amountCoin, err = coin.NewCoinFromString(amount.Denom, amount.Amount) if err != nil { return nil, fmt.Errorf("error parsing amount %s to Coin: %v", amount.Amount, err) } - coins = coins.Add(*amountCoin) + coins = coins.Add(amountCoin) } return coins, nil