Skip to content

Commit

Permalink
Enable CORS on localosmosis (#4891)
Browse files Browse the repository at this point in the history
Closes: [#4879](#4879)

## What is the purpose of the change

Enables cors on localOsmosis for:
- rpc
- api
- gRPC-web

## Brief Changelog

- Enable cors by default on localosmosis

## Testing and Verifying

Start localosmosis:

```bash
make localnet-start
```

Check file changes:

```bash
❯ cat ~/.osmosisd-local/config/config.toml | grep cors
  cors_allowed_headers = ["Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time", "Accept-Encoding"]
  cors_allowed_methods = ["HEAD", "GET", "POST", "DELETE", "OPTIONS", "PATCH", "PUT"]
  cors_allowed_origins = ["*"]
```

```bash
❯ cat ~/.osmosisd-local/config/app.toml | grep cors
  enabled-unsafe-cors = true
  enable-unsafe-cors = true
```

## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? no
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? yes
  - How is the feature or change documented? not applicable

(cherry picked from commit 3b2e168)

# Conflicts:
#	CHANGELOG.md
#	tests/localosmosis/scripts/setup.sh
  • Loading branch information
niccoloraspa authored and mergify[bot] committed Apr 11, 2023
1 parent 8eab695 commit 8529c2a
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Misc Improvements

* [#4582](https://github.com/osmosis-labs/osmosis/pull/4582) Consistently generate build tags metadata, to return a comma-separated list without stray quotes. This affects the output from `version` CLI subcommand and server info API calls.
<<<<<<< HEAD
=======
* [#4549](https://github.com/osmosis-labs/osmosis/pull/4549) Add single pool price estimate queries
* [#4767](https://github.com/osmosis-labs/osmosis/pull/4767) Disable create pool with non-zero exit fee
* [#4847](https://github.com/osmosis-labs/osmosis/pull/4847) Update `make build` command to build only `osmosisd` binary
* [#4891](https://github.com/osmosis-labs/osmosis/pull/4891) Enable CORS by default on localosmosis
* [#4893](https://github.com/osmosis-labs/osmosis/pull/4893) Update alpine docker base image to `alpine:3.17`

### API Breaks

### API breaks

* [#4336](https://github.com/osmosis-labs/osmosis/pull/4336) Move epochs module into its own go.mod
* [#4658](https://github.com/osmosis-labs/osmosis/pull/4658) Deprecate x/gamm Pool query. The new one is located in x/poolmanager.
* [#4682](https://github.com/osmosis-labs/osmosis/pull/4682) Deprecate x/gamm SpotPrice v2 query. The new one is located in x/poolmanager.
* [#4801](https://github.com/osmosis-labs/osmosis/pull/4801) remove GetTotalShares, GetTotalLiquidity and GetExitFee from PoolI. Define all on CFMMPoolI, define GetTotalLiquidity on PoolModuleI only.
* [#4868](https://github.com/osmosis-labs/osmosis/pull/4868) Remove wasmEnabledProposals []wasm.ProposalType from NewOsmosisApp

>>>>>>> 3b2e1680 (Enable CORS on localosmosis (#4891))
## v15.0.0

Expand Down
61 changes: 61 additions & 0 deletions tests/localosmosis/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,75 @@ add_genesis_accounts () {
}

edit_config () {

# Remove seeds
dasel put string -f $CONFIG_FOLDER/config.toml '.p2p.seeds' ''

# Expose the rpc
dasel put string -f $CONFIG_FOLDER/config.toml '.rpc.laddr' "tcp://0.0.0.0:26657"
}

<<<<<<< HEAD
create_two_asset_pool () {
# Create default pool
=======
enable_cors () {

# Enable cors on RPC
dasel put string -f $CONFIG_FOLDER/config.toml -v "*" '.rpc.cors_allowed_origins.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "Accept-Encoding" '.rpc.cors_allowed_headers.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "DELETE" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "OPTIONS" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "PATCH" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "PUT" '.rpc.cors_allowed_methods.[]'

# Enable unsafe cors and swagger on the api
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.api.swagger'
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.api.enabled-unsafe-cors'

# Enable cors on gRPC Web
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.grpc-web.enable-unsafe-cors'
}

run_with_retries() {
cmd=$1
success_msg=$2

substring='code: 0'
COUNTER=0

while [ $COUNTER -lt 15 ]; do
string=$(eval $cmd 2>&1)
echo $string

if [ "$string" != "${string%"$substring"*}" ]; then
echo "$success_msg"
break
else
COUNTER=$((COUNTER+1))
sleep 0.5
fi
done
}

# Define the functions using the new function
create_two_asset_pool() {
run_with_retries "osmosisd tx gamm create-pool --pool-file=$1 --from pools --chain-id=$CHAIN_ID --home $OSMOSIS_HOME --keyring-backend=test -b block --fees 5000uosmo --yes" "create two asset pool: successful"
}

create_three_asset_pool() {
run_with_retries "osmosisd tx gamm create-pool --pool-file=nativeDenomThreeAssetPool.json --from pools --chain-id=$CHAIN_ID --home $OSMOSIS_HOME --keyring-backend=test -b block --fees 5000uosmo --gas 900000 --yes" "create three asset pool: successful"
}

create_concentrated_pool() {
run_with_retries "osmosisd tx concentratedliquidity create-concentrated-pool uosmo uion 1 [-4] \"0.01\" --from pools --chain-id=$CHAIN_ID --home $OSMOSIS_HOME --keyring-backend=test -b block --fees 5000uosmo --gas 900000 --yes" "create concentrated pool: successful"
}

create_concentrated_pool_positions () {
# Define an array to hold the parameters that change for each command
set "[-1620000] 3420000" "305450 315000" "315000 322500" "300000 309990"

>>>>>>> 3b2e1680 (Enable CORS on localosmosis (#4891))
substring='code: 0'
COUNTER=0
while [ $COUNTER -lt 15 ]; do
Expand Down Expand Up @@ -151,6 +211,7 @@ then
edit_genesis
add_genesis_accounts
edit_config
enable_cors
fi

osmosisd start --home $OSMOSIS_HOME &
Expand Down
19 changes: 19 additions & 0 deletions tests/localosmosis/state_export/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ edit_config () {
dasel put string -f $CONFIG_FOLDER/config.toml '.rpc.laddr' "tcp://0.0.0.0:26657"
}

enable_cors () {

# Enable cors on RPC
dasel put string -f $CONFIG_FOLDER/config.toml -v "*" '.rpc.cors_allowed_origins.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "Accept-Encoding" '.rpc.cors_allowed_headers.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "DELETE" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "OPTIONS" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "PATCH" '.rpc.cors_allowed_methods.[]'
dasel put string -f $CONFIG_FOLDER/config.toml -v "PUT" '.rpc.cors_allowed_methods.[]'

# Enable unsafe cors and swagger on the api
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.api.swagger'
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.api.enabled-unsafe-cors'

# Enable cors on gRPC Web
dasel put bool -f $CONFIG_FOLDER/app.toml -v "true" '.grpc-web.enable-unsafe-cors'
}

if [[ ! -d $CONFIG_FOLDER ]]
then

Expand Down Expand Up @@ -67,6 +85,7 @@ then
--prune-ibc

edit_config
enable_cors
fi

osmosisd start --home $OSMOSIS_HOME --x-crisis-skip-assert-invariants

0 comments on commit 8529c2a

Please sign in to comment.