Skip to content

Commit

Permalink
feat: framework for e2e testing upgrades (#662)
Browse files Browse the repository at this point in the history
* feat(e2e): upgrade from genesis

* feat: use unionvisor in upgrade e2e

* fix: call unionvisor correctly

* fix: revert 0.X.1 version names

* feat: test v0.9.0 -> v0.10.0

* chore: nix fmt

* chore: updated workflows with upgrade-from-genesis e2e

* chore: remove unused inputs

* chore: spelling
  • Loading branch information
PoisonPhang authored Sep 8, 2023
1 parent 6ae7799 commit 026a2e9
Show file tree
Hide file tree
Showing 13 changed files with 992 additions and 667 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ jobs:
"spellcheck",
"treefmt-check",
"union-runs",
"upgrade-from-genesis",
"virtualisation-works"
]
)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
nixbuild_token: ${{ secrets.nixbuild_token }}
access-tokens: github.com=${{ secrets.github-token }}
with:
filter_builds: '((.top_attr == "checks") and (.system == "x86_64-linux") and (.attr == "virtualisation-works" or .attr == "ensure-blocks" or .attr == "sepolia-runs" or .attr == "union-runs" or .attr == "epoch-completes" or .attr == "forced-set-rotation"))'
filter_builds: '((.top_attr == "checks") and (.system == "x86_64-linux") and (.attr == "virtualisation-works" or .attr == "ensure-blocks" or .attr == "sepolia-runs" or .attr == "union-runs" or .attr == "epoch-completes" or .attr == "forced-set-rotation" or .attr == "upgrade-from-genesis"))'
2 changes: 2 additions & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ cratedir
crisiskeeper
crisistypes
ctypes
dasel
dataconnector
datadir
datetime
Expand Down Expand Up @@ -577,6 +578,7 @@ unionmoduletypes
unionp
unionsimulation
unionvisor
unionvisorbn
unjail
unjailed
unmarshal
Expand Down
6 changes: 5 additions & 1 deletion e2e/all-tests.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ lib, withSystem, inputs, ... }: {
flake.checks = lib.genAttrs [ "x86_64-linux" "aarch64-linux" ]
(lib.flip withSystem ({ e2e, networks, pkgs, nixpkgs, crane, ... }:
(lib.flip withSystem ({ e2e, networks, pkgs, nixpkgs, crane, self', ... }:
let
epoch-staking = import ./epoch-staking.nix { inherit e2e pkgs; };
upgrades = import ./upgrades.nix { inherit e2e pkgs; unionvisor = self'.packages.unionvisor; bundle = self'.packages.bundle-testnet; };
in
{
ensure-blocks = import ./ensure-blocks/ensure-blocks.nix { inherit e2e networks pkgs nixpkgs crane; };
Expand All @@ -11,6 +12,9 @@
epoch-completes = epoch-staking.epoch-completes;
forced-set-rotation = epoch-staking.forced-set-rotation;

# Tests from ./upgrades.nix
upgrade-from-genesis = upgrades.upgrade-from-genesis;

virtualisation-works = e2e.mkTest {
name = "devnet";
nodes = {
Expand Down
19 changes: 17 additions & 2 deletions e2e/e2e.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ inputs, ... }: {
perSystem = { pkgs, nixpkgs, system, networks, ... }:
perSystem = { pkgs, nixpkgs, system, networks, inputs', ... }:
let
mkTest =
let
Expand Down Expand Up @@ -31,6 +31,21 @@
};
};

unionTestnetGenesisNode = {
node = { pkgs, ... }: {
imports = [
inputs.arion.nixosModules.arion
];
virtualisation = {
diskSize = 4 * 1024;
arion = {
backend = "docker";
projects.union-devnet.settings = networks.devnet-minimal;
};
};
};
};

unionNode = {
wait_for_console_text = "height=[1-9][0-9]*";
wait_for_open_port = 26657;
Expand All @@ -50,7 +65,7 @@
in
{
_module.args.e2e = {
inherit mkTest unionNode sepoliaNode;
inherit mkTest unionNode sepoliaNode unionTestnetGenesisNode;

mkTestWithDevnetSetup = { name, testScript, nodes }:
mkTest {
Expand Down
55 changes: 55 additions & 0 deletions e2e/upgrades.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{ e2e, pkgs, unionvisor, bundle, ... }:
let
unionvisorbn = pkgs.lib.meta.getExe unionvisor;

mkUpgradeProposal = version: height: pkgs.runCommand "upgrade-proposal" { } ''
mkdir -p $out
echo '{
"messages": [
{
"@type": "/cosmos.upgrade.v1beta1.MsgSoftwareUpgrade",
"authority": "union10d07y265gmmuvt4z0w9aw880jnsr700js4jdcz",
"plan": {
"name": "${version}",
"height": "${toString height}",
"info": "${version}"
}
}
],
"deposit": "15000000stake",
"title": "${version}",
"summary": "Upgrade to ${version}"
}' > proposal-${version}.json
mv proposal-${version}.json $out
'';

upgradeTo = version: height: ''
union.succeed('docker cp ${mkUpgradeProposal version height}/proposal-${version}.json devnet-minimal-uniond-0-1:/proposal-${version}.json')
union.succeed('docker exec devnet-minimal-uniond-0-1 ${unionvisorbn} --root . call --bundle ${bundle} -- tx gov submit-proposal proposal-${version}.json --from val-0 --keyring-backend test --home ./home -y')
union.succeed('docker exec devnet-minimal-uniond-0-1 ${unionvisorbn} --root . call --bundle ${bundle} -- tx gov vote 1 yes --keyring-backend test --from val-0 --home ./home -y')
union.succeed('docker exec devnet-minimal-uniond-1-1 ${unionvisorbn} --root . call --bundle ${bundle} -- tx gov vote 1 yes --keyring-backend test --from val-1 --home ./home -y')
union.succeed('docker exec devnet-minimal-uniond-2-1 ${unionvisorbn} --root . call --bundle ${bundle} -- tx gov vote 1 yes --keyring-backend test --from val-2 --home ./home -y')
union.succeed('docker exec devnet-minimal-uniond-3-1 ${unionvisorbn} --root . call --bundle ${bundle} -- tx gov vote 1 yes --keyring-backend test --from val-3 --home ./home -y')
union.wait_until_succeeds('[[ $(curl "http://localhost:26660/block" --fail --silent | ${pkgs.lib.meta.getExe pkgs.jq} ".result.block.header.height | tonumber > ${toString height}") == "true" ]]')
'';
in
{
upgrade-from-genesis = e2e.mkTest {
name = "upgrade-from-genesis";

testScript = ''
union.wait_for_open_port(${toString e2e.unionNode.wait_for_open_port})
# Ensure the union network commits more than one block
union.wait_until_succeeds('[[ $(curl "http://localhost:26660/block" --fail --silent | ${pkgs.lib.meta.getExe pkgs.jq} ".result.block.header.height | tonumber > 1") == "true" ]]')
${upgradeTo "v0.9.0" 10}
${upgradeTo "v0.10.0" 20}
'';

nodes = {
union = e2e.unionTestnetGenesisNode.node;
};
};
}
Loading

0 comments on commit 026a2e9

Please sign in to comment.