Skip to content

Commit 6fe46e7

Browse files
authored
Update chaos examples (#1658)
update chaos examples, havoc fixes
1 parent e53a303 commit 6fe46e7

File tree

17 files changed

+497
-605
lines changed

17 files changed

+497
-605
lines changed

book/src/framework/chaos/chaos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ We also offer a set of blockchain-specific experiments, which typically involve
5656

5757
- Utilizing developer APIs (e.g., Anvil)
5858

59-
Check [gas](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/examples/myproject/chaos/chaos_blockchain_evm_gas_test.go) and [reorg](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/examples/myproject/chaos/chaos_blockchain_evm_reorg_test.go) examples.
59+
Check [gas](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/examples/myproject/chaos/chaos_blockchain_evm_gas_test.go) and [reorg](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/examples/myproject/chaos/chaos_blockchain_evm_reorg_test.go) examples, the same example work for [K8s](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/framework/examples/myproject/chaos/chaos_k8s_test.go).
6060

6161
## Debugging
6262

framework/.changeset/v0.5.8.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- All-in-one chaos examples for K8s based on CCIPv2

framework/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,11 @@ func (d *JSONStrDuration) UnmarshalJSON(b []byte) error {
235235
return errors.New("invalid duration")
236236
}
237237
}
238+
239+
func MustParseDuration(s string) time.Duration {
240+
d, err := time.ParseDuration(s)
241+
if err != nil {
242+
L.Fatal().Msg("cannot parse duration, should be Go format 1h2m3s")
243+
}
244+
return d
245+
}

framework/examples/myproject/chaos/chaos_blockchain_evm_gas_test.go

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package chaos
22

33
import (
4-
"context"
5-
"github.com/ethereum/go-ethereum/ethclient"
6-
"github.com/smartcontractkit/chainlink-testing-framework/framework"
4+
f "github.com/smartcontractkit/chainlink-testing-framework/framework"
75
"github.com/smartcontractkit/chainlink-testing-framework/framework/clclient"
86
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/blockchain"
97
"github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake"
@@ -15,24 +13,14 @@ import (
1513
"time"
1614
)
1715

18-
func printBlockBaseFee(t *testing.T, url string) {
19-
ec, err := ethclient.Dial(url)
20-
require.NoError(t, err)
21-
bn, err := ec.BlockNumber(context.Background())
22-
require.NoError(t, err)
23-
b, err := ec.BlockByNumber(context.Background(), big.NewInt(int64(bn)))
24-
require.NoError(t, err)
25-
t.Logf("Current block base fee: %d", b.BaseFee())
26-
}
27-
2816
type CfgGas struct {
2917
BlockchainA *blockchain.Input `toml:"blockchain_a" validate:"required"`
3018
MockerDataProvider *fake.Input `toml:"data_provider" validate:"required"`
3119
NodeSet *ns.Input `toml:"nodeset" validate:"required"`
3220
}
3321

3422
func TestBlockchainGasChaos(t *testing.T) {
35-
in, err := framework.Load[CfgGas](t)
23+
in, err := f.Load[CfgGas](t)
3624
require.NoError(t, err)
3725

3826
// Can replace deployments with CRIB here
@@ -51,28 +39,31 @@ func TestBlockchainGasChaos(t *testing.T) {
5139
blockEvery := 1 * time.Second
5240
waitBetweenTests := 1 * time.Minute
5341

54-
gasControlFunc := func(t *testing.T, r *rpc.RPCClient, url string) {
42+
gasControlFunc := func(t *testing.T, r *rpc.RPCClient) {
5543
startGasPrice := big.NewInt(2e9)
5644
// ramp
5745
for i := 0; i < 10; i++ {
58-
printBlockBaseFee(t, url)
46+
err := r.PrintBlockBaseFee()
47+
require.NoError(t, err)
5948
t.Logf("Setting block base fee: %d", startGasPrice)
60-
err := r.AnvilSetNextBlockBaseFeePerGas(startGasPrice)
49+
err = r.AnvilSetNextBlockBaseFeePerGas(startGasPrice)
6150
require.NoError(t, err)
6251
startGasPrice = startGasPrice.Add(startGasPrice, big.NewInt(1e9))
6352
time.Sleep(blockEvery)
6453
}
6554
// hold
6655
for i := 0; i < 10; i++ {
67-
printBlockBaseFee(t, url)
56+
err := r.PrintBlockBaseFee()
57+
require.NoError(t, err)
6858
time.Sleep(blockEvery)
6959
t.Logf("Setting block base fee: %d", startGasPrice)
70-
err := r.AnvilSetNextBlockBaseFeePerGas(startGasPrice)
60+
err = r.AnvilSetNextBlockBaseFeePerGas(startGasPrice)
7161
require.NoError(t, err)
7262
}
7363
// release
7464
for i := 0; i < 10; i++ {
75-
printBlockBaseFee(t, url)
65+
err := r.PrintBlockBaseFee()
66+
require.NoError(t, err)
7667
time.Sleep(blockEvery)
7768
}
7869
}
@@ -82,7 +73,7 @@ func TestBlockchainGasChaos(t *testing.T) {
8273
chainURL string
8374
increase *big.Int
8475
waitBetweenTests time.Duration
85-
gasFunc func(t *testing.T, r *rpc.RPCClient, url string)
76+
gasFunc func(t *testing.T, r *rpc.RPCClient)
8677
validate func(t *testing.T, c []*clclient.ChainlinkClient)
8778
}{
8879
{
@@ -114,9 +105,8 @@ func TestBlockchainGasChaos(t *testing.T) {
114105
for _, tc := range testCases {
115106
t.Run(tc.name, func(t *testing.T) {
116107
t.Log(tc.name)
117-
printBlockBaseFee(t, tc.chainURL)
118108
r := rpc.New(tc.chainURL, nil)
119-
tc.gasFunc(t, r, tc.chainURL)
109+
tc.gasFunc(t, r)
120110
tc.validate(t, c)
121111
time.Sleep(waitBetweenTests)
122112
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[chaos]
2+
wait_before_start = "10s"
3+
namespace = "default"
4+
dashboard_uuids = ["WaspDebug"]
5+
experiment_duration = "20s"
6+
experiment_injection_duration = "10s"
7+
remove_k8s_chaos = true
8+
9+
blockchain_http_urls = ["http://localhost:8545", "http://localhost:8550"]
10+
reorg_below_finality_threshold = 5
11+
reorg_above_finality_threshold = 10
12+
block_every = "1s"

0 commit comments

Comments
 (0)