|
| 1 | +package paymaster |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/NethermindEth/starknet.go/internal/tests" |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | + "github.com/stretchr/testify/require" |
| 11 | + "go.uber.org/mock/gomock" |
| 12 | +) |
| 13 | + |
| 14 | +// Test the 'paymaster_getSupportedTokens' method |
| 15 | +func TestGetSupportedTokens(t *testing.T) { |
| 16 | + t.Parallel() |
| 17 | + t.Run("integration", func(t *testing.T) { |
| 18 | + tests.RunTestOn(t, tests.IntegrationEnv) |
| 19 | + t.Parallel() |
| 20 | + |
| 21 | + pm, spy := SetupPaymaster(t) |
| 22 | + tokens, err := pm.GetSupportedTokens(context.Background()) |
| 23 | + require.NoError(t, err) |
| 24 | + |
| 25 | + rawResult, err := json.Marshal(tokens) |
| 26 | + require.NoError(t, err) |
| 27 | + assert.EqualValues(t, spy.LastResponse(), rawResult) |
| 28 | + }) |
| 29 | + |
| 30 | + t.Run("mock", func(t *testing.T) { |
| 31 | + tests.RunTestOn(t, tests.MockEnv) |
| 32 | + t.Parallel() |
| 33 | + |
| 34 | + pm := SetupMockPaymaster(t) |
| 35 | + |
| 36 | + expectedRawResult := `[ |
| 37 | + { |
| 38 | + "token_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", |
| 39 | + "decimals": 18, |
| 40 | + "price_in_strk": "0x288aa92ed8c5539ae80" |
| 41 | + }, |
| 42 | + { |
| 43 | + "token_address": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", |
| 44 | + "decimals": 18, |
| 45 | + "price_in_strk": "0xde0b6b3a7640000" |
| 46 | + }, |
| 47 | + { |
| 48 | + "token_address": "0x53b40a647cedfca6ca84f542a0fe36736031905a9639a7f19a3c1e66bfd5080", |
| 49 | + "decimals": 6, |
| 50 | + "price_in_strk": "0x48e1ecdbbe883b08" |
| 51 | + }, |
| 52 | + { |
| 53 | + "token_address": "0x30058f19ed447208015f6430f0102e8ab82d6c291566d7e73fe8e613c3d2ed", |
| 54 | + "decimals": 6, |
| 55 | + "price_in_strk": "0x2c3460a7992f8a" |
| 56 | + } |
| 57 | + ]` |
| 58 | + |
| 59 | + var expectedResult []TokenData |
| 60 | + err := json.Unmarshal([]byte(expectedRawResult), &expectedResult) |
| 61 | + require.NoError(t, err) |
| 62 | + |
| 63 | + pm.c.EXPECT(). |
| 64 | + CallContextWithSliceArgs(context.Background(), gomock.AssignableToTypeOf(new([]TokenData)), "paymaster_getSupportedTokens"). |
| 65 | + SetArg(1, expectedResult). |
| 66 | + Return(nil) |
| 67 | + result, err := pm.GetSupportedTokens(context.Background()) |
| 68 | + assert.NoError(t, err) |
| 69 | + assert.Equal(t, expectedResult, result) |
| 70 | + |
| 71 | + rawResult, err := json.Marshal(result) |
| 72 | + require.NoError(t, err) |
| 73 | + assert.JSONEq(t, expectedRawResult, string(rawResult)) |
| 74 | + }) |
| 75 | +} |
0 commit comments