diff --git a/core/services/pipeline/task.divide_test.go b/core/services/pipeline/task.divide_test.go index a55abf6d41d..111087d2e3c 100644 --- a/core/services/pipeline/task.divide_test.go +++ b/core/services/pipeline/task.divide_test.go @@ -10,7 +10,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + bridgesMocks "github.com/smartcontractkit/chainlink/v2/core/bridges/mocks" "github.com/smartcontractkit/chainlink/v2/core/internal/testutils" + "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest" + "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/pipeline" ) @@ -193,3 +196,38 @@ func TestDivideTask_Overflow(t *testing.T) { assert.False(t, runInfo.IsRetryable) require.Equal(t, pipeline.ErrDivisionOverlow, errors.Cause(result.Error)) } + +func TestDivide_Example(t *testing.T) { + t.Parallel() + + dag := ` +ds1 [type=memo value=10000.1234] + +ds2 [type=memo value=100] + +div_by_ds2 [type=divide divisor="$(ds2)"] + +multiply [type=multiply times=10000 index=0] + +ds1->div_by_ds2->multiply; +` + + db := pgtest.NewSqlxDB(t) + cfg := configtest.NewTestGeneralConfig(t) + btORM := bridgesMocks.NewORM(t) + r, _ := newRunner(t, db, btORM, cfg) + + spec := pipeline.Spec{DotDagSource: dag} + vars := pipeline.NewVarsFrom(nil) + + lggr := logger.TestLogger(t) + _, trrs, err := r.ExecuteRun(testutils.Context(t), spec, vars, lggr) + require.NoError(t, err) + + require.Len(t, trrs, 4) + + finalResult := trrs[3] + + assert.Nil(t, finalResult.Result.Error) + assert.Equal(t, "1000012.34", finalResult.Result.Value.(decimal.Decimal).String()) +}