|
| 1 | +package examples |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "github.com/smartcontractkit/chainlink-testing-framework/framework" |
| 6 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/chaos" |
| 7 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/clclient" |
| 8 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" |
| 9 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake" |
| 10 | + ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | + "testing" |
| 13 | + "time" |
| 14 | +) |
| 15 | + |
| 16 | +type CfgReload struct { |
| 17 | + BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"` |
| 18 | + MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"` |
| 19 | + NodeSet *ns.Input `toml:"nodeset" validate:"required"` |
| 20 | +} |
| 21 | + |
| 22 | +func TestReload(t *testing.T) { |
| 23 | + in, err := framework.Load[CfgReload](t) |
| 24 | + require.NoError(t, err) |
| 25 | + |
| 26 | + bc, err := blockchain.NewBlockchainNetwork(in.BlockchainA) |
| 27 | + require.NoError(t, err) |
| 28 | + dp, err := fake.NewFakeDataProvider(in.MockerDataProvider) |
| 29 | + require.NoError(t, err) |
| 30 | + |
| 31 | + // deploy first time |
| 32 | + out, err := ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker) |
| 33 | + require.NoError(t, err) |
| 34 | + |
| 35 | + c, err := clclient.NewCLDefaultClients(out.CLNodes, framework.L) |
| 36 | + require.NoError(t, err) |
| 37 | + _, _, err = c[0].CreateJobRaw(` |
| 38 | + type = "cron" |
| 39 | + schemaVersion = 1 |
| 40 | + schedule = "CRON_TZ=UTC */10 * * * * *" # every 10 secs |
| 41 | + observationSource = """ |
| 42 | + // data source 2 |
| 43 | + fetch [type=http method=GET url="https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD"]; |
| 44 | + parse [type=jsonparse path="RAW,ETH,USD,PRICE"]; |
| 45 | + multiply [type="multiply" input="$(parse)" times=100] |
| 46 | + encode_tx [type="ethabiencode" |
| 47 | + abi="submit(uint256 value)" |
| 48 | + data="{ \\"value\\": $(multiply) }"] |
| 49 | + submit_tx [type="ethtx" to="0x859AAa51961284C94d970B47E82b8771942F1980" data="$(encode_tx)"] |
| 50 | + |
| 51 | + fetch -> parse -> multiply -> encode_tx -> submit_tx |
| 52 | + """`) |
| 53 | + require.NoError(t, err) |
| 54 | + time.Sleep(20 * time.Second) |
| 55 | + |
| 56 | + // deploy second time |
| 57 | + _, err = chaos.ExecPumba("rm --volumes=false re2:node.*|postgresql.*") |
| 58 | + require.NoError(t, err) |
| 59 | + |
| 60 | + in.NodeSet.NodeSpecs[0].Node.UserConfigOverrides = in.NodeSet.NodeSpecs[0].Node.UserConfigOverrides + ` |
| 61 | +[Log] |
| 62 | +Level = 'info' |
| 63 | +` |
| 64 | + in.NodeSet.Out = nil |
| 65 | + out, err = ns.NewSharedDBNodeSet(in.NodeSet, bc, dp.BaseURLDocker) |
| 66 | + require.NoError(t, err) |
| 67 | + jobs, _, err := c[0].ReadJobs() |
| 68 | + require.NoError(t, err) |
| 69 | + fmt.Println(jobs) |
| 70 | + |
| 71 | + t.Run("test something", func(t *testing.T) { |
| 72 | + for _, n := range out.CLNodes { |
| 73 | + require.NotEmpty(t, n.Node.HostURL) |
| 74 | + require.NotEmpty(t, n.Node.HostP2PURL) |
| 75 | + } |
| 76 | + }) |
| 77 | +} |
0 commit comments