Best Mock code snippet using gomock.Helper
rebalance_test.go
Source:rebalance_test.go
...14 "testing"15)16func TestRebalance(t *testing.T) {17 t.Run("success, rebalance with stableCredit 1 loop", func(t *testing.T) {18 testHelper := testHelperWithMock(t)19 defer testHelper.MockController.Finish()20 stableCreditSize := uint8(1)21 stableCreditAddress := common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")22 stableCreditId := utils.StringToByte32("VELO_vUSD_0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")23 stableCreditAssetCode := "vUSD"24 collateralAssetCode := utils.StringToByte32("VELO")25 testHelper.MockHeartContract.EXPECT().26 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).27 Return(stableCreditSize, nil)28 testHelper.MockHeartContract.EXPECT().29 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).30 Return(stableCreditAddress, nil)31 testHelper.MockTxHelper.EXPECT().32 StableCreditAssetCode(gomock.AssignableToTypeOf(stableCreditAddress)).33 Return(&stableCreditAssetCode, &stableCreditId, nil)34 testHelper.MockDRSContract.EXPECT().35 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCode).36 Return(&types.Transaction{}, nil)37 testHelper.MockTxHelper.EXPECT().38 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).39 Return(&types.Receipt{40 Logs: []*types.Log{41 {42 Topics: []common.Hash{43 crypto.Keccak256Hash([]byte("Rebalance(string,bytes32,uint256,uint256)")),44 },45 },46 },47 }, nil)48 testHelper.MockTxHelper.EXPECT().49 ExtractRebalanceEvent("Rebalance", gomock.AssignableToTypeOf(&types.Log{})).50 Return(&vabi.DigitalReserveSystemRebalance{51 AssetCode: stableCreditAssetCode,52 CollateralAssetCode: collateralAssetCode,53 PresentAmount: big.NewInt(1000000000),54 RequiredAmount: big.NewInt(1000000000),55 }, nil)56 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})57 assert.Equal(t, "100.0000000", result.RebalanceTransactions[0].RequiredAmount)58 assert.Equal(t, "100.0000000", result.RebalanceTransactions[0].PresentAmount)59 assert.Equal(t, stableCreditAssetCode, result.RebalanceTransactions[0].AssetCode)60 assert.Equal(t, utils.Byte32ToString(collateralAssetCode), result.RebalanceTransactions[0].CollateralAssetCode)61 assert.NoError(t, err)62 assert.NotNil(t, result)63 })64 t.Run("success, rebalance with stableCredit 2 loop", func(t *testing.T) {65 testHelper := testHelperWithMock(t)66 defer testHelper.MockController.Finish()67 stableCreditSize := uint8(2)68 stableCreditAddress := common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")69 nextStableCreditAddress := common.HexToAddress("0x8F384Dd497A06941531ED277Cc0Cd34e7d594323")70 stableCreditId := utils.StringToByte32("VELO_vUSD_0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")71 stableCreditAssetCodeVUSD := "vUSD"72 stableCreditAssetCodeVTHB := "vTHB"73 collateralAssetCode := utils.StringToByte32("VELO")74 testHelper.MockHeartContract.EXPECT().75 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).76 Return(stableCreditSize, nil)77 testHelper.MockHeartContract.EXPECT().78 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).79 Return(stableCreditAddress, nil)80 testHelper.MockTxHelper.EXPECT().81 StableCreditAssetCode(gomock.AssignableToTypeOf(stableCreditAddress)).82 Return(&stableCreditAssetCodeVUSD, &stableCreditId, nil)83 testHelper.MockTxHelper.EXPECT().84 StableCreditAssetCode(gomock.AssignableToTypeOf(stableCreditAddress)).85 Return(&stableCreditAssetCodeVTHB, &stableCreditId, nil)86 testHelper.MockHeartContract.EXPECT().87 GetNextStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{}), gomock.AssignableToTypeOf(stableCreditId)).88 Return(nextStableCreditAddress, nil)89 testHelper.MockDRSContract.EXPECT().90 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCodeVUSD).91 Return(&types.Transaction{}, nil)92 testHelper.MockTxHelper.EXPECT().93 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).94 Return(&types.Receipt{95 Logs: []*types.Log{96 {97 Topics: []common.Hash{98 crypto.Keccak256Hash([]byte("Rebalance(string,bytes32,uint256,uint256)")),99 },100 },101 },102 }, nil)103 testHelper.MockTxHelper.EXPECT().104 ExtractRebalanceEvent("Rebalance", gomock.AssignableToTypeOf(&types.Log{})).105 Return(&vabi.DigitalReserveSystemRebalance{106 AssetCode: stableCreditAssetCodeVUSD,107 CollateralAssetCode: collateralAssetCode,108 PresentAmount: big.NewInt(1000000000),109 RequiredAmount: big.NewInt(1000000000),110 }, nil)111 testHelper.MockDRSContract.EXPECT().112 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCodeVTHB).113 Return(&types.Transaction{}, nil)114 testHelper.MockTxHelper.EXPECT().115 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).116 Return(&types.Receipt{117 Logs: []*types.Log{118 {119 Topics: []common.Hash{120 crypto.Keccak256Hash([]byte("Rebalance(string,bytes32,uint256,uint256)")),121 },122 },123 },124 }, nil)125 testHelper.MockTxHelper.EXPECT().126 ExtractRebalanceEvent("Rebalance", gomock.AssignableToTypeOf(&types.Log{})).127 Return(&vabi.DigitalReserveSystemRebalance{128 AssetCode: stableCreditAssetCodeVTHB,129 CollateralAssetCode: collateralAssetCode,130 PresentAmount: big.NewInt(1000000000),131 RequiredAmount: big.NewInt(1000000000),132 }, nil)133 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})134 assert.NoError(t, err)135 assert.NotNil(t, result)136 assert.Equal(t, "100.0000000", result.RebalanceTransactions[0].RequiredAmount)137 assert.Equal(t, "100.0000000", result.RebalanceTransactions[0].PresentAmount)138 assert.Equal(t, stableCreditAssetCodeVUSD, result.RebalanceTransactions[0].AssetCode)139 assert.Equal(t, "100.0000000", result.RebalanceTransactions[1].RequiredAmount)140 assert.Equal(t, "100.0000000", result.RebalanceTransactions[1].PresentAmount)141 assert.Equal(t, stableCreditAssetCodeVTHB, result.RebalanceTransactions[1].AssetCode)142 })143 t.Run("success, rebalance with stableCredit 3 loop", func(t *testing.T) {144 testHelper := testHelperWithMock(t)145 defer testHelper.MockController.Finish()146 stableCreditSize := uint8(3)147 stableCreditAddress := common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")148 nextStableCreditAddress := common.HexToAddress("0x8F384Dd497A06941531ED277Cc0Cd34e7d594323")149 stableCreditId := utils.StringToByte32("VELO_vUSD_0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")150 stableCreditAssetCodeVUSD := "vUSD"151 stableCreditAssetCodeVTHB := "vTHB"152 stableCreditAssetCodeVSGD := "vSGD"153 collateralAssetCodeVELO := utils.StringToByte32("VELO")154 collateralAssetCodeETH := utils.StringToByte32("ETH")155 testHelper.MockHeartContract.EXPECT().156 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).157 Return(stableCreditSize, nil)158 testHelper.MockHeartContract.EXPECT().159 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).160 Return(stableCreditAddress, nil)161 testHelper.MockTxHelper.EXPECT().162 StableCreditAssetCode(gomock.AssignableToTypeOf(stableCreditAddress)).163 Return(&stableCreditAssetCodeVUSD, &stableCreditId, nil)164 testHelper.MockTxHelper.EXPECT().165 StableCreditAssetCode(gomock.AssignableToTypeOf(stableCreditAddress)).166 Return(&stableCreditAssetCodeVTHB, &stableCreditId, nil)167 testHelper.MockTxHelper.EXPECT().168 StableCreditAssetCode(gomock.AssignableToTypeOf(stableCreditAddress)).169 Return(&stableCreditAssetCodeVSGD, &stableCreditId, nil)170 testHelper.MockHeartContract.EXPECT().171 GetNextStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{}), gomock.AssignableToTypeOf(stableCreditId)).172 Return(nextStableCreditAddress, nil)173 testHelper.MockHeartContract.EXPECT().174 GetNextStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{}), gomock.AssignableToTypeOf(stableCreditId)).175 Return(nextStableCreditAddress, nil)176 testHelper.MockDRSContract.EXPECT().177 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCodeVUSD).178 Return(&types.Transaction{}, nil)179 testHelper.MockTxHelper.EXPECT().180 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).181 Return(&types.Receipt{182 Logs: []*types.Log{183 {184 Topics: []common.Hash{185 crypto.Keccak256Hash([]byte("Rebalance(string,bytes32,uint256,uint256)")),186 },187 },188 },189 }, nil)190 testHelper.MockTxHelper.EXPECT().191 ExtractRebalanceEvent("Rebalance", gomock.AssignableToTypeOf(&types.Log{})).192 Return(&vabi.DigitalReserveSystemRebalance{193 AssetCode: stableCreditAssetCodeVUSD,194 CollateralAssetCode: collateralAssetCodeVELO,195 PresentAmount: big.NewInt(1000000000),196 RequiredAmount: big.NewInt(1000000000),197 }, nil)198 testHelper.MockDRSContract.EXPECT().199 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCodeVTHB).200 Return(&types.Transaction{}, nil)201 testHelper.MockTxHelper.EXPECT().202 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).203 Return(&types.Receipt{204 Logs: []*types.Log{205 {206 Topics: []common.Hash{207 crypto.Keccak256Hash([]byte("Rebalance(string,bytes32,uint256,uint256)")),208 },209 },210 },211 }, nil)212 testHelper.MockTxHelper.EXPECT().213 ExtractRebalanceEvent("Rebalance", gomock.AssignableToTypeOf(&types.Log{})).214 Return(&vabi.DigitalReserveSystemRebalance{215 AssetCode: stableCreditAssetCodeVTHB,216 CollateralAssetCode: collateralAssetCodeETH,217 PresentAmount: big.NewInt(1000000000),218 RequiredAmount: big.NewInt(1000000000),219 }, nil)220 testHelper.MockDRSContract.EXPECT().221 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCodeVSGD).222 Return(&types.Transaction{}, nil)223 testHelper.MockTxHelper.EXPECT().224 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).225 Return(&types.Receipt{226 Logs: []*types.Log{227 {228 Topics: []common.Hash{229 crypto.Keccak256Hash([]byte("Rebalance(string,bytes32,uint256,uint256)")),230 },231 },232 },233 }, nil)234 testHelper.MockTxHelper.EXPECT().235 ExtractRebalanceEvent("Rebalance", gomock.AssignableToTypeOf(&types.Log{})).236 Return(&vabi.DigitalReserveSystemRebalance{237 AssetCode: stableCreditAssetCodeVSGD,238 CollateralAssetCode: collateralAssetCodeVELO,239 PresentAmount: big.NewInt(1000000000),240 RequiredAmount: big.NewInt(1000000000),241 }, nil)242 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})243 assert.NoError(t, err)244 assert.NotNil(t, result)245 })246 t.Run("success, no event emit rebalance equilibrium", func(t *testing.T) {247 testHelper := testHelperWithMock(t)248 defer testHelper.MockController.Finish()249 stableCreditSize := uint8(1)250 stableCreditAddress := common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")251 stableCreditId := utils.StringToByte32("VELO_vUSD_0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")252 stableCreditAssetCode := "vUSD"253 testHelper.MockHeartContract.EXPECT().254 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).255 Return(stableCreditSize, nil)256 testHelper.MockHeartContract.EXPECT().257 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).258 Return(stableCreditAddress, nil)259 testHelper.MockTxHelper.EXPECT().260 StableCreditAssetCode(gomock.AssignableToTypeOf(stableCreditAddress)).261 Return(&stableCreditAssetCode, &stableCreditId, nil)262 testHelper.MockDRSContract.EXPECT().263 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCode).264 Return(&types.Transaction{}, nil)265 testHelper.MockTxHelper.EXPECT().266 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).267 Return(&types.Receipt{268 Logs: []*types.Log{269 {},270 },271 }, nil)272 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})273 assert.NotNil(t, result)274 assert.NoError(t, err)275 })276 t.Run("fail, call Heart Contract GetStableCreditCount", func(t *testing.T) {277 testHelper := testHelperWithMock(t)278 defer testHelper.MockController.Finish()279 testHelper.MockHeartContract.EXPECT().280 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).281 Return(uint8(0), errors.New("error here"))282 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})283 assert.Error(t, err)284 assert.Nil(t, result)285 })286 t.Run("fail, call Heart Contract GetStableCreditCount with stableCreditSize 0", func(t *testing.T) {287 testHelper := testHelperWithMock(t)288 defer testHelper.MockController.Finish()289 testHelper.MockHeartContract.EXPECT().290 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).291 Return(uint8(0), nil)292 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})293 assert.Error(t, err)294 assert.Nil(t, result)295 assert.Equal(t, "stable credit not found", err.Error())296 })297 t.Run("fail, call Heart Contract GetRecentStableCredit", func(t *testing.T) {298 testHelper := testHelperWithMock(t)299 defer testHelper.MockController.Finish()300 testHelper.MockHeartContract.EXPECT().301 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).302 Return(uint8(1), nil)303 testHelper.MockHeartContract.EXPECT().304 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).305 Return(common.Address{}, errors.New("error here"))306 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})307 assert.Error(t, err)308 assert.Nil(t, result)309 })310 t.Run("fail, call txHelper StableCreditAssetCode", func(t *testing.T) {311 testHelper := testHelperWithMock(t)312 defer testHelper.MockController.Finish()313 testHelper.MockHeartContract.EXPECT().314 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).315 Return(uint8(1), nil)316 testHelper.MockHeartContract.EXPECT().317 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).318 Return(common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0"), nil)319 testHelper.MockTxHelper.EXPECT().320 StableCreditAssetCode(gomock.AssignableToTypeOf(common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0"))).321 Return(nil, nil, errors.New("error here"))322 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})323 assert.Error(t, err)324 assert.Nil(t, result)325 })326 t.Run("fail, call Drs Contract Rebalance 2 loop but got error from call Heart Contract GetNextStableCredit", func(t *testing.T) {327 testHelper := testHelperWithMock(t)328 defer testHelper.MockController.Finish()329 stableCreditId := utils.StringToByte32("VELO_vUSD_0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")330 stableCreditAssetCode := "vUSD"331 collateralAssetCode := utils.StringToByte32("VELO")332 testHelper.MockHeartContract.EXPECT().333 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).334 Return(uint8(2), nil)335 testHelper.MockHeartContract.EXPECT().336 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).337 Return(common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0"), nil)338 testHelper.MockTxHelper.EXPECT().339 StableCreditAssetCode(gomock.AssignableToTypeOf(common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0"))).340 Return(&stableCreditAssetCode, &stableCreditId, nil)341 testHelper.MockHeartContract.EXPECT().342 GetNextStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{}), gomock.AssignableToTypeOf(stableCreditId)).343 Return(common.Address{}, errors.New("error here"))344 testHelper.MockDRSContract.EXPECT().345 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCode).346 Return(&types.Transaction{}, nil)347 testHelper.MockTxHelper.EXPECT().348 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).349 Return(&types.Receipt{350 Logs: []*types.Log{351 {352 Topics: []common.Hash{353 crypto.Keccak256Hash([]byte("Rebalance(string,bytes32,uint256,uint256)")),354 },355 },356 },357 }, nil)358 testHelper.MockTxHelper.EXPECT().359 ExtractRebalanceEvent("Rebalance", gomock.AssignableToTypeOf(&types.Log{})).360 Return(&vabi.DigitalReserveSystemRebalance{361 AssetCode: stableCreditAssetCode,362 CollateralAssetCode: collateralAssetCode,363 PresentAmount: big.NewInt(1000000000),364 RequiredAmount: big.NewInt(1000000000),365 }, nil)366 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})367 assert.Error(t, err)368 assert.Nil(t, result)369 })370 t.Run("fail, call Drs Contract Rebalance throw error", func(t *testing.T) {371 testHelper := testHelperWithMock(t)372 defer testHelper.MockController.Finish()373 stableCreditId := utils.StringToByte32("VELO_vUSD_0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")374 stableCreditAssetCode := "vUSD"375 testHelper.MockHeartContract.EXPECT().376 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).377 Return(uint8(2), nil)378 testHelper.MockHeartContract.EXPECT().379 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).380 Return(common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0"), nil)381 testHelper.MockTxHelper.EXPECT().382 StableCreditAssetCode(gomock.AssignableToTypeOf(common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0"))).383 Return(&stableCreditAssetCode, &stableCreditId, nil)384 testHelper.MockDRSContract.EXPECT().385 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCode).386 Return(nil, errors.New("error here"))387 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})388 assert.Error(t, err)389 assert.Nil(t, result)390 })391 t.Run("fail, call txHelper.ConfirmTx", func(t *testing.T) {392 testHelper := testHelperWithMock(t)393 defer testHelper.MockController.Finish()394 stableCreditId := utils.StringToByte32("VELO_vUSD_0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")395 stableCreditAssetCode := "vUSD"396 testHelper.MockHeartContract.EXPECT().397 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).398 Return(uint8(2), nil)399 testHelper.MockHeartContract.EXPECT().400 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).401 Return(common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0"), nil)402 testHelper.MockTxHelper.EXPECT().403 StableCreditAssetCode(gomock.AssignableToTypeOf(common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0"))).404 Return(&stableCreditAssetCode, &stableCreditId, nil)405 testHelper.MockDRSContract.EXPECT().406 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCode).407 Return(&types.Transaction{}, nil)408 testHelper.MockTxHelper.EXPECT().409 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).410 Return(nil, errors.New("error here"))411 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})412 assert.Error(t, err)413 assert.Nil(t, result)414 })415 t.Run("fail, call txHelper.ExtractRebalanceEvent", func(t *testing.T) {416 testHelper := testHelperWithMock(t)417 defer testHelper.MockController.Finish()418 stableCreditSize := uint8(1)419 stableCreditAddress := common.HexToAddress("0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")420 stableCreditId := utils.StringToByte32("VELO_vUSD_0x2Fb9287ba799297EB918aD607B5F8D3108a026f0")421 stableCreditAssetCode := "vUSD"422 testHelper.MockHeartContract.EXPECT().423 GetStableCreditCount(gomock.AssignableToTypeOf(&bind.CallOpts{})).424 Return(stableCreditSize, nil)425 testHelper.MockHeartContract.EXPECT().426 GetRecentStableCredit(gomock.AssignableToTypeOf(&bind.CallOpts{})).427 Return(stableCreditAddress, nil)428 testHelper.MockTxHelper.EXPECT().429 StableCreditAssetCode(gomock.AssignableToTypeOf(stableCreditAddress)).430 Return(&stableCreditAssetCode, &stableCreditId, nil)431 testHelper.MockDRSContract.EXPECT().432 Rebalance(gomock.AssignableToTypeOf(&bind.TransactOpts{}), stableCreditAssetCode).433 Return(&types.Transaction{}, nil)434 testHelper.MockTxHelper.EXPECT().435 ConfirmTx(gomock.AssignableToTypeOf(context.Background()), gomock.AssignableToTypeOf(&types.Transaction{}), gomock.AssignableToTypeOf(common.Address{})).436 Return(&types.Receipt{437 Logs: []*types.Log{438 {439 Topics: []common.Hash{440 crypto.Keccak256Hash([]byte("Rebalance(string,bytes32,uint256,uint256)")),441 },442 },443 },444 }, nil)445 testHelper.MockTxHelper.EXPECT().446 ExtractRebalanceEvent("Rebalance", gomock.AssignableToTypeOf(&types.Log{})).447 Return(nil, errors.New("error here"))448 result, err := testHelper.Client.Rebalance(context.Background(), &RebalanceInput{})449 assert.Nil(t, result)450 assert.Error(t, err)451 })452}...
api.pb.go
Source:api.pb.go
...51}5253// Register mocks base method54func (m *MockRegistrationClient) Register(arg0 context.Context, arg1 *v1alpha1.RegisterRequest, arg2 ...grpc.CallOption) (*v1alpha1.Empty, error) {55 m.ctrl.T.Helper()56 varargs := []interface{}{arg0, arg1}57 for _, a := range arg2 {58 varargs = append(varargs, a)59 }60 ret := m.ctrl.Call(m, "Register", varargs...)61 ret0, _ := ret[0].(*v1alpha1.Empty)62 ret1, _ := ret[1].(error)63 return ret0, ret164}6566// Register indicates an expected call of Register67func (mr *MockRegistrationClientMockRecorder) Register(arg0, arg1 interface{}, arg2 ...interface{}) *gomock.Call {68 mr.mock.ctrl.T.Helper()69 varargs := append([]interface{}{arg0, arg1}, arg2...)70 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Register", reflect.TypeOf((*MockRegistrationClient)(nil).Register), varargs...)71}7273// MockRegistrationServer is a mock of RegistrationServer interface74type MockRegistrationServer struct {75 ctrl *gomock.Controller76 recorder *MockRegistrationServerMockRecorder77}7879// MockRegistrationServerMockRecorder is the mock recorder for MockRegistrationServer80type MockRegistrationServerMockRecorder struct {81 mock *MockRegistrationServer82}8384// NewMockRegistrationServer creates a new mock instance85func NewMockRegistrationServer(ctrl *gomock.Controller) *MockRegistrationServer {86 mock := &MockRegistrationServer{ctrl: ctrl}87 mock.recorder = &MockRegistrationServerMockRecorder{mock}88 return mock89}9091// EXPECT returns an object that allows the caller to indicate expected use92func (m *MockRegistrationServer) EXPECT() *MockRegistrationServerMockRecorder {93 return m.recorder94}9596// Register mocks base method97func (m *MockRegistrationServer) Register(arg0 context.Context, arg1 *v1alpha1.RegisterRequest) (*v1alpha1.Empty, error) {98 m.ctrl.T.Helper()99 ret := m.ctrl.Call(m, "Register", arg0, arg1)100 ret0, _ := ret[0].(*v1alpha1.Empty)101 ret1, _ := ret[1].(error)102 return ret0, ret1103}104105// Register indicates an expected call of Register106func (mr *MockRegistrationServerMockRecorder) Register(arg0, arg1 interface{}) *gomock.Call {107 mr.mock.ctrl.T.Helper()108 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Register", reflect.TypeOf((*MockRegistrationServer)(nil).Register), arg0, arg1)109}110111// MockConnectionClient is a mock of ConnectionClient interface112type MockConnectionClient struct {113 ctrl *gomock.Controller114 recorder *MockConnectionClientMockRecorder115}116117// MockConnectionClientMockRecorder is the mock recorder for MockConnectionClient118type MockConnectionClientMockRecorder struct {119 mock *MockConnectionClient120}121122// NewMockConnectionClient creates a new mock instance123func NewMockConnectionClient(ctrl *gomock.Controller) *MockConnectionClient {124 mock := &MockConnectionClient{ctrl: ctrl}125 mock.recorder = &MockConnectionClientMockRecorder{mock}126 return mock127}128129// EXPECT returns an object that allows the caller to indicate expected use130func (m *MockConnectionClient) EXPECT() *MockConnectionClientMockRecorder {131 return m.recorder132}133134// Connect mocks base method135func (m *MockConnectionClient) Connect(arg0 context.Context, arg1 ...grpc.CallOption) (v1alpha1.Connection_ConnectClient, error) {136 m.ctrl.T.Helper()137 varargs := []interface{}{arg0}138 for _, a := range arg1 {139 varargs = append(varargs, a)140 }141 ret := m.ctrl.Call(m, "Connect", varargs...)142 ret0, _ := ret[0].(v1alpha1.Connection_ConnectClient)143 ret1, _ := ret[1].(error)144 return ret0, ret1145}146147// Connect indicates an expected call of Connect148func (mr *MockConnectionClientMockRecorder) Connect(arg0 interface{}, arg1 ...interface{}) *gomock.Call {149 mr.mock.ctrl.T.Helper()150 varargs := append([]interface{}{arg0}, arg1...)151 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Connect", reflect.TypeOf((*MockConnectionClient)(nil).Connect), varargs...)152}153154// MockConnection_ConnectClient is a mock of Connection_ConnectClient interface155type MockConnection_ConnectClient struct {156 ctrl *gomock.Controller157 recorder *MockConnection_ConnectClientMockRecorder158}159160// MockConnection_ConnectClientMockRecorder is the mock recorder for MockConnection_ConnectClient161type MockConnection_ConnectClientMockRecorder struct {162 mock *MockConnection_ConnectClient163}164165// NewMockConnection_ConnectClient creates a new mock instance166func NewMockConnection_ConnectClient(ctrl *gomock.Controller) *MockConnection_ConnectClient {167 mock := &MockConnection_ConnectClient{ctrl: ctrl}168 mock.recorder = &MockConnection_ConnectClientMockRecorder{mock}169 return mock170}171172// EXPECT returns an object that allows the caller to indicate expected use173func (m *MockConnection_ConnectClient) EXPECT() *MockConnection_ConnectClientMockRecorder {174 return m.recorder175}176177// CloseSend mocks base method178func (m *MockConnection_ConnectClient) CloseSend() error {179 m.ctrl.T.Helper()180 ret := m.ctrl.Call(m, "CloseSend")181 ret0, _ := ret[0].(error)182 return ret0183}184185// CloseSend indicates an expected call of CloseSend186func (mr *MockConnection_ConnectClientMockRecorder) CloseSend() *gomock.Call {187 mr.mock.ctrl.T.Helper()188 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CloseSend", reflect.TypeOf((*MockConnection_ConnectClient)(nil).CloseSend))189}190191// Context mocks base method192func (m *MockConnection_ConnectClient) Context() context.Context {193 m.ctrl.T.Helper()194 ret := m.ctrl.Call(m, "Context")195 ret0, _ := ret[0].(context.Context)196 return ret0197}198199// Context indicates an expected call of Context200func (mr *MockConnection_ConnectClientMockRecorder) Context() *gomock.Call {201 mr.mock.ctrl.T.Helper()202 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Context", reflect.TypeOf((*MockConnection_ConnectClient)(nil).Context))203}204205// Header mocks base method206func (m *MockConnection_ConnectClient) Header() (metadata.MD, error) {207 m.ctrl.T.Helper()208 ret := m.ctrl.Call(m, "Header")209 ret0, _ := ret[0].(metadata.MD)210 ret1, _ := ret[1].(error)211 return ret0, ret1212}213214// Header indicates an expected call of Header215func (mr *MockConnection_ConnectClientMockRecorder) Header() *gomock.Call {216 mr.mock.ctrl.T.Helper()217 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Header", reflect.TypeOf((*MockConnection_ConnectClient)(nil).Header))218}219220// Recv mocks base method221func (m *MockConnection_ConnectClient) Recv() (*v1alpha1.ConnectResponse, error) {222 m.ctrl.T.Helper()223 ret := m.ctrl.Call(m, "Recv")224 ret0, _ := ret[0].(*v1alpha1.ConnectResponse)225 ret1, _ := ret[1].(error)226 return ret0, ret1227}228229// Recv indicates an expected call of Recv230func (mr *MockConnection_ConnectClientMockRecorder) Recv() *gomock.Call {231 mr.mock.ctrl.T.Helper()232 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Recv", reflect.TypeOf((*MockConnection_ConnectClient)(nil).Recv))233}234235// RecvMsg mocks base method236func (m *MockConnection_ConnectClient) RecvMsg(arg0 interface{}) error {237 m.ctrl.T.Helper()238 ret := m.ctrl.Call(m, "RecvMsg", arg0)239 ret0, _ := ret[0].(error)240 return ret0241}242243// RecvMsg indicates an expected call of RecvMsg244func (mr *MockConnection_ConnectClientMockRecorder) RecvMsg(arg0 interface{}) *gomock.Call {245 mr.mock.ctrl.T.Helper()246 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecvMsg", reflect.TypeOf((*MockConnection_ConnectClient)(nil).RecvMsg), arg0)247}248249// Send mocks base method250func (m *MockConnection_ConnectClient) Send(arg0 *v1alpha1.ConnectRequest) error {251 m.ctrl.T.Helper()252 ret := m.ctrl.Call(m, "Send", arg0)253 ret0, _ := ret[0].(error)254 return ret0255}256257// Send indicates an expected call of Send258func (mr *MockConnection_ConnectClientMockRecorder) Send(arg0 interface{}) *gomock.Call {259 mr.mock.ctrl.T.Helper()260 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockConnection_ConnectClient)(nil).Send), arg0)261}262263// SendMsg mocks base method264func (m *MockConnection_ConnectClient) SendMsg(arg0 interface{}) error {265 m.ctrl.T.Helper()266 ret := m.ctrl.Call(m, "SendMsg", arg0)267 ret0, _ := ret[0].(error)268 return ret0269}270271// SendMsg indicates an expected call of SendMsg272func (mr *MockConnection_ConnectClientMockRecorder) SendMsg(arg0 interface{}) *gomock.Call {273 mr.mock.ctrl.T.Helper()274 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMsg", reflect.TypeOf((*MockConnection_ConnectClient)(nil).SendMsg), arg0)275}276277// Trailer mocks base method278func (m *MockConnection_ConnectClient) Trailer() metadata.MD {279 m.ctrl.T.Helper()280 ret := m.ctrl.Call(m, "Trailer")281 ret0, _ := ret[0].(metadata.MD)282 return ret0283}284285// Trailer indicates an expected call of Trailer286func (mr *MockConnection_ConnectClientMockRecorder) Trailer() *gomock.Call {287 mr.mock.ctrl.T.Helper()288 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Trailer", reflect.TypeOf((*MockConnection_ConnectClient)(nil).Trailer))289}290291// MockConnectionServer is a mock of ConnectionServer interface292type MockConnectionServer struct {293 ctrl *gomock.Controller294 recorder *MockConnectionServerMockRecorder295}296297// MockConnectionServerMockRecorder is the mock recorder for MockConnectionServer298type MockConnectionServerMockRecorder struct {299 mock *MockConnectionServer300}301302// NewMockConnectionServer creates a new mock instance303func NewMockConnectionServer(ctrl *gomock.Controller) *MockConnectionServer {304 mock := &MockConnectionServer{ctrl: ctrl}305 mock.recorder = &MockConnectionServerMockRecorder{mock}306 return mock307}308309// EXPECT returns an object that allows the caller to indicate expected use310func (m *MockConnectionServer) EXPECT() *MockConnectionServerMockRecorder {311 return m.recorder312}313314// Connect mocks base method315func (m *MockConnectionServer) Connect(arg0 v1alpha1.Connection_ConnectServer) error {316 m.ctrl.T.Helper()317 ret := m.ctrl.Call(m, "Connect", arg0)318 ret0, _ := ret[0].(error)319 return ret0320}321322// Connect indicates an expected call of Connect323func (mr *MockConnectionServerMockRecorder) Connect(arg0 interface{}) *gomock.Call {324 mr.mock.ctrl.T.Helper()325 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Connect", reflect.TypeOf((*MockConnectionServer)(nil).Connect), arg0)326}327328// MockConnection_ConnectServer is a mock of Connection_ConnectServer interface329type MockConnection_ConnectServer struct {330 ctrl *gomock.Controller331 recorder *MockConnection_ConnectServerMockRecorder332}333334// MockConnection_ConnectServerMockRecorder is the mock recorder for MockConnection_ConnectServer335type MockConnection_ConnectServerMockRecorder struct {336 mock *MockConnection_ConnectServer337}338339// NewMockConnection_ConnectServer creates a new mock instance340func NewMockConnection_ConnectServer(ctrl *gomock.Controller) *MockConnection_ConnectServer {341 mock := &MockConnection_ConnectServer{ctrl: ctrl}342 mock.recorder = &MockConnection_ConnectServerMockRecorder{mock}343 return mock344}345346// EXPECT returns an object that allows the caller to indicate expected use347func (m *MockConnection_ConnectServer) EXPECT() *MockConnection_ConnectServerMockRecorder {348 return m.recorder349}350351// Context mocks base method352func (m *MockConnection_ConnectServer) Context() context.Context {353 m.ctrl.T.Helper()354 ret := m.ctrl.Call(m, "Context")355 ret0, _ := ret[0].(context.Context)356 return ret0357}358359// Context indicates an expected call of Context360func (mr *MockConnection_ConnectServerMockRecorder) Context() *gomock.Call {361 mr.mock.ctrl.T.Helper()362 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Context", reflect.TypeOf((*MockConnection_ConnectServer)(nil).Context))363}364365// Recv mocks base method366func (m *MockConnection_ConnectServer) Recv() (*v1alpha1.ConnectRequest, error) {367 m.ctrl.T.Helper()368 ret := m.ctrl.Call(m, "Recv")369 ret0, _ := ret[0].(*v1alpha1.ConnectRequest)370 ret1, _ := ret[1].(error)371 return ret0, ret1372}373374// Recv indicates an expected call of Recv375func (mr *MockConnection_ConnectServerMockRecorder) Recv() *gomock.Call {376 mr.mock.ctrl.T.Helper()377 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Recv", reflect.TypeOf((*MockConnection_ConnectServer)(nil).Recv))378}379380// RecvMsg mocks base method381func (m *MockConnection_ConnectServer) RecvMsg(arg0 interface{}) error {382 m.ctrl.T.Helper()383 ret := m.ctrl.Call(m, "RecvMsg", arg0)384 ret0, _ := ret[0].(error)385 return ret0386}387388// RecvMsg indicates an expected call of RecvMsg389func (mr *MockConnection_ConnectServerMockRecorder) RecvMsg(arg0 interface{}) *gomock.Call {390 mr.mock.ctrl.T.Helper()391 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RecvMsg", reflect.TypeOf((*MockConnection_ConnectServer)(nil).RecvMsg), arg0)392}393394// Send mocks base method395func (m *MockConnection_ConnectServer) Send(arg0 *v1alpha1.ConnectResponse) error {396 m.ctrl.T.Helper()397 ret := m.ctrl.Call(m, "Send", arg0)398 ret0, _ := ret[0].(error)399 return ret0400}401402// Send indicates an expected call of Send403func (mr *MockConnection_ConnectServerMockRecorder) Send(arg0 interface{}) *gomock.Call {404 mr.mock.ctrl.T.Helper()405 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Send", reflect.TypeOf((*MockConnection_ConnectServer)(nil).Send), arg0)406}407408// SendHeader mocks base method409func (m *MockConnection_ConnectServer) SendHeader(arg0 metadata.MD) error {410 m.ctrl.T.Helper()411 ret := m.ctrl.Call(m, "SendHeader", arg0)412 ret0, _ := ret[0].(error)413 return ret0414}415416// SendHeader indicates an expected call of SendHeader417func (mr *MockConnection_ConnectServerMockRecorder) SendHeader(arg0 interface{}) *gomock.Call {418 mr.mock.ctrl.T.Helper()419 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendHeader", reflect.TypeOf((*MockConnection_ConnectServer)(nil).SendHeader), arg0)420}421422// SendMsg mocks base method423func (m *MockConnection_ConnectServer) SendMsg(arg0 interface{}) error {424 m.ctrl.T.Helper()425 ret := m.ctrl.Call(m, "SendMsg", arg0)426 ret0, _ := ret[0].(error)427 return ret0428}429430// SendMsg indicates an expected call of SendMsg431func (mr *MockConnection_ConnectServerMockRecorder) SendMsg(arg0 interface{}) *gomock.Call {432 mr.mock.ctrl.T.Helper()433 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendMsg", reflect.TypeOf((*MockConnection_ConnectServer)(nil).SendMsg), arg0)434}435436// SetHeader mocks base method437func (m *MockConnection_ConnectServer) SetHeader(arg0 metadata.MD) error {438 m.ctrl.T.Helper()439 ret := m.ctrl.Call(m, "SetHeader", arg0)440 ret0, _ := ret[0].(error)441 return ret0442}443444// SetHeader indicates an expected call of SetHeader445func (mr *MockConnection_ConnectServerMockRecorder) SetHeader(arg0 interface{}) *gomock.Call {446 mr.mock.ctrl.T.Helper()447 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetHeader", reflect.TypeOf((*MockConnection_ConnectServer)(nil).SetHeader), arg0)448}449450// SetTrailer mocks base method451func (m *MockConnection_ConnectServer) SetTrailer(arg0 metadata.MD) {452 m.ctrl.T.Helper()453 m.ctrl.Call(m, "SetTrailer", arg0)454}455456// SetTrailer indicates an expected call of SetTrailer457func (mr *MockConnection_ConnectServerMockRecorder) SetTrailer(arg0 interface{}) *gomock.Call {458 mr.mock.ctrl.T.Helper()459 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SetTrailer", reflect.TypeOf((*MockConnection_ConnectServer)(nil).SetTrailer), arg0)460}
...
mock_record.go
Source:mock_record.go
...40 return m.recorder41}42// AddInfoElement mocks base method43func (m *MockRecord) AddInfoElement(arg0 entities.InfoElementWithValue) error {44 m.ctrl.T.Helper()45 ret := m.ctrl.Call(m, "AddInfoElement", arg0)46 ret0, _ := ret[0].(error)47 return ret048}49// AddInfoElement indicates an expected call of AddInfoElement50func (mr *MockRecordMockRecorder) AddInfoElement(arg0 interface{}) *gomock.Call {51 mr.mock.ctrl.T.Helper()52 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddInfoElement", reflect.TypeOf((*MockRecord)(nil).AddInfoElement), arg0)53}54// GetBuffer mocks base method55func (m *MockRecord) GetBuffer() []byte {56 m.ctrl.T.Helper()57 ret := m.ctrl.Call(m, "GetBuffer")58 ret0, _ := ret[0].([]byte)59 return ret060}61// GetBuffer indicates an expected call of GetBuffer62func (mr *MockRecordMockRecorder) GetBuffer() *gomock.Call {63 mr.mock.ctrl.T.Helper()64 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBuffer", reflect.TypeOf((*MockRecord)(nil).GetBuffer))65}66// GetElementMap mocks base method67func (m *MockRecord) GetElementMap() map[string]interface{} {68 m.ctrl.T.Helper()69 ret := m.ctrl.Call(m, "GetElementMap")70 ret0, _ := ret[0].(map[string]interface{})71 return ret072}73// GetElementMap indicates an expected call of GetElementMap74func (mr *MockRecordMockRecorder) GetElementMap() *gomock.Call {75 mr.mock.ctrl.T.Helper()76 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetElementMap", reflect.TypeOf((*MockRecord)(nil).GetElementMap))77}78// GetFieldCount mocks base method79func (m *MockRecord) GetFieldCount() uint16 {80 m.ctrl.T.Helper()81 ret := m.ctrl.Call(m, "GetFieldCount")82 ret0, _ := ret[0].(uint16)83 return ret084}85// GetFieldCount indicates an expected call of GetFieldCount86func (mr *MockRecordMockRecorder) GetFieldCount() *gomock.Call {87 mr.mock.ctrl.T.Helper()88 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFieldCount", reflect.TypeOf((*MockRecord)(nil).GetFieldCount))89}90// GetInfoElementWithValue mocks base method91func (m *MockRecord) GetInfoElementWithValue(arg0 string) (entities.InfoElementWithValue, int, bool) {92 m.ctrl.T.Helper()93 ret := m.ctrl.Call(m, "GetInfoElementWithValue", arg0)94 ret0, _ := ret[0].(entities.InfoElementWithValue)95 ret1, _ := ret[1].(int)96 ret2, _ := ret[2].(bool)97 return ret0, ret1, ret298}99// GetInfoElementWithValue indicates an expected call of GetInfoElementWithValue100func (mr *MockRecordMockRecorder) GetInfoElementWithValue(arg0 interface{}) *gomock.Call {101 mr.mock.ctrl.T.Helper()102 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetInfoElementWithValue", reflect.TypeOf((*MockRecord)(nil).GetInfoElementWithValue), arg0)103}104// GetMinDataRecordLen mocks base method105func (m *MockRecord) GetMinDataRecordLen() uint16 {106 m.ctrl.T.Helper()107 ret := m.ctrl.Call(m, "GetMinDataRecordLen")108 ret0, _ := ret[0].(uint16)109 return ret0110}111// GetMinDataRecordLen indicates an expected call of GetMinDataRecordLen112func (mr *MockRecordMockRecorder) GetMinDataRecordLen() *gomock.Call {113 mr.mock.ctrl.T.Helper()114 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMinDataRecordLen", reflect.TypeOf((*MockRecord)(nil).GetMinDataRecordLen))115}116// GetOrderedElementList mocks base method117func (m *MockRecord) GetOrderedElementList() []entities.InfoElementWithValue {118 m.ctrl.T.Helper()119 ret := m.ctrl.Call(m, "GetOrderedElementList")120 ret0, _ := ret[0].([]entities.InfoElementWithValue)121 return ret0122}123// GetOrderedElementList indicates an expected call of GetOrderedElementList124func (mr *MockRecordMockRecorder) GetOrderedElementList() *gomock.Call {125 mr.mock.ctrl.T.Helper()126 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetOrderedElementList", reflect.TypeOf((*MockRecord)(nil).GetOrderedElementList))127}128// GetRecordLength mocks base method129func (m *MockRecord) GetRecordLength() int {130 m.ctrl.T.Helper()131 ret := m.ctrl.Call(m, "GetRecordLength")132 ret0, _ := ret[0].(int)133 return ret0134}135// GetRecordLength indicates an expected call of GetRecordLength136func (mr *MockRecordMockRecorder) GetRecordLength() *gomock.Call {137 mr.mock.ctrl.T.Helper()138 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetRecordLength", reflect.TypeOf((*MockRecord)(nil).GetRecordLength))139}140// GetTemplateID mocks base method141func (m *MockRecord) GetTemplateID() uint16 {142 m.ctrl.T.Helper()143 ret := m.ctrl.Call(m, "GetTemplateID")144 ret0, _ := ret[0].(uint16)145 return ret0146}147// GetTemplateID indicates an expected call of GetTemplateID148func (mr *MockRecordMockRecorder) GetTemplateID() *gomock.Call {149 mr.mock.ctrl.T.Helper()150 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTemplateID", reflect.TypeOf((*MockRecord)(nil).GetTemplateID))151}152// PrepareRecord mocks base method153func (m *MockRecord) PrepareRecord() error {154 m.ctrl.T.Helper()155 ret := m.ctrl.Call(m, "PrepareRecord")156 ret0, _ := ret[0].(error)157 return ret0158}159// PrepareRecord indicates an expected call of PrepareRecord160func (mr *MockRecordMockRecorder) PrepareRecord() *gomock.Call {161 mr.mock.ctrl.T.Helper()162 return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PrepareRecord", reflect.TypeOf((*MockRecord)(nil).PrepareRecord))163}...
Helper
Using AI Code Generation
1import (2func TestHelper(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 mock := mocking.NewMockInterface(ctrl)6 mock.Helper()7 fmt.Println("Hello World")8}
Helper
Using AI Code Generation
1func (m *MockMyInterface) Helper() {2 m.ctrl.Helper()3}4func (m *MockMyInterface) Helper() {5 m.ctrl.Helper()6}7import (8func TestGet(t *testing.T) {9 db, mock, err := sqlmock.New()10 if err != nil {11 t.Fatalf("error opening a stub database connection: %s", err)12 }13 defer db.Close()14 rows := sqlmock.NewRows([]string{"id", "name"}).AddRow(1, "test")15 mock.ExpectQuery("SELECT (.+) FROM users WHERE id = ?").WillReturnRows(rows)16 err = db.QueryRow("SELECT id, name FROM users WHERE id = ?", id).Scan(&id, &name)17 if err != nil {18 t.Fatalf("error while querying database: %s", err)19 }20 assert.Equal(t, name, "test")21}22--- FAIL: TestGet (0.00s)23testing.tRunner.func1(0xc0000c6100)24panic(0x5f9c00, 0xc0000b2020)25database/sql.(*Rows).Scan(0xc0000b2000, 0xc0000b6000, 0x1, 0x1, 0x0, 0
Helper
Using AI Code Generation
1import (2func main() {3 ctrl := gomock.NewController(nil)4 defer ctrl.Finish()5 mock := gomocktest.NewMockHelper(ctrl)6 mock.EXPECT().Get(1).Return("one")7 mock.EXPECT().Get(2).Return("two")8 mock.EXPECT().Get(3).Return("three")9 mock.EXPECT().Get(4).Return("four")10 mock.EXPECT().Get(5).Return("five")11 mock.EXPECT().Get(6).Return("six")12 mock.EXPECT().Get(7).Return("seven")13 mock.EXPECT().Get(8).Return("eight")14 mock.EXPECT().Get(9).Return("nine")15 mock.EXPECT().Get(10).Return("ten")16 fmt.Println(mock.Get(1))17 fmt.Println(mock.Get(2))18 fmt.Println(mock.Get(3))19 fmt.Println(mock.Get(4))20 fmt.Println(mock.Get(5))21 fmt.Println(mock.Get(6))22 fmt.Println(mock.Get(7))23 fmt.Println(mock.Get(8))24 fmt.Println(mock.Get(9))25 fmt.Println(mock.Get(10))26}27--- PASS: TestHelper_Get (0.00s)
Helper
Using AI Code Generation
1func TestSomething(t *testing.T) {2 mockCtrl := gomock.NewController(t)3 defer mockCtrl.Finish()4 mockFoo := NewMockFoo(mockCtrl)5 mockFoo.EXPECT().Bar().Return(1)6 mockFoo.EXPECT().Baz().Return(2)7 mockFoo.EXPECT().Baz().Return(3)8 mockFoo.EXPECT().Baz().Return(4)9 mockFoo.EXPECT().Baz().Return(5)10 mockFoo.EXPECT().Baz().Return(6)11 mockFoo.EXPECT().Baz().Return(7)12 mockFoo.EXPECT().Baz().Return(8)13 mockFoo.EXPECT().Baz().Return(9)14 mockFoo.EXPECT().Baz().Return(10)15 mockFoo.EXPECT().Baz().Return(11)16 mockFoo.EXPECT().Baz().Return(12)17 mockFoo.EXPECT().Baz().Return(13)18 mockFoo.EXPECT().Baz().Return(14)19 mockFoo.EXPECT().Baz().Return(15)20 mockFoo.EXPECT().Baz().Return(16)21 mockFoo.EXPECT().Baz().Return(17)22 mockFoo.EXPECT().Baz().Return(18)23 mockFoo.EXPECT().Baz().Return(19)24 mockFoo.EXPECT().Baz().Return(20)25 mockFoo.EXPECT().Baz().Return(21)26 mockFoo.EXPECT().Baz().Return(22)27 mockFoo.EXPECT().Baz().Return(23)28 mockFoo.EXPECT().Baz().Return(24)29 mockFoo.EXPECT().Baz().Return(25)30 mockFoo.EXPECT().Baz().Return(26)31 mockFoo.EXPECT().Baz().Return(27)32 mockFoo.EXPECT().Baz().Return(28)33 mockFoo.EXPECT().Baz().Return(29)34 mockFoo.EXPECT().Baz().Return(30)35 mockFoo.EXPECT().Baz().Return(31)36 mockFoo.EXPECT().Baz().Return(32)37 mockFoo.EXPECT().Baz().Return(33)38 mockFoo.EXPECT().Baz().Return(34)39 mockFoo.EXPECT().Baz().Return(35)40 mockFoo.EXPECT().B
Helper
Using AI Code Generation
1func Test(t *testing.T) {2 mockCtrl := gomock.NewController(t)3 defer mockCtrl.Finish()4 mockDB := NewMockDB(mockCtrl)5 mockDB.EXPECT().Query(gomock.Any()).Return(nil)6 helper := Helper{DB: mockDB}7 helper.Run()8}9type Helper struct {10}11func (h *Helper) Run() {12 h.DB.Query("SELECT * FROM users")13}14type DB interface {15 Query(query string) error16}17type DBImpl struct{}18func (d *DBImpl) Query(query string) error {19}20type MockDB struct {21}22func (m *MockDB) Query(query string) error {23 ret := m.Called(query)24 return ret.Error(0)25}26package main import ( "fmt" "testing" ) func TestGeneric(t *testing.T) { var tests = []struct { name string f func() int }{ {"one", func() int { return 1 }}, {"two", func() int { return 2 }}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := tt.f() if got != 1 { t.Errorf("got %v, want %v", got, 1) } }) } } func TestOne(t *testing.T) { got := one() if got != 1 { t.Errorf("got %v, want %v", got, 1) } } func TestTwo(t *testing.T) { got := two() if got != 2 { t.Errorf("got %
Helper
Using AI Code Generation
1import (2func TestMock(t *testing.T) {3 ctrl := gomock.NewController(t)4 defer ctrl.Finish()5 mock := NewMockHelper(ctrl)6 mock.EXPECT().Helper().Return("hello")7 result := mock.Helper()8 assert.Equal(t, "hello", result, "should be equal")9}10import "fmt"11type Helper interface {12 Helper() string13}14type MockHelper struct{}15func (m *MockHelper) Helper() string {16 fmt.Println("Mocking Helper")17}18func NewMockHelper() Helper {19 return &MockHelper{}20}21import "fmt"22type Helper interface {23 Helper() string24}25type MockHelper struct{}26func (m *MockHelper) Helper() string {27 fmt.Println("Mocking Helper")28}29func NewMockHelper() Helper {30 return &MockHelper{}31}32import "fmt"33type Helper interface {34 Helper() string35}36type MockHelper struct{}37func (m *MockHelper) Helper() string {38 fmt.Println("Mocking Helper")39}40func NewMockHelper() Helper {41 return &MockHelper{}42}43import "fmt"44type Helper interface {45 Helper() string46}47type MockHelper struct{}48func (m *MockHelper) Helper() string {49 fmt.Println("Mocking Helper")50}51func NewMockHelper() Helper {52 return &MockHelper{}53}54import "fmt"55type Helper interface {56 Helper() string57}58type MockHelper struct{}59func (m *MockHelper) Helper() string {60 fmt.Println("Mocking Helper")
Helper
Using AI Code Generation
1func TestGet(t *testing.T) {2 ctrl := gomock.NewController(t)3 defer ctrl.Finish()4 mock := NewMockHelper(ctrl)5 mock.EXPECT().Get("foo").Return("bar", nil)6}7type Helper struct {8}9func (h *Helper) Get(key string) (string, error) {10}11func TestGet(t *testing.T) {12 ctrl := gomock.NewController(t)13 defer ctrl.Finish()14 mock := NewMockHelper(ctrl)15 mock.EXPECT().Get("foo").Return("bar", nil)16}17import (18type Foo struct {19}20func (f *Foo) Bar() {21 fmt.Println("Hello, world!")22}23func NewFoo(name string) *Foo {24 return &Foo{25 }26}27func TestFoo_Bar(t *testing.T) {28 ctrl := gomock.NewController(t)29 defer ctrl.Finish()30 mock := NewMockFoo(ctrl)31 mock.EXPECT().Bar().Return()32 mock.Bar()33}34func TestFoo_Bar2(t *testing.T) {35 foo := NewFoo("test")36 foo.Bar()37}38--- FAIL: TestFoo_Bar2 (0.00s)39testing.tRunner.func1(0xc0000d6000)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!