From c3038e04eda0e426fb2820a18240212f100aa295 Mon Sep 17 00:00:00 2001 From: Daniel Wasserman Date: Fri, 10 May 2024 11:49:39 -0500 Subject: [PATCH] Feat: add new test case for mismatched methods but existing rebalance --- .../rfq/relayer/inventory/manager_test.go | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/services/rfq/relayer/inventory/manager_test.go b/services/rfq/relayer/inventory/manager_test.go index db2ce7bc8e..be8b4ba49e 100644 --- a/services/rfq/relayer/inventory/manager_test.go +++ b/services/rfq/relayer/inventory/manager_test.go @@ -67,18 +67,21 @@ func (i *InventoryTestSuite) TestGetRebalance() { Decimals: 6, ChainID: origin, Addr: common.HexToAddress("0x0000000000000000000000000000000000000123"), + Balance: big.NewInt(0), } usdcDataDest := inventory.TokenMetadata{ Name: "USDC", Decimals: 6, ChainID: dest, Addr: common.HexToAddress("0x0000000000000000000000000000000000000456"), + Balance: big.NewInt(0), } usdcDataExtra := inventory.TokenMetadata{ Name: "USDC", Decimals: 6, ChainID: extra, Addr: common.HexToAddress("0x0000000000000000000000000000000000000789"), + Balance: big.NewInt(0), } tokens := map[int]map[common.Address]*inventory.TokenMetadata{ origin: { @@ -88,6 +91,17 @@ func (i *InventoryTestSuite) TestGetRebalance() { usdcDataDest.Addr: &usdcDataDest, }, } + tokensWithExtra := map[int]map[common.Address]*inventory.TokenMetadata{ + origin: { + usdcDataOrigin.Addr: &usdcDataOrigin, + }, + dest: { + usdcDataDest.Addr: &usdcDataDest, + }, + extra: { + usdcDataExtra.Addr: &usdcDataExtra, + }, + } getConfig := func(minRebalanceAmount, maxRebalanceAmount string, originMethod, destMethod relconfig.RebalanceMethod) relconfig.Config { return relconfig.Config{ Chains: map[int]relconfig.ChainConfig{ @@ -199,6 +213,64 @@ func (i *InventoryTestSuite) TestGetRebalance() { rebalance, err = inventory.GetRebalance(cfg, tokens, dest, usdcDataDest.Addr) i.NoError(err) i.Nil(rebalance) + + // Set origin as lowest balance, but mismatched rebalance method, so next lowest balance + // should be chosen + cfg = relconfig.Config{ + Chains: map[int]relconfig.ChainConfig{ + origin: { + Tokens: map[string]relconfig.TokenConfig{ + "USDC": { + Address: usdcDataOrigin.Addr.Hex(), + Decimals: 6, + MaintenanceBalancePct: 20, + InitialBalancePct: 40, + MinRebalanceAmount: "", + MaxRebalanceAmount: "", + RebalanceMethod: "synapsecctp", + }, + }, + }, + dest: { + Tokens: map[string]relconfig.TokenConfig{ + "USDC": { + Address: usdcDataDest.Addr.Hex(), + Decimals: 6, + MaintenanceBalancePct: 20, + InitialBalancePct: 40, + MinRebalanceAmount: "", + MaxRebalanceAmount: "", + RebalanceMethod: "circlecctp", + }, + }, + }, + extra: { + Tokens: map[string]relconfig.TokenConfig{ + "USDC": { + Address: usdcDataExtra.Addr.Hex(), + Decimals: 6, + MaintenanceBalancePct: 20, + InitialBalancePct: 40, + MinRebalanceAmount: "", + MaxRebalanceAmount: "", + RebalanceMethod: "circlecctp", + }, + }, + }, + }, + } + usdcDataOrigin.Balance = big.NewInt(0) + usdcDataDest.Balance = big.NewInt(1e6) + usdcDataExtra.Balance = big.NewInt(9e6) + rebalance, err = inventory.GetRebalance(cfg, tokensWithExtra, dest, usdcDataDest.Addr) + i.NoError(err) + expected = &inventory.RebalanceData{ + OriginMetadata: &usdcDataExtra, + DestMetadata: &usdcDataDest, + Amount: big.NewInt(5e6), + Method: relconfig.RebalanceMethodCircleCCTP, + } + i.Equal(expected, rebalance) } func (i *InventoryTestSuite) TestHasSufficientGas() {