Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional mock DA configuration for dymintToml overrides #366

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 102 additions & 1 deletion tests/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,23 @@ func registerGenesisEventTriggerer(t *testing.T, targetChain *cosmos.CosmosChain
require.Equal(t, string(deployerWhitelistParams), newParams.Value)
}

func overridesDymintToml(settlemenLayer, nodeAddress, rollappId, gasPrices, maxIdleTime, maxProofTime, batchSubmitMaxTime string) map[string]any {
func overridesDymintToml(settlemenLayer, nodeAddress, rollappId, gasPrices, maxIdleTime, maxProofTime, batchSubmitMaxTime string, optionalConfigs ...bool) map[string]any {
configFileOverrides := make(map[string]any)
dymintTomlOverrides := make(testutil.Toml)

// Default values for optional fields
includeDaGrpcLayer := false

// Check if any options were passed and update the optional fields
if len(optionalConfigs) > 0 {
includeDaGrpcLayer = optionalConfigs[0]
}

if includeDaGrpcLayer {
dymintTomlOverrides["da_layer"] = "grpc"
dymintTomlOverrides["da_config"] = "{\"host\":\"host.docker.internal\",\"port\": 7980}"
}

dymintTomlOverrides["settlement_layer"] = settlemenLayer
dymintTomlOverrides["settlement_node_address"] = nodeAddress
dymintTomlOverrides["rollapp_id"] = rollappId
Expand Down Expand Up @@ -731,3 +744,91 @@ func GetLatestBlockHeight(url, headerKey, headerValue string) (string, error) {
}
return string(body), nil
}


func customEpochConfig(epochDuration string) ibc.ChainConfig {
// Custom dymension epoch for faster disconnection
modifyGenesisKV := dymensionGenesisKV
for i, kv := range modifyGenesisKV {
if kv.Key == "app_state.incentives.params.distr_epoch_identifier" || kv.Key == "app_state.txfees.params.epoch_identifier" {
modifyGenesisKV[i].Value = "custom"
}
}

customDymensionConfig := ibc.ChainConfig{
Type: "hub-dym",
Name: "dymension",
ChainID: "dymension_100-1",
Images: []ibc.DockerImage{dymensionImage},
Bin: "dymd",
Bech32Prefix: "dym",
Denom: "adym",
CoinType: "60",
GasPrices: "0.0adym",
EncodingConfig: encodingConfig(),
GasAdjustment: 1.1,
TrustingPeriod: "112h",
NoHostMount: false,
ModifyGenesis: func(chainConfig ibc.ChainConfig, inputGenBz []byte) ([]byte, error) {
g := make(map[string]interface{})
if err := json.Unmarshal(inputGenBz, &g); err != nil {
return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err)
}

epochData, err := dyno.Get(g, "app_state", "epochs", "epochs")
if err != nil {
return nil, fmt.Errorf("failed to retrieve epochs: %w", err)
}
epochs := epochData.([]interface{})
exist := false
// Check if the "custom" identifier already exists
for _, epoch := range epochs {
if epochMap, ok := epoch.(map[string]interface{}); ok {
if epochMap["identifier"] == "custom" {
exist = true
}
}
}
if !exist {
// Define the new epoch type to be added
newEpochType := map[string]interface{}{
"identifier": "custom",
"start_time": "0001-01-01T00:00:00Z",
"duration": epochDuration,
"current_epoch": "0",
"current_epoch_start_time": "0001-01-01T00:00:00Z",
"epoch_counting_started": false,
"current_epoch_start_height": "0",
}

// Add the new epoch to the epochs array
updatedEpochs := append(epochs, newEpochType)
if err := dyno.Set(g, updatedEpochs, "app_state", "epochs", "epochs"); err != nil {
return nil, fmt.Errorf("failed to set epochs in genesis json: %w", err)
}
}
if err := dyno.Set(g, "adym", "app_state", "gov", "params", "min_deposit", 0, "denom"); err != nil {
return nil, fmt.Errorf("failed to set denom on gov min_deposit in genesis json: %w", err)
}
if err := dyno.Set(g, "10000000000", "app_state", "gov", "params", "min_deposit", 0, "amount"); err != nil {
return nil, fmt.Errorf("failed to set amount on gov min_deposit in genesis json: %w", err)
}
if err := dyno.Set(g, "adym", "app_state", "gamm", "params", "pool_creation_fee", 0, "denom"); err != nil {
return nil, fmt.Errorf("failed to set amount on gov min_deposit in genesis json: %w", err)
}
// if err := dyno.Set(g, "1000000000000", "app_state", "rollapp", "params", "registration_fee", "amount"); err != nil {
// return nil, fmt.Errorf("failed to set registration_fee in genesis json: %w", err)
// }
outputGenBz, err := json.Marshal(g)
if err != nil {
return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err)
}

return cosmos.ModifyGenesis(modifyGenesisKV)(chainConfig, outputGenBz)
},
ConfigFileOverrides: nil,
}

return customDymensionConfig
}

Loading