interchaintest icon indicating copy to clipboard operation
interchaintest copied to clipboard

Handle merging of lists in `RecursiveModifyToml`

Open chatton opened this issue 8 months ago • 0 comments

When attempting to modify the hermes configuration file using this function, I wanted to apply the following changes

    var channelIDs [][]string
    for _, c := range channels {
       channelIDs = append(channelIDs, []string{c.PortID, c.ChannelID})
    }

    channelIDs = append(channelIDs, []string{"ica*", "*"})

    overrides := map[string]any{
       "chains": []map[string]interface{}{
          {
             "id": chainID,
             "packet_filter": map[string]interface{}{
                "policy": "allow",
                // we explicitly override the full list, this allows this function to provide a complete set of channels to watch.
                "list": channelIDs,
             },
          },
       },
    }

    return h.ModifyTomlConfigFile(ctx, ".hermes/config.toml", overrides)

i.e. explicitly adding the packet_filter field for chainID. The current behaviour of RecursiveModifyToml will ignore slices of maps, I think it would be desirable to be able to merge lists of maps this way.

Things may get tricky when you are trying to append/prepend/insert items in the merging logic, but I think it would be fine to even just require providing the same number of items, e.g. the above example would become

    overrides := map[string]any{
       "chains": []map[string]interface{}{
          {
             "packet_filter": map[string]interface{}{
                "policy": "allow",
                // we explicitly override the full list, this allows this function to provide a complete set of channels to watch.
                "list": channelIDs,
             },
          },
       },
      {}, // <--- empty map
    }

to modify the first chain in a 2 chain setup

chatton avatar Jun 25 '24 10:06 chatton