|
| 1 | +package simple_node_set_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/smartcontractkit/chainlink-testing-framework/framework" |
| 5 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain" |
| 6 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/components/clnode" |
| 7 | + "github.com/smartcontractkit/chainlink-testing-framework/framework/components/postgres" |
| 8 | + ns "github.com/smartcontractkit/chainlink-testing-framework/framework/components/simple_node_set" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | + "sync" |
| 11 | + "testing" |
| 12 | +) |
| 13 | + |
| 14 | +type testCase struct { |
| 15 | + name string |
| 16 | + fakeURL string |
| 17 | + funding float64 |
| 18 | + bcInput *blockchain.Input |
| 19 | + nodeSetInput *ns.Input |
| 20 | + assertion func(t *testing.T, output *ns.Output) |
| 21 | +} |
| 22 | + |
| 23 | +func checkBasicOutputs(t *testing.T, output *ns.Output) { |
| 24 | + require.NotNil(t, output) |
| 25 | + require.NotNil(t, output.CLNodes) |
| 26 | + require.Len(t, output.CLNodes, 2) |
| 27 | + require. Contains( t, output. CLNodes[ 0]. PostgreSQL. Url, "postgresql://chainlink:[email protected]") |
| 28 | + require.Contains(t, output.CLNodes[0].PostgreSQL.DockerInternalURL, "postgresql://chainlink:thispasswordislongenough@postgresql-") |
| 29 | + require.Contains(t, output.CLNodes[0].Node.HostURL, "127.0.0.1") |
| 30 | + require.Contains(t, output.CLNodes[0].Node.DockerURL, "node") |
| 31 | + require.Contains(t, output.CLNodes[0].Node.DockerP2PUrl, "node") |
| 32 | + |
| 33 | + require. Contains( t, output. CLNodes[ 1]. PostgreSQL. Url, "postgresql://chainlink:[email protected]") |
| 34 | + require.Contains(t, output.CLNodes[1].PostgreSQL.DockerInternalURL, "postgresql://chainlink:thispasswordislongenough@postgresql-") |
| 35 | + require.Contains(t, output.CLNodes[1].Node.HostURL, "127.0.0.1") |
| 36 | + require.Contains(t, output.CLNodes[1].Node.DockerURL, "node") |
| 37 | + require.Contains(t, output.CLNodes[1].Node.DockerP2PUrl, "node") |
| 38 | +} |
| 39 | + |
| 40 | +func TestNodeSetSharedDB(t *testing.T) { |
| 41 | + testCases := []testCase{ |
| 42 | + { |
| 43 | + name: "2 nodes cluster, override mode 'all'", |
| 44 | + fakeURL: "http://example.com", |
| 45 | + bcInput: &blockchain.Input{ |
| 46 | + Type: "anvil", |
| 47 | + Image: "f4hrenh9it/foundry", |
| 48 | + PullImage: true, |
| 49 | + Port: "8545", |
| 50 | + ChainID: "31337", |
| 51 | + }, |
| 52 | + nodeSetInput: &ns.Input{ |
| 53 | + Nodes: 2, |
| 54 | + OverrideMode: "all", |
| 55 | + NodeSpecs: []*clnode.Input{ |
| 56 | + { |
| 57 | + DataProviderURL: "http://example.com", |
| 58 | + DbInput: &postgres.Input{ |
| 59 | + Image: "postgres:15.6", |
| 60 | + PullImage: true, |
| 61 | + }, |
| 62 | + Node: &clnode.NodeInput{ |
| 63 | + Image: "public.ecr.aws/chainlink/chainlink:v2.17.0", |
| 64 | + Name: "cl-node", |
| 65 | + PullImage: true, |
| 66 | + }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + }, |
| 70 | + assertion: func(t *testing.T, output *ns.Output) { |
| 71 | + checkBasicOutputs(t, output) |
| 72 | + }, |
| 73 | + }, |
| 74 | + { |
| 75 | + name: "2 nodes cluster, override mode 'each'", |
| 76 | + fakeURL: "http://example.com", |
| 77 | + bcInput: &blockchain.Input{ |
| 78 | + Type: "anvil", |
| 79 | + Image: "f4hrenh9it/foundry", |
| 80 | + PullImage: true, |
| 81 | + Port: "8545", |
| 82 | + ChainID: "31337", |
| 83 | + }, |
| 84 | + nodeSetInput: &ns.Input{ |
| 85 | + Nodes: 2, |
| 86 | + OverrideMode: "each", |
| 87 | + NodeSpecs: []*clnode.Input{ |
| 88 | + { |
| 89 | + DataProviderURL: "http://example.com", |
| 90 | + DbInput: &postgres.Input{ |
| 91 | + Image: "postgres:15.6", |
| 92 | + PullImage: true, |
| 93 | + }, |
| 94 | + Node: &clnode.NodeInput{ |
| 95 | + Image: "public.ecr.aws/chainlink/chainlink:v2.17.0", |
| 96 | + Name: "cl-node-1", |
| 97 | + PullImage: true, |
| 98 | + UserConfigOverrides: ` |
| 99 | +[Log] |
| 100 | +level = 'info' |
| 101 | +`, |
| 102 | + }, |
| 103 | + }, |
| 104 | + { |
| 105 | + DataProviderURL: "http://example.com", |
| 106 | + DbInput: &postgres.Input{ |
| 107 | + Image: "postgres:15.6", |
| 108 | + PullImage: true, |
| 109 | + }, |
| 110 | + Node: &clnode.NodeInput{ |
| 111 | + Image: "public.ecr.aws/chainlink/chainlink:v2.17.0", |
| 112 | + Name: "cl-node-2", |
| 113 | + PullImage: true, |
| 114 | + UserConfigOverrides: ` |
| 115 | +[Log] |
| 116 | +level = 'info' |
| 117 | +`, |
| 118 | + }, |
| 119 | + }, |
| 120 | + }, |
| 121 | + }, |
| 122 | + assertion: func(t *testing.T, output *ns.Output) { |
| 123 | + checkBasicOutputs(t, output) |
| 124 | + }, |
| 125 | + }, |
| 126 | + } |
| 127 | + |
| 128 | + for _, tc := range testCases { |
| 129 | + err := framework.DefaultNetwork(t, &sync.Once{}) |
| 130 | + require.NoError(t, err) |
| 131 | + |
| 132 | + t.Run(tc.name, func(t *testing.T) { |
| 133 | + bc, err := blockchain.NewBlockchainNetwork(tc.bcInput) |
| 134 | + require.NoError(t, err) |
| 135 | + output, err := ns.NewSharedDBNodeSet(tc.nodeSetInput, bc, tc.fakeURL) |
| 136 | + require.NoError(t, err) |
| 137 | + tc.assertion(t, output) |
| 138 | + }) |
| 139 | + } |
| 140 | +} |
0 commit comments