|
| 1 | +// The Licensed Work is (c) 2022 Sygma |
| 2 | +// SPDX-License-Identifier: LGPL-3.0-only |
| 3 | + |
| 4 | +package lighter_test |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/ethereum/go-ethereum/common" |
| 10 | + solverConfig "github.com/sprintertech/solver-config/go/config" |
| 11 | + "github.com/sprintertech/sprinter-signing/chains/lighter" |
| 12 | + "github.com/stretchr/testify/suite" |
| 13 | +) |
| 14 | + |
| 15 | +type NewLighterConfigTestSuite struct { |
| 16 | + suite.Suite |
| 17 | +} |
| 18 | + |
| 19 | +func TestRunNewLighterConfigTestSuite(t *testing.T) { |
| 20 | + suite.Run(t, new(NewLighterConfigTestSuite)) |
| 21 | +} |
| 22 | + |
| 23 | +func (s *NewLighterConfigTestSuite) Test_ArbitrumNotConfigured() { |
| 24 | + solverChains := make(map[string]solverConfig.Chain) |
| 25 | + _, err := lighter.NewLighterConfig(solverConfig.SolverConfig{ |
| 26 | + Chains: solverChains, |
| 27 | + ProtocolsMetadata: solverConfig.ProtocolsMetadata{}, |
| 28 | + }) |
| 29 | + |
| 30 | + s.NotNil(err) |
| 31 | +} |
| 32 | + |
| 33 | +func (s *NewLighterConfigTestSuite) Test_UsdcNotConfigured() { |
| 34 | + solverChains := make(map[string]solverConfig.Chain) |
| 35 | + solverChains["eip155:42161"] = solverConfig.Chain{} |
| 36 | + |
| 37 | + _, err := lighter.NewLighterConfig(solverConfig.SolverConfig{ |
| 38 | + Chains: solverChains, |
| 39 | + ProtocolsMetadata: solverConfig.ProtocolsMetadata{}, |
| 40 | + }) |
| 41 | + |
| 42 | + s.NotNil(err) |
| 43 | +} |
| 44 | + |
| 45 | +func (s *NewLighterConfigTestSuite) Test_WithdrawalAddressNotConfigured() { |
| 46 | + tokens := make(map[string]solverConfig.Token) |
| 47 | + tokens["usdc"] = solverConfig.Token{ |
| 48 | + Address: "address", |
| 49 | + Decimals: 6, |
| 50 | + } |
| 51 | + |
| 52 | + solverChains := make(map[string]solverConfig.Chain) |
| 53 | + solverChains["eip155:42161"] = solverConfig.Chain{ |
| 54 | + Tokens: tokens, |
| 55 | + } |
| 56 | + |
| 57 | + _, err := lighter.NewLighterConfig(solverConfig.SolverConfig{ |
| 58 | + Chains: solverChains, |
| 59 | + ProtocolsMetadata: solverConfig.ProtocolsMetadata{ |
| 60 | + Lighter: &solverConfig.Lighter{}, |
| 61 | + }, |
| 62 | + }) |
| 63 | + |
| 64 | + s.NotNil(err) |
| 65 | +} |
| 66 | + |
| 67 | +func (s *NewLighterConfigTestSuite) Test_ValidConfig() { |
| 68 | + tokens := make(map[string]solverConfig.Token) |
| 69 | + tokens["usdc"] = solverConfig.Token{ |
| 70 | + Address: "usdc", |
| 71 | + Decimals: 6, |
| 72 | + } |
| 73 | + |
| 74 | + solverChains := make(map[string]solverConfig.Chain) |
| 75 | + solverChains["eip155:42161"] = solverConfig.Chain{ |
| 76 | + Tokens: tokens, |
| 77 | + } |
| 78 | + |
| 79 | + config, err := lighter.NewLighterConfig(solverConfig.SolverConfig{ |
| 80 | + Chains: solverChains, |
| 81 | + ProtocolsMetadata: solverConfig.ProtocolsMetadata{ |
| 82 | + Lighter: &solverConfig.Lighter{ |
| 83 | + FastWithdrawalContract: map[string]string{ |
| 84 | + "eip155:42161": "withdrawal", |
| 85 | + }, |
| 86 | + }, |
| 87 | + }, |
| 88 | + }) |
| 89 | + |
| 90 | + s.Nil(err) |
| 91 | + s.Equal(config, &lighter.LighterConfig{ |
| 92 | + WithdrawalAddress: common.HexToAddress("withdrawal"), |
| 93 | + UsdcAddress: common.HexToAddress("usdc"), |
| 94 | + }) |
| 95 | +} |
0 commit comments