diff --git a/.github/workflows/integration-test.yaml b/.github/workflows/integration-test.yaml index 05423359..efc771c1 100644 --- a/.github/workflows/integration-test.yaml +++ b/.github/workflows/integration-test.yaml @@ -1,4 +1,4 @@ -name: Integration test +name: End-to-end test on: push: @@ -17,7 +17,7 @@ jobs: - name: Setup network run: | mkdir ~/genesis - cd integration_test && docker-compose up -d + cd tests/e2e && docker-compose up -d docker ps sleep 20 @@ -26,8 +26,8 @@ jobs: with: go-version: 1.18.x - - name: Integration test - run: cd integration_test && go test + - name: End-to-end test + run: cd tests/e2e && go test - name: Teardown - run: cd integration_test && docker-compose down + run: cd tests/e2e && docker-compose down diff --git a/Dockerfile b/Dockerfile index 63868525..28976315 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,10 +39,10 @@ RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS='-linkmode=external -extldflag FROM alpine:3.15 AS runtime WORKDIR /opt -RUN [ "mkdir", "-p", "/opt/integration_test" ] +RUN [ "mkdir", "-p", "/opt/tests/integration" ] COPY --from=build /localnet/build/xplad /usr/bin/xplad -COPY --from=build /localnet/integration_test /opt/integration_test +COPY --from=build /localnet/tests/e2e /opt/tests/e2e # Expose Cosmos ports EXPOSE 9090 diff --git a/integration_test/README.md b/integration_test/README.md deleted file mode 100644 index 35da89a6..00000000 --- a/integration_test/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# Integration Test - -This module is basically for the automated integration test. But if you want to execute by yourself for testing (test testing) purpose, this tests are also executable on your local. Please follow the step below: - -## Prerequisites - -- Docker >= 20.10 -- Docker compose >= 2.12 - -## How to run - -```bash -# 1. From the repo root, move to the integration_test, and execute docker compose -cd integration_test -docker-compose up -d - -# 2. Wait for building. Once done without error, you may check the nodes running -docker ps - -#CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -#648b7146ce8c integration_test-node1 "sh -c 'MONIKER=vali…" 44 minutes ago Up 44 minutes 0.0.0.0:8545->8545/tcp, 0.0.0.0:9090->9090/tcp, 0.0.0.0:26656->26656/tcp xpla-localnet-validator1 -#97279d567135 integration_test-node2 "sh -c 'MONIKER=vali…" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9100->9100/tcp, 26656/tcp, 0.0.0.0:26666->26666/tcp xpla-localnet-validator2 -#f604f68c3f82 integration_test-node3 "sh -c 'MONIKER=vali…" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9110->9110/tcp, 26656/tcp, 0.0.0.0:26676->26676/tcp xpla-localnet-validator3 -#c3d0d9daefd2 integration_test-node4 "sh -c 'MONIKER=vali…" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9120->9120/tcp, 26656/tcp, 0.0.0.0:26686->26686/tcp xpla-localnet-validator4 - -# 3. Execute tests -go test - -# Do not execute short mode -# (X) go test -short - -# ... -# PASS -# ok github.com/xpladev/xpla/integration_test 29.365s - -# If you see the pass sign, you may down the nodes -docker-compose down -``` - -## Test scenario - -### WASM - -- Send `delegation` tx -- Upload the contract binary and get a code ID -- With the code ID above, try to instantiate the contract -- Execute the contract -- Assert from querying the contract in each test step by assertion diff --git a/integration_test/.env b/tests/e2e/.env similarity index 100% rename from integration_test/.env rename to tests/e2e/.env diff --git a/tests/e2e/README.md b/tests/e2e/README.md new file mode 100644 index 00000000..43431ebd --- /dev/null +++ b/tests/e2e/README.md @@ -0,0 +1,48 @@ +# End-to-end Test + +This module is basically for the automated end-to-end test. But if you want to execute by yourself for testing (test testing) purpose, this tests are also executable on your local. Please follow the step below: + +## Prerequisites + +- Docker >= 20.10 +- Docker compose >= 2.12 + +## How to run + +```bash +# 1. From the repo root, move to the tests/e2e, and execute docker compose +cd tests/e2e +docker-compose up -d + +# 2. Wait for building. Once done without error, you may check the nodes running +docker ps + +#CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +#648b7146ce8c e2e-node1 "sh -c 'MONIKER=vali…" 44 minutes ago Up 44 minutes 0.0.0.0:8545->8545/tcp, 0.0.0.0:9090->9090/tcp, 0.0.0.0:26656->26656/tcp xpla-localnet-validator1 +#97279d567135 e2e-node2 "sh -c 'MONIKER=vali…" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9100->9100/tcp, 26656/tcp, 0.0.0.0:26666->26666/tcp xpla-localnet-validator2 +#f604f68c3f82 e2e-node3 "sh -c 'MONIKER=vali…" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9110->9110/tcp, 26656/tcp, 0.0.0.0:26676->26676/tcp xpla-localnet-validator3 +#c3d0d9daefd2 e2e-node4 "sh -c 'MONIKER=vali…" 44 minutes ago Up 44 minutes 8545/tcp, 9090/tcp, 0.0.0.0:9120->9120/tcp, 26656/tcp, 0.0.0.0:26686->26686/tcp xpla-localnet-validator4 + +# 3. Execute tests +go test + +# Do not execute short mode +# (X) go test -short + +# ... +# PASS +# ok github.com/xpladev/xpla/tests/e2e 29.365s + +# If you see the pass sign, you may down the nodes +docker-compose down +``` + +## Test scenario + +### WASM + +- Send `delegation` tx +- Upload the contract binary and get a code ID +- With the code ID above, try to instantiate the contract +- Execute the contract +- Assert from querying the contract in each test step by assertion diff --git a/integration_test/common_configs/app.toml b/tests/e2e/common_configs/app.toml similarity index 100% rename from integration_test/common_configs/app.toml rename to tests/e2e/common_configs/app.toml diff --git a/integration_test/common_configs/client.toml b/tests/e2e/common_configs/client.toml similarity index 100% rename from integration_test/common_configs/client.toml rename to tests/e2e/common_configs/client.toml diff --git a/integration_test/common_configs/config.toml b/tests/e2e/common_configs/config.toml similarity index 100% rename from integration_test/common_configs/config.toml rename to tests/e2e/common_configs/config.toml diff --git a/integration_test/docker-compose.yml b/tests/e2e/docker-compose.yml similarity index 84% rename from integration_test/docker-compose.yml rename to tests/e2e/docker-compose.yml index fe581e52..3eed63bf 100644 --- a/integration_test/docker-compose.yml +++ b/tests/e2e/docker-compose.yml @@ -4,7 +4,7 @@ services: container_name: xpla-localnet-validator1 build: - context: ../. + context: ../../. target: runtime volumes: @@ -16,7 +16,7 @@ services: - "36656:26656" - "36657:26657" - entrypoint: sh -c "MONIKER=validator1 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_master.sh" + entrypoint: sh -c "MONIKER=validator1 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_master.sh" networks: vpcbr: @@ -32,7 +32,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -40,7 +40,7 @@ services: - "19100:9090" - "36666:26656" - entrypoint: sh -c "MONIKER=validator2 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=validator2 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -56,7 +56,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -64,7 +64,7 @@ services: - "19110:9090" - "36676:26656" - entrypoint: sh -c "MONIKER=validator3 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=validator3 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -80,7 +80,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -88,7 +88,7 @@ services: - "19120:9090" - "36686:26656" - entrypoint: sh -c "MONIKER=validator4 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=validator4 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -104,7 +104,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -112,7 +112,7 @@ services: - "19130:9090" - "36696:26656" - entrypoint: sh -c "MONIKER=validator5_experimental XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=validator5_experimental XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -128,7 +128,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -136,7 +136,7 @@ services: - "19140:9090" - "36706:26656" - entrypoint: sh -c "MONIKER=volunteer_validator1 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=volunteer_validator1 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -152,7 +152,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -160,7 +160,7 @@ services: - "19150:9090" - "36716:26656" - entrypoint: sh -c "MONIKER=volunteer_validator2 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=volunteer_validator2 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: @@ -176,7 +176,7 @@ services: - node1 build: - context: ../. + context: ../../. target: runtime ports: @@ -184,7 +184,7 @@ services: - "19160:9090" - "36726:26656" - entrypoint: sh -c "MONIKER=volunteer_validator3 XPLAHOME=$XPLAHOME sh /opt/integration_test/entrypoint_secondary.sh" + entrypoint: sh -c "MONIKER=volunteer_validator3 XPLAHOME=$XPLAHOME sh /opt/tests/e2e/entrypoint_secondary.sh" networks: vpcbr: diff --git a/integration_test/entrypoint.sh b/tests/e2e/entrypoint.sh similarity index 64% rename from integration_test/entrypoint.sh rename to tests/e2e/entrypoint.sh index 862deb1f..5c6b411b 100644 --- a/integration_test/entrypoint.sh +++ b/tests/e2e/entrypoint.sh @@ -1,16 +1,16 @@ #!/bin/sh -# MONIKER=validator1|validator2|validator3|validator4 sh /opt/integration_test/entrypoint.sh +# MONIKER=validator1|validator2|validator3|validator4 sh /opt/tests/e2e/entrypoint.sh # 1. chain init /usr/bin/xplad init $MONIKER --chain-id localtest_1-1 --home $XPLAHOME # 2. copy the node setting files to the node home dir -cp -r /opt/integration_test/$MONIKER/* /opt/.xpla/config +cp -r /opt/tests/e2e/$MONIKER/* /opt/.xpla/config # 3. register my validator & users keyfile -/usr/bin/xplad keys add validator1 --recover --home $XPLAHOME < /opt/integration_test/test_keys/$MONIKER.mnemonics -/usr/bin/xplad keys add user1 --recover --home $XPLAHOME < /opt/integration_test/test_keys/user1.mnemonics -/usr/bin/xplad keys add user2 --recover --home $XPLAHOME < /opt/integration_test/test_keys/user2.mnemonics +/usr/bin/xplad keys add validator1 --recover --home $XPLAHOME < /opt/tests/e2e/test_keys/$MONIKER.mnemonics +/usr/bin/xplad keys add user1 --recover --home $XPLAHOME < /opt/tests/e2e/test_keys/user1.mnemonics +/usr/bin/xplad keys add user2 --recover --home $XPLAHOME < /opt/tests/e2e/test_keys/user2.mnemonics # 4. check genesis.json /usr/bin/xplad validate-genesis --home $XPLAHOME diff --git a/integration_test/entrypoint_master.sh b/tests/e2e/entrypoint_master.sh similarity index 84% rename from integration_test/entrypoint_master.sh rename to tests/e2e/entrypoint_master.sh index 28f41f53..e6d1f505 100644 --- a/integration_test/entrypoint_master.sh +++ b/tests/e2e/entrypoint_master.sh @@ -1,5 +1,5 @@ #!/bin/sh -# MONIKER=validator1|validator2|validator3|validator4 sh /opt/integration_test/entrypoint.sh +# MONIKER=validator1|validator2|validator3|validator4 sh /opt/tests/e2e/entrypoint.sh # File is not atomic and somestimes secondary nodes copies the existing old genesisfile # It should be cleared @@ -10,25 +10,25 @@ rm -f /genesis/* # 2. Register the keys # xpla1z2k85n48ydfvzslrugwzl4j2u7vtdyf3xvucmc -/usr/bin/xplad keys add validator1 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator1.mnemonics +/usr/bin/xplad keys add validator1 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator1.mnemonics # xpla16wx7ye3ce060tjvmmpu8lm0ak5xr7gm2dp0kpt -/usr/bin/xplad keys add validator2 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator2.mnemonics +/usr/bin/xplad keys add validator2 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator2.mnemonics # xpla1pe9mc2q72u94sn2gg52ramrt26x5efw6hr5gt4 -/usr/bin/xplad keys add validator3 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator3.mnemonics +/usr/bin/xplad keys add validator3 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator3.mnemonics # xpla1luqjvjyns9e92h06tq6zqtw76k8xtegfcerzjr -/usr/bin/xplad keys add validator4 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator4.mnemonics +/usr/bin/xplad keys add validator4 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator4.mnemonics # xpla1y6gnay0pv49asun56la09jcmhg2kc949mpftvt -/usr/bin/xplad keys add user1 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/user1.mnemonics +/usr/bin/xplad keys add user1 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/user1.mnemonics # xpla1u27snswkjpenlscgvszcfjmz8uy2y5qacx0826 -/usr/bin/xplad keys add user2 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/user2.mnemonics +/usr/bin/xplad keys add user2 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/user2.mnemonics # xpla14xprgqlnuep23kmvsk5utd9pw7w27yeyjlcmcz -- validator5_experimental -/usr/bin/xplad keys add validator5_experimental --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/validator5_experimental.mnemonics +/usr/bin/xplad keys add validator5_experimental --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/validator5_experimental.mnemonics # xpla1ur90l8ecppc55gll7k57dk2tvs2w5m9jzptpcj -- volunteer validator1 -/usr/bin/xplad keys add volunteer_validator1 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/volunteer_validator1.mnemonics +/usr/bin/xplad keys add volunteer_validator1 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/volunteer_validator1.mnemonics # xpla1yct6tmmm0twn2wz637lt0yz62xwtqhyqa84uu5 -- volunteer validator2 -/usr/bin/xplad keys add volunteer_validator2 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/volunteer_validator2.mnemonics +/usr/bin/xplad keys add volunteer_validator2 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/volunteer_validator2.mnemonics # xpla1unq7rvf4jkcpmqww09j0u8k37qkgjxm43llwx5 -- volunteer validator3 -/usr/bin/xplad keys add volunteer_validator3 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/volunteer_validator3.mnemonics +/usr/bin/xplad keys add volunteer_validator3 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/volunteer_validator3.mnemonics # 3. Add the genesis accounts /usr/bin/xplad add-genesis-account $(/usr/bin/xplad keys show validator1 -a --keyring-backend test --home $XPLAHOME) 100000000000000000000axpla --keyring-backend test --home $XPLAHOME @@ -49,8 +49,8 @@ rm -f /genesis/* for IDX in 1 2 3 4 do # 1) Copy the credentials - cp /opt/integration_test/validator$IDX/node_key.json $XPLAHOME/config - cp /opt/integration_test/validator$IDX/priv_validator_key.json $XPLAHOME/config + cp /opt/tests/e2e/validator$IDX/node_key.json $XPLAHOME/config + cp /opt/tests/e2e/validator$IDX/priv_validator_key.json $XPLAHOME/config # 2) Execute a gentx /usr/bin/xplad gentx validator$IDX 9000000000000000000axpla \ @@ -104,8 +104,8 @@ cp $XPLAHOME/config/genesis.json /genesis ### followings are for validator setting # 1. Copy the node setting files to the node home dir -cp -r /opt/integration_test/$MONIKER/* $XPLAHOME/config -cp -r /opt/integration_test/common_configs/* $XPLAHOME/config +cp -r /opt/tests/e2e/$MONIKER/* $XPLAHOME/config +cp -r /opt/tests/e2e/common_configs/* $XPLAHOME/config # 2. Get genesis.json from the shared cp /genesis/genesis.json $XPLAHOME/config diff --git a/integration_test/entrypoint_secondary.sh b/tests/e2e/entrypoint_secondary.sh similarity index 68% rename from integration_test/entrypoint_secondary.sh rename to tests/e2e/entrypoint_secondary.sh index 14feb52b..389fc7d8 100644 --- a/integration_test/entrypoint_secondary.sh +++ b/tests/e2e/entrypoint_secondary.sh @@ -1,19 +1,19 @@ #!/bin/sh -# MONIKER=validator1|validator2|validator3|validator4 sh /opt/integration_test/entrypoint.sh +# MONIKER=validator1|validator2|validator3|validator4 sh /opt/tests/e2e/entrypoint.sh # 1. chain init /usr/bin/xplad init $MONIKER --chain-id localtest_1-1 --home $XPLAHOME # 2. copy the node setting files to the node home dir -cp -r /opt/integration_test/$MONIKER/* $XPLAHOME/config -cp -r /opt/integration_test/common_configs/* $XPLAHOME/config +cp -r /opt/tests/e2e/$MONIKER/* $XPLAHOME/config +cp -r /opt/tests/e2e/common_configs/* $XPLAHOME/config sed -i "s/moniker = \"validator1\"/moniker = \"$MONIKER\"/g" $XPLAHOME/config/config.toml # 3. register my validator & users keyfile -/usr/bin/xplad keys add $MONIKER --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/$MONIKER.mnemonics -/usr/bin/xplad keys add user1 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/user1.mnemonics -/usr/bin/xplad keys add user2 --recover --keyring-backend test --home $XPLAHOME < /opt/integration_test/test_keys/user2.mnemonics +/usr/bin/xplad keys add $MONIKER --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/$MONIKER.mnemonics +/usr/bin/xplad keys add user1 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/user1.mnemonics +/usr/bin/xplad keys add user2 --recover --keyring-backend test --home $XPLAHOME < /opt/tests/e2e/test_keys/user2.mnemonics # 4. get genesis.json from the shared folder # "depends_on" in docker-compose.yml means that it depends on Dockerfile image, not completely wait for the entrypoint exeuction. diff --git a/integration_test/grpcclient_test.go b/tests/e2e/grpcclient_test.go similarity index 99% rename from integration_test/grpcclient_test.go rename to tests/e2e/grpcclient_test.go index 2d88b7bb..07e5b6bb 100644 --- a/integration_test/grpcclient_test.go +++ b/tests/e2e/grpcclient_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/integration_test/init_test.go b/tests/e2e/init_test.go similarity index 95% rename from integration_test/init_test.go rename to tests/e2e/init_test.go index 0b3f3f1c..fb1121ca 100644 --- a/integration_test/init_test.go +++ b/tests/e2e/init_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "log" diff --git a/integration_test/integration_test.go b/tests/e2e/integration_test.go similarity index 99% rename from integration_test/integration_test.go rename to tests/e2e/integration_test.go index 2cabc720..38aca948 100644 --- a/integration_test/integration_test.go +++ b/tests/e2e/integration_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/integration_test/misc/token.sol b/tests/e2e/misc/token.sol similarity index 100% rename from integration_test/misc/token.sol rename to tests/e2e/misc/token.sol diff --git a/integration_test/misc/token.sol.abi b/tests/e2e/misc/token.sol.abi similarity index 100% rename from integration_test/misc/token.sol.abi rename to tests/e2e/misc/token.sol.abi diff --git a/integration_test/misc/token.sol.bin b/tests/e2e/misc/token.sol.bin similarity index 100% rename from integration_test/misc/token.sol.bin rename to tests/e2e/misc/token.sol.bin diff --git a/integration_test/misc/token.wasm b/tests/e2e/misc/token.wasm similarity index 100% rename from integration_test/misc/token.wasm rename to tests/e2e/misc/token.wasm diff --git a/integration_test/test_keys/user1.mnemonics b/tests/e2e/test_keys/user1.mnemonics similarity index 100% rename from integration_test/test_keys/user1.mnemonics rename to tests/e2e/test_keys/user1.mnemonics diff --git a/integration_test/test_keys/user2.mnemonics b/tests/e2e/test_keys/user2.mnemonics similarity index 100% rename from integration_test/test_keys/user2.mnemonics rename to tests/e2e/test_keys/user2.mnemonics diff --git a/integration_test/test_keys/validator1.mnemonics b/tests/e2e/test_keys/validator1.mnemonics similarity index 100% rename from integration_test/test_keys/validator1.mnemonics rename to tests/e2e/test_keys/validator1.mnemonics diff --git a/integration_test/test_keys/validator2.mnemonics b/tests/e2e/test_keys/validator2.mnemonics similarity index 100% rename from integration_test/test_keys/validator2.mnemonics rename to tests/e2e/test_keys/validator2.mnemonics diff --git a/integration_test/test_keys/validator3.mnemonics b/tests/e2e/test_keys/validator3.mnemonics similarity index 100% rename from integration_test/test_keys/validator3.mnemonics rename to tests/e2e/test_keys/validator3.mnemonics diff --git a/integration_test/test_keys/validator4.mnemonics b/tests/e2e/test_keys/validator4.mnemonics similarity index 100% rename from integration_test/test_keys/validator4.mnemonics rename to tests/e2e/test_keys/validator4.mnemonics diff --git a/integration_test/test_keys/validator5_experimental.mnemonics b/tests/e2e/test_keys/validator5_experimental.mnemonics similarity index 100% rename from integration_test/test_keys/validator5_experimental.mnemonics rename to tests/e2e/test_keys/validator5_experimental.mnemonics diff --git a/integration_test/test_keys/volunteer_validator1.mnemonics b/tests/e2e/test_keys/volunteer_validator1.mnemonics similarity index 100% rename from integration_test/test_keys/volunteer_validator1.mnemonics rename to tests/e2e/test_keys/volunteer_validator1.mnemonics diff --git a/integration_test/test_keys/volunteer_validator2.mnemonics b/tests/e2e/test_keys/volunteer_validator2.mnemonics similarity index 100% rename from integration_test/test_keys/volunteer_validator2.mnemonics rename to tests/e2e/test_keys/volunteer_validator2.mnemonics diff --git a/integration_test/test_keys/volunteer_validator3.mnemonics b/tests/e2e/test_keys/volunteer_validator3.mnemonics similarity index 100% rename from integration_test/test_keys/volunteer_validator3.mnemonics rename to tests/e2e/test_keys/volunteer_validator3.mnemonics diff --git a/integration_test/token_test.go b/tests/e2e/token_test.go similarity index 99% rename from integration_test/token_test.go rename to tests/e2e/token_test.go index 19f60f7f..e6d71ca5 100644 --- a/integration_test/token_test.go +++ b/tests/e2e/token_test.go @@ -1,7 +1,7 @@ // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. -package integrationtest +package e2e import ( "errors" diff --git a/integration_test/util_test.go b/tests/e2e/util_test.go similarity index 99% rename from integration_test/util_test.go rename to tests/e2e/util_test.go index ad175903..a562a1e6 100644 --- a/integration_test/util_test.go +++ b/tests/e2e/util_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/integration_test/validator1/node_key.json b/tests/e2e/validator1/node_key.json similarity index 100% rename from integration_test/validator1/node_key.json rename to tests/e2e/validator1/node_key.json diff --git a/integration_test/validator1/priv_validator_key.json b/tests/e2e/validator1/priv_validator_key.json similarity index 100% rename from integration_test/validator1/priv_validator_key.json rename to tests/e2e/validator1/priv_validator_key.json diff --git a/integration_test/validator2/node_key.json b/tests/e2e/validator2/node_key.json similarity index 100% rename from integration_test/validator2/node_key.json rename to tests/e2e/validator2/node_key.json diff --git a/integration_test/validator2/priv_validator_key.json b/tests/e2e/validator2/priv_validator_key.json similarity index 100% rename from integration_test/validator2/priv_validator_key.json rename to tests/e2e/validator2/priv_validator_key.json diff --git a/integration_test/validator3/node_key.json b/tests/e2e/validator3/node_key.json similarity index 100% rename from integration_test/validator3/node_key.json rename to tests/e2e/validator3/node_key.json diff --git a/integration_test/validator3/priv_validator_key.json b/tests/e2e/validator3/priv_validator_key.json similarity index 100% rename from integration_test/validator3/priv_validator_key.json rename to tests/e2e/validator3/priv_validator_key.json diff --git a/integration_test/validator4/node_key.json b/tests/e2e/validator4/node_key.json similarity index 100% rename from integration_test/validator4/node_key.json rename to tests/e2e/validator4/node_key.json diff --git a/integration_test/validator4/priv_validator_key.json b/tests/e2e/validator4/priv_validator_key.json similarity index 100% rename from integration_test/validator4/priv_validator_key.json rename to tests/e2e/validator4/priv_validator_key.json diff --git a/integration_test/validator5_experimental/node_key.json b/tests/e2e/validator5_experimental/node_key.json similarity index 100% rename from integration_test/validator5_experimental/node_key.json rename to tests/e2e/validator5_experimental/node_key.json diff --git a/integration_test/validator5_experimental/priv_validator_key.json b/tests/e2e/validator5_experimental/priv_validator_key.json similarity index 100% rename from integration_test/validator5_experimental/priv_validator_key.json rename to tests/e2e/validator5_experimental/priv_validator_key.json diff --git a/integration_test/volunteer_validator1/node_key.json b/tests/e2e/volunteer_validator1/node_key.json similarity index 100% rename from integration_test/volunteer_validator1/node_key.json rename to tests/e2e/volunteer_validator1/node_key.json diff --git a/integration_test/volunteer_validator1/priv_validator_key.json b/tests/e2e/volunteer_validator1/priv_validator_key.json similarity index 100% rename from integration_test/volunteer_validator1/priv_validator_key.json rename to tests/e2e/volunteer_validator1/priv_validator_key.json diff --git a/integration_test/volunteer_validator2/node_key.json b/tests/e2e/volunteer_validator2/node_key.json similarity index 100% rename from integration_test/volunteer_validator2/node_key.json rename to tests/e2e/volunteer_validator2/node_key.json diff --git a/integration_test/volunteer_validator2/priv_validator_key.json b/tests/e2e/volunteer_validator2/priv_validator_key.json similarity index 100% rename from integration_test/volunteer_validator2/priv_validator_key.json rename to tests/e2e/volunteer_validator2/priv_validator_key.json diff --git a/integration_test/volunteer_validator3/node_key.json b/tests/e2e/volunteer_validator3/node_key.json similarity index 100% rename from integration_test/volunteer_validator3/node_key.json rename to tests/e2e/volunteer_validator3/node_key.json diff --git a/integration_test/volunteer_validator3/priv_validator_key.json b/tests/e2e/volunteer_validator3/priv_validator_key.json similarity index 100% rename from integration_test/volunteer_validator3/priv_validator_key.json rename to tests/e2e/volunteer_validator3/priv_validator_key.json diff --git a/integration_test/wallet_cosmos_test.go b/tests/e2e/wallet_cosmos_test.go similarity index 99% rename from integration_test/wallet_cosmos_test.go rename to tests/e2e/wallet_cosmos_test.go index a3d5a84b..a7c9df87 100644 --- a/integration_test/wallet_cosmos_test.go +++ b/tests/e2e/wallet_cosmos_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/integration_test/wallet_evm_test.go b/tests/e2e/wallet_evm_test.go similarity index 99% rename from integration_test/wallet_evm_test.go rename to tests/e2e/wallet_evm_test.go index 14dacb73..2f4f1f3f 100644 --- a/integration_test/wallet_evm_test.go +++ b/tests/e2e/wallet_evm_test.go @@ -1,4 +1,4 @@ -package integrationtest +package e2e import ( "context" diff --git a/x/reward/abci_test.go b/tests/integration/reward/abci_test.go similarity index 58% rename from x/reward/abci_test.go rename to tests/integration/reward/abci_test.go index 28522558..9b3aa728 100644 --- a/x/reward/abci_test.go +++ b/tests/integration/reward/abci_test.go @@ -10,8 +10,8 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/xpladev/xpla/tests/integration/testutil" "github.com/xpladev/xpla/x/reward" - "github.com/xpladev/xpla/x/reward/keeper" ) // TestBeginBlocker @@ -20,46 +20,46 @@ import ( // 3. 1.1 fee // 4. process 1 block func TestBeginBlocker(t *testing.T) { - input := keeper.CreateTestInput(t) - sh := staking.NewHandler(input.StakingKeeper) + input := testutil.CreateTestInput(t) + sh := staking.NewHandler(input.StakingKeeper.Keeper) sdk.DefaultPowerReduction = sdk.NewIntFromUint64(1000000000000000000) defaultFee := sdk.NewInt(11).Mul(sdk.DefaultPowerReduction).Quo(sdk.NewInt(10)) // 1.1 // create validator & self delegation - for i := 0; i < keeper.ValidatorCount; i++ { - err := input.InitAccountWithCoins(sdk.AccAddress(keeper.Pks[i].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100)))) + for i := 0; i < testutil.ValidatorCount; i++ { + err := input.InitAccountWithCoins(sdk.AccAddress(testutil.Pks[i].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100)))) require.NoError(t, err) - valAddress := sdk.ValAddress(keeper.Pks[i].Address()) - _, err = sh(input.Ctx, keeper.NewTestMsgCreateValidator(valAddress, keeper.Pks[i], input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100))) + valAddress := sdk.ValAddress(testutil.Pks[i].Address()) + _, err = sh(input.Ctx, testutil.NewMsgCreateValidator(valAddress, testutil.Pks[i], input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100))) require.NoError(t, err) } // validator settlement delegation - err := input.InitAccountWithCoins(sdk.AccAddress(keeper.Pks[keeper.ValidatorSettlementIndex].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100)))) + err := input.InitAccountWithCoins(sdk.AccAddress(testutil.Pks[testutil.ValidatorSettlementIndex].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 100)))) require.NoError(t, err) - for i := 0; i < keeper.ValidatorCount; i++ { - valAddress := sdk.ValAddress(keeper.Pks[i].Address()) + for i := 0; i < testutil.ValidatorCount; i++ { + valAddress := sdk.ValAddress(testutil.Pks[i].Address()) - _, err = sh(input.Ctx, keeper.NewTestMsgDelegate(sdk.AccAddress(keeper.Pks[keeper.ValidatorSettlementIndex].Address()), valAddress, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 10))) + _, err = sh(input.Ctx, testutil.NewMsgDelegate(sdk.AccAddress(testutil.Pks[testutil.ValidatorSettlementIndex].Address()), valAddress, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 10))) require.NoError(t, err) } - staking.EndBlocker(input.Ctx, input.StakingKeeper) + staking.EndBlocker(input.Ctx, input.StakingKeeper.Keeper) // checkt balance & staking - for i := 0; i < keeper.ValidatorCount; i++ { + for i := 0; i < testutil.ValidatorCount; i++ { require.Equal( t, sdk.NewCoins(sdk.Coin{ Denom: "", Amount: sdk.ZeroInt(), }), - input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(keeper.Pks[i].Address())), + input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(testutil.Pks[i].Address())), ) - valAddress := sdk.ValAddress(keeper.Pks[i].Address()) + valAddress := sdk.ValAddress(testutil.Pks[i].Address()) require.Equal( t, input.StakingKeeper.TokensFromConsensusPower(input.Ctx, 110), input.StakingKeeper.Validator(input.Ctx, valAddress).GetBondedTokens(), @@ -71,25 +71,25 @@ func TestBeginBlocker(t *testing.T) { Denom: "", Amount: sdk.ZeroInt(), }), - input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(keeper.Pks[keeper.ValidatorSettlementIndex].Address())), + input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(testutil.Pks[testutil.ValidatorSettlementIndex].Address())), ) // fund fee - err = input.InitAccountWithCoins(sdk.AccAddress(keeper.Pks[keeper.TempIndex].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, defaultFee))) + err = input.InitAccountWithCoins(sdk.AccAddress(testutil.Pks[testutil.TempIndex].Address()), sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, defaultFee))) require.NoError(t, err) - err = input.BankKeeper.SendCoinsFromAccountToModule(input.Ctx, sdk.AccAddress(keeper.Pks[keeper.TempIndex].Address()), authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, defaultFee))) + err = input.BankKeeper.SendCoinsFromAccountToModule(input.Ctx, sdk.AccAddress(testutil.Pks[testutil.TempIndex].Address()), authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, defaultFee))) require.NoError(t, err) // distirubte - input.DistrKeeper.SetPreviousProposerConsAddr(input.Ctx, sdk.ConsAddress(keeper.Pks[0].Address())) + input.DistrKeeper.SetPreviousProposerConsAddr(input.Ctx, sdk.ConsAddress(testutil.Pks[0].Address())) input.Ctx = input.Ctx.WithBlockHeight(input.Ctx.BlockHeight() + 2) voteInfoes := []types.VoteInfo{} - for i := 0; i < keeper.ValidatorCount; i++ { + for i := 0; i < testutil.ValidatorCount; i++ { voteInfoes = append(voteInfoes, types.VoteInfo{ Validator: types.Validator{ - Address: keeper.Pks[i].Address().Bytes(), + Address: testutil.Pks[i].Address().Bytes(), Power: int64(110), }, }) @@ -97,7 +97,7 @@ func TestBeginBlocker(t *testing.T) { distribution.BeginBlocker(input.Ctx, types.RequestBeginBlock{ Header: tmproto.Header{ - ProposerAddress: keeper.Pks[0].Address().Bytes(), + ProposerAddress: testutil.Pks[0].Address().Bytes(), }, LastCommitInfo: types.LastCommitInfo{ Round: int32(1), @@ -129,6 +129,6 @@ func TestBeginBlocker(t *testing.T) { // 3. reserve account (0.0009) require.Equal( t, "900000000000000stake", - input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(keeper.Pks[keeper.ReserveIndex].Address())).String(), + input.BankKeeper.GetAllBalances(input.Ctx, sdk.AccAddress(testutil.Pks[testutil.ReserveIndex].Address())).String(), ) } diff --git a/x/reward/keeper/test_utils.go b/tests/integration/testutil/common.go similarity index 78% rename from x/reward/keeper/test_utils.go rename to tests/integration/testutil/common.go index 92a29a9d..48a80874 100644 --- a/x/reward/keeper/test_utils.go +++ b/tests/integration/testutil/common.go @@ -1,4 +1,4 @@ -package keeper +package testutil import ( "testing" @@ -12,10 +12,8 @@ import ( "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" dbm "github.com/tendermint/tm-db" - "github.com/xpladev/xpla/x/reward/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types" - cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" simparams "github.com/cosmos/cosmos-sdk/simapp/params" "github.com/cosmos/cosmos-sdk/std" "github.com/cosmos/cosmos-sdk/types/module" @@ -35,9 +33,16 @@ import ( params "github.com/cosmos/cosmos-sdk/x/params" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/cosmos-sdk/x/slashing" + slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" + slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + rewardkeeper "github.com/xpladev/xpla/x/reward/keeper" + rewardtypes "github.com/xpladev/xpla/x/reward/types" + stakingkeeper "github.com/xpladev/xpla/x/staking/keeper" + volunteerkeeper "github.com/xpladev/xpla/x/volunteer/keeper" + volunteertypes "github.com/xpladev/xpla/x/volunteer/types" ) const ( @@ -60,6 +65,7 @@ var ModuleBasics = module.NewBasicManager( bank.AppModuleBasic{}, distr.AppModuleBasic{}, staking.AppModuleBasic{}, + slashing.AppModuleBasic{}, mint.AppModuleBasic{}, params.AppModuleBasic{}, ) @@ -76,8 +82,8 @@ func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig { ModuleBasics.RegisterLegacyAminoCodec(amino) ModuleBasics.RegisterInterfaces(interfaceRegistry) - types.RegisterLegacyAminoCodec(amino) - types.RegisterInterfaces(interfaceRegistry) + rewardtypes.RegisterLegacyAminoCodec(amino) + rewardtypes.RegisterInterfaces(interfaceRegistry) return simparams.EncodingConfig{ InterfaceRegistry: interfaceRegistry, Marshaler: marshaler, @@ -88,13 +94,17 @@ func MakeEncodingConfig(_ *testing.T) simparams.EncodingConfig { // TestInput nolint type TestInput struct { - Ctx sdk.Context - Cdc *codec.LegacyAmino - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.Keeper - RewardKeeper Keeper - StakingKeeper stakingkeeper.Keeper - DistrKeeper distrkeeper.Keeper + Ctx sdk.Context + Cdc *codec.LegacyAmino + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.Keeper + RewardKeeper rewardkeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + DistrKeeper distrkeeper.Keeper + VolunteerKeeper volunteerkeeper.Keeper + + StakingHandler sdk.Handler } // CreateTestInput nolint @@ -103,10 +113,12 @@ func CreateTestInput(t *testing.T) TestInput { keyBank := sdk.NewKVStoreKey(banktypes.StoreKey) keyParams := sdk.NewKVStoreKey(paramstypes.StoreKey) tKeyParams := sdk.NewTransientStoreKey(paramstypes.TStoreKey) - keyReward := sdk.NewKVStoreKey(types.StoreKey) + keyReward := sdk.NewKVStoreKey(rewardtypes.StoreKey) keyStaking := sdk.NewKVStoreKey(stakingtypes.StoreKey) + keySlahsing := sdk.NewKVStoreKey(slashingtypes.StoreKey) keyDistr := sdk.NewKVStoreKey(distrtypes.StoreKey) keyMint := sdk.NewKVStoreKey(minttypes.StoreKey) + keyVolunteer := sdk.NewKVStoreKey(volunteertypes.StoreKey) db := dbm.NewMemDB() ms := store.NewCommitMultiStore(db) @@ -120,8 +132,10 @@ func CreateTestInput(t *testing.T) TestInput { ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyReward, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyStaking, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(keySlahsing, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyDistr, sdk.StoreTypeIAVL, db) ms.MountStoreWithDB(keyMint, sdk.StoreTypeIAVL, db) + ms.MountStoreWithDB(keyVolunteer, sdk.StoreTypeIAVL, db) require.NoError(t, ms.LoadLatestVersion()) @@ -138,19 +152,21 @@ func CreateTestInput(t *testing.T) TestInput { stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, distrtypes.ModuleName: nil, - types.ModuleName: nil, + rewardtypes.ModuleName: nil, } paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, keyParams, tKeyParams) accountKeeper := authkeeper.NewAccountKeeper(appCodec, keyAcc, paramsKeeper.Subspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms) bankKeeper := bankkeeper.NewBaseKeeper(appCodec, keyBank, accountKeeper, paramsKeeper.Subspace(banktypes.ModuleName), blackListAddrs) + var volunteerKeeper volunteerkeeper.Keeper stakingKeeper := stakingkeeper.NewKeeper( appCodec, keyStaking, accountKeeper, bankKeeper, paramsKeeper.Subspace(stakingtypes.ModuleName), + &volunteerKeeper, ) stakingParams := stakingtypes.DefaultParams() @@ -165,20 +181,25 @@ func CreateTestInput(t *testing.T) TestInput { accountKeeper, bankKeeper, stakingKeeper, authtypes.FeeCollectorName, blackListAddrs) + slashingKeeper := slashingkeeper.NewKeeper(appCodec, keySlahsing, &stakingKeeper, paramsKeeper.Subspace(slashingtypes.ModuleName)) + slashingKeeper.SetParams(ctx, slashingtypes.DefaultParams()) + + volunteerKeeper = volunteerkeeper.NewKeeper(keyVolunteer, appCodec, &stakingKeeper, distrKeeper) + distrKeeper.SetFeePool(ctx, distrtypes.InitialFeePool()) distrParams := distrtypes.DefaultParams() distrParams.CommunityTax = sdk.ZeroDec() distrParams.BaseProposerReward = sdk.ZeroDec() distrParams.BonusProposerReward = sdk.ZeroDec() distrKeeper.SetParams(ctx, distrParams) - stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(distrKeeper.Hooks())) + stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(distrKeeper.Hooks(), slashingKeeper.Hooks())) mintKeeper.SetParams(ctx, minttypes.DefaultParams()) feeCollectorAcc := authtypes.NewEmptyModuleAccount(authtypes.FeeCollectorName) notBondedPool := authtypes.NewEmptyModuleAccount(stakingtypes.NotBondedPoolName, authtypes.Burner, authtypes.Staking) bondPool := authtypes.NewEmptyModuleAccount(stakingtypes.BondedPoolName, authtypes.Burner, authtypes.Staking) distrAcc := authtypes.NewEmptyModuleAccount(distrtypes.ModuleName) - rewardAcc := authtypes.NewEmptyModuleAccount(types.ModuleName) + rewardAcc := authtypes.NewEmptyModuleAccount(rewardtypes.ModuleName) accountKeeper.SetModuleAccount(ctx, feeCollectorAcc) accountKeeper.SetModuleAccount(ctx, bondPool) @@ -186,10 +207,10 @@ func CreateTestInput(t *testing.T) TestInput { accountKeeper.SetModuleAccount(ctx, distrAcc) accountKeeper.SetModuleAccount(ctx, rewardAcc) - keeper := NewKeeper( + keeper := rewardkeeper.NewKeeper( appCodec, keyReward, - paramsKeeper.Subspace(types.ModuleName), + paramsKeeper.Subspace(rewardtypes.ModuleName), accountKeeper, bankKeeper, stakingKeeper, @@ -197,7 +218,7 @@ func CreateTestInput(t *testing.T) TestInput { mintKeeper, ) - defaults := types.Params{ + defaults := rewardtypes.Params{ FeePoolRate: sdk.NewDecWithPrec(20, 2), CommunityPoolRate: sdk.NewDecWithPrec(79, 2), ReserveRate: sdk.NewDecWithPrec(1, 2), @@ -206,7 +227,9 @@ func CreateTestInput(t *testing.T) TestInput { } keeper.SetParams(ctx, defaults) - return TestInput{ctx, legacyAmino, accountKeeper, bankKeeper, keeper, stakingKeeper, distrKeeper} + sh := staking.NewHandler(stakingKeeper.Keeper) + + return TestInput{ctx, legacyAmino, accountKeeper, bankKeeper, keeper, stakingKeeper, slashingKeeper, distrKeeper, volunteerKeeper, sh} } func (ti *TestInput) InitAccountWithCoins(addr sdk.AccAddress, coins sdk.Coins) error { @@ -222,22 +245,3 @@ func (ti *TestInput) InitAccountWithCoins(addr sdk.AccAddress, coins sdk.Coins) return nil } - -// NewTestMsgCreateValidator test msg creator -func NewTestMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { - commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(10, 2), sdk.OneDec(), sdk.OneDec()) - msg, _ := stakingtypes.NewMsgCreateValidator( - address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), - stakingtypes.Description{}, commission, sdk.OneInt(), - ) - - return msg -} - -// NewTestMsgDelegate test msg creator -func NewTestMsgDelegate(delegatorAddress sdk.AccAddress, validatorAddress sdk.ValAddress, amt sdk.Int) *stakingtypes.MsgDelegate { - - return stakingtypes.NewMsgDelegate( - delegatorAddress, validatorAddress, sdk.NewCoin(sdk.DefaultBondDenom, amt), - ) -} diff --git a/tests/integration/testutil/staking.go b/tests/integration/testutil/staking.go new file mode 100644 index 00000000..c6801303 --- /dev/null +++ b/tests/integration/testutil/staking.go @@ -0,0 +1,27 @@ +package testutil + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// NewMsgCreateValidator test msg creator +func NewMsgCreateValidator(address sdk.ValAddress, pubKey cryptotypes.PubKey, amt sdk.Int) *stakingtypes.MsgCreateValidator { + commission := stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(10, 2), sdk.OneDec(), sdk.OneDec()) + msg, _ := stakingtypes.NewMsgCreateValidator( + address, pubKey, sdk.NewCoin(sdk.DefaultBondDenom, amt), + stakingtypes.Description{}, commission, sdk.OneInt(), + ) + + return msg +} + +// NewMsgDelegate test msg creator +func NewMsgDelegate(delegatorAddress sdk.AccAddress, validatorAddress sdk.ValAddress, amt sdk.Int) *stakingtypes.MsgDelegate { + + return stakingtypes.NewMsgDelegate( + delegatorAddress, validatorAddress, sdk.NewCoin(sdk.DefaultBondDenom, amt), + ) +}