Skip to content

Commit

Permalink
use correct mock
Browse files Browse the repository at this point in the history
  • Loading branch information
0xstepit committed Dec 19, 2024
1 parent 00caa02 commit c60628d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 458 deletions.
68 changes: 34 additions & 34 deletions x/evm/wrappers/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestMintAmountToAccount(t *testing.T) {
amount *big.Int
recipient sdk.AccAddress
expectErr string
mockSetup func(*testutil.MockBankKeeper)
mockSetup func(*testutil.MockBankWrapper)
}{
{
name: "success - convert 18 decimals amount to 6 decimals",
Expand All @@ -37,7 +37,7 @@ func TestMintAmountToAccount(t *testing.T) {
amount: big.NewInt(1e18), // 1 token in 18 decimals
recipient: sdk.AccAddress([]byte("test_address")),
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoin := sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6)) // 1 token in 6 decimals
expectedCoins := sdk.NewCoins(expectedCoin)

Expand All @@ -61,7 +61,7 @@ func TestMintAmountToAccount(t *testing.T) {
amount: big.NewInt(1e18), // 1 token in 18 decimals
recipient: sdk.AccAddress([]byte("test_address")),
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoin := sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e18))
expectedCoins := sdk.NewCoins(expectedCoin)

Expand All @@ -85,7 +85,7 @@ func TestMintAmountToAccount(t *testing.T) {
amount: big.NewInt(1e18),
recipient: sdk.AccAddress([]byte("test_address")),
expectErr: "failed to mint coins to account in bank wrapper",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoin := sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6))
expectedCoins := sdk.NewCoins(expectedCoin)

Expand All @@ -101,7 +101,7 @@ func TestMintAmountToAccount(t *testing.T) {
amount: big.NewInt(1e18),
recipient: sdk.AccAddress([]byte("test_address")),
expectErr: "send error",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoin := sdk.NewCoin("evm", sdkmath.NewInt(1e6))
expectedCoins := sdk.NewCoins(expectedCoin)

Expand Down Expand Up @@ -131,7 +131,7 @@ func TestMintAmountToAccount(t *testing.T) {
// Setup mock controller
ctrl := gomock.NewController(t)

mockBankKeeper := testutil.NewMockBankKeeper(ctrl)
mockBankKeeper := testutil.NewMockBankWrapper(ctrl)
tc.mockSetup(mockBankKeeper)

bankWrapper := wrappers.NewBankWrapper(mockBankKeeper)
Expand All @@ -156,15 +156,15 @@ func TestBurnAmountFromAccount(t *testing.T) {
evmDecimals uint8
amount *big.Int
expectErr string
mockSetup func(*testutil.MockBankKeeper)
mockSetup func(*testutil.MockBankWrapper)
}{
{
name: "success - convert 18 decimals amount to 6 decimals",
evmDenom: tokenDenom,
evmDecimals: 6,
amount: big.NewInt(1e18),
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoin := sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6))
expectedCoins := sdk.NewCoins(expectedCoin)

Expand All @@ -187,7 +187,7 @@ func TestBurnAmountFromAccount(t *testing.T) {
evmDecimals: 18,
amount: big.NewInt(1e18),
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoin := sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e18))
expectedCoins := sdk.NewCoins(expectedCoin)

Expand All @@ -210,7 +210,7 @@ func TestBurnAmountFromAccount(t *testing.T) {
evmDecimals: 6,
amount: big.NewInt(1e18),
expectErr: "failed to burn coins from account in bank wrapper",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoin := sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6))
expectedCoins := sdk.NewCoins(expectedCoin)

Expand All @@ -229,7 +229,7 @@ func TestBurnAmountFromAccount(t *testing.T) {
evmDecimals: 6,
amount: big.NewInt(1e18),
expectErr: "burn error",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoin := sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6))
expectedCoins := sdk.NewCoins(expectedCoin)

Expand All @@ -255,7 +255,7 @@ func TestBurnAmountFromAccount(t *testing.T) {
// Setup mock controller
ctrl := gomock.NewController(t)

mockBankKeeper := testutil.NewMockBankKeeper(ctrl)
mockBankKeeper := testutil.NewMockBankWrapper(ctrl)
tc.mockSetup(mockBankKeeper)

bankWrapper := wrappers.NewBankWrapper(mockBankKeeper)
Expand All @@ -280,7 +280,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) {
evmDecimals uint8
coins func() sdk.Coins
expectErr string
mockSetup func(*testutil.MockBankKeeper)
mockSetup func(*testutil.MockBankWrapper)
}{
{
name: "success - does not convert 18 decimals amount with single token",
Expand All @@ -293,7 +293,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoins := sdk.NewCoins([]sdk.Coin{
sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e18)),
}...)
Expand All @@ -318,7 +318,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoins := sdk.NewCoins([]sdk.Coin{
sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6)),
}...)
Expand All @@ -344,7 +344,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoins := sdk.NewCoins([]sdk.Coin{
sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e18)),
sdk.NewCoin("something", sdkmath.NewInt(3e18)),
Expand All @@ -371,7 +371,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoins := sdk.NewCoins([]sdk.Coin{
sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6)),
sdk.NewCoin("something", sdkmath.NewInt(3e18)),
Expand All @@ -397,7 +397,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
mbk.EXPECT().
SendCoinsFromModuleToAccount(
gomock.Any(),
Expand All @@ -420,7 +420,7 @@ func TestSendCoinsFromModuleToAccount(t *testing.T) {
// Setup mock controller
ctrl := gomock.NewController(t)

mockBankKeeper := testutil.NewMockBankKeeper(ctrl)
mockBankKeeper := testutil.NewMockBankWrapper(ctrl)
tc.mockSetup(mockBankKeeper)

bankWrapper := wrappers.NewBankWrapper(mockBankKeeper)
Expand All @@ -445,7 +445,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) {
evmDecimals uint8
coins func() sdk.Coins
expectErr string
mockSetup func(*testutil.MockBankKeeper)
mockSetup func(*testutil.MockBankWrapper)
}{
{
name: "success - does not convert 18 decimals amount with single token",
Expand All @@ -458,7 +458,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoins := sdk.NewCoins([]sdk.Coin{
sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e18)),
}...)
Expand All @@ -483,7 +483,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoins := sdk.NewCoins([]sdk.Coin{
sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6)),
}...)
Expand All @@ -509,7 +509,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoins := sdk.NewCoins([]sdk.Coin{
sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e18)),
sdk.NewCoin("something", sdkmath.NewInt(3e18)),
Expand All @@ -536,7 +536,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
expectedCoins := sdk.NewCoins([]sdk.Coin{
sdk.NewCoin(tokenDenom, sdkmath.NewInt(1e6)),
sdk.NewCoin("something", sdkmath.NewInt(3e18)),
Expand All @@ -562,7 +562,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) {
return coins
},
expectErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
mbk.EXPECT().
SendCoinsFromAccountToModule(
gomock.Any(),
Expand All @@ -585,7 +585,7 @@ func TestSendCoinsFromAccountToModule(t *testing.T) {
// Setup mock controller
ctrl := gomock.NewController(t)

mockBankKeeper := testutil.NewMockBankKeeper(ctrl)
mockBankKeeper := testutil.NewMockBankWrapper(ctrl)
tc.mockSetup(mockBankKeeper)

bankWrapper := wrappers.NewBankWrapper(mockBankKeeper)
Expand Down Expand Up @@ -614,15 +614,15 @@ func TestGetBalance(t *testing.T) {
expCoin sdk.Coin
expErr string
expPanic string
mockSetup func(*testutil.MockBankKeeper)
mockSetup func(*testutil.MockBankWrapper)
}{
{
name: "success - convert 6 decimals amount to 18 decimals",
denom: evmDenom,
evmDecimals: 6,
expCoin: sdk.NewCoin(evmDenom, sdkmath.NewInt(1e18)),
expErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
returnedCoin := sdk.NewCoin(evmDenom, sdkmath.NewInt(1e6))

mbk.EXPECT().
Expand All @@ -639,7 +639,7 @@ func TestGetBalance(t *testing.T) {
evmDecimals: 6,
expCoin: sdk.NewCoin(evmDenom, sdkmath.NewInt(1e12).MulRaw(maxInt64)),
expErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
returnedCoin := sdk.NewCoin(evmDenom, sdkmath.NewInt(maxInt64))

mbk.EXPECT().
Expand All @@ -656,7 +656,7 @@ func TestGetBalance(t *testing.T) {
evmDecimals: 18,
expCoin: sdk.NewCoin(evmDenom, sdkmath.NewInt(1e18)),
expErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
returnedCoin := sdk.NewCoin(evmDenom, sdkmath.NewInt(1e18))

mbk.EXPECT().
Expand All @@ -673,7 +673,7 @@ func TestGetBalance(t *testing.T) {
evmDecimals: 6,
expCoin: sdk.NewCoin(evmDenom, sdkmath.NewInt(0)),
expErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
returnedCoin := sdk.NewCoin(evmDenom, sdkmath.NewInt(0))

mbk.EXPECT().
Expand All @@ -690,7 +690,7 @@ func TestGetBalance(t *testing.T) {
evmDecimals: 6,
expCoin: sdk.NewCoin(evmDenom, sdkmath.NewInt(1e14)), // 0.0001 token in 18 decimals
expErr: "",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
returnedCoin := sdk.NewCoin(evmDenom, sdkmath.NewInt(100)) // 0.0001 token in 6 decimals

mbk.EXPECT().
Expand All @@ -706,7 +706,7 @@ func TestGetBalance(t *testing.T) {
denom: "wrong_denom",
evmDecimals: 18,
expPanic: "expected evm denom token",
mockSetup: func(mbk *testutil.MockBankKeeper) {
mockSetup: func(mbk *testutil.MockBankWrapper) {
returnedCoin := sdk.NewCoin("wrong_denom", sdkmath.NewInt(1e18))

mbk.EXPECT().
Expand All @@ -730,7 +730,7 @@ func TestGetBalance(t *testing.T) {
// Setup mock controller
ctrl := gomock.NewController(t)

mockBankKeeper := testutil.NewMockBankKeeper(ctrl)
mockBankKeeper := testutil.NewMockBankWrapper(ctrl)
tc.mockSetup(mockBankKeeper)

bankWrapper := wrappers.NewBankWrapper(mockBankKeeper)
Expand Down
Loading

0 comments on commit c60628d

Please sign in to comment.