|
| 1 | +package evm |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | +) |
| 10 | + |
| 11 | +func TestNewDecodedOperation(t *testing.T) { |
| 12 | + t.Parallel() |
| 13 | + |
| 14 | + tests := []struct { |
| 15 | + name string |
| 16 | + functionName string |
| 17 | + inputKeys []string |
| 18 | + inputArgs []any |
| 19 | + wantErr string |
| 20 | + }{ |
| 21 | + { |
| 22 | + name: "success", |
| 23 | + functionName: "functionName", |
| 24 | + inputKeys: []string{"inputKey1", "inputKey2"}, |
| 25 | + inputArgs: []any{"inputArg1", "inputArg2"}, |
| 26 | + }, |
| 27 | + { |
| 28 | + name: "success with empty input keys and args", |
| 29 | + functionName: "functionName", |
| 30 | + inputKeys: []string{}, |
| 31 | + inputArgs: []any{}, |
| 32 | + }, |
| 33 | + { |
| 34 | + name: "error with mismatched input keys and args", |
| 35 | + functionName: "functionName", |
| 36 | + inputKeys: []string{"inputKey1", "inputKey2"}, |
| 37 | + inputArgs: []any{"inputArg1"}, |
| 38 | + wantErr: "input keys and input args must have the same length", |
| 39 | + }, |
| 40 | + } |
| 41 | + |
| 42 | + for _, tt := range tests { |
| 43 | + t.Run(tt.name, func(t *testing.T) { |
| 44 | + t.Parallel() |
| 45 | + |
| 46 | + got, err := NewDecodedOperation(tt.functionName, tt.inputKeys, tt.inputArgs) |
| 47 | + if tt.wantErr != "" { |
| 48 | + require.Error(t, err) |
| 49 | + assert.EqualError(t, err, tt.wantErr) |
| 50 | + } else { |
| 51 | + require.NoError(t, err) |
| 52 | + assert.Equal(t, tt.functionName, got.FunctionName) |
| 53 | + assert.Equal(t, tt.inputKeys, got.InputKeys) |
| 54 | + assert.Equal(t, tt.inputArgs, got.InputArgs) |
| 55 | + |
| 56 | + // Test member functions |
| 57 | + assert.Equal(t, tt.functionName, got.MethodName()) |
| 58 | + assert.Equal(t, tt.inputKeys, got.Keys()) |
| 59 | + assert.Equal(t, tt.inputArgs, got.Args()) |
| 60 | + |
| 61 | + // Test String() |
| 62 | + fn, inputs, err := got.String() |
| 63 | + require.NoError(t, err) |
| 64 | + assert.Equal(t, tt.functionName, fn) |
| 65 | + for i := range tt.inputKeys { |
| 66 | + assert.Contains(t, inputs, fmt.Sprintf(`"%s": "%v"`, tt.inputKeys[i], tt.inputArgs[i])) |
| 67 | + } |
| 68 | + } |
| 69 | + }) |
| 70 | + } |
| 71 | +} |
0 commit comments