Skip to content

Commit

Permalink
nixos/tests/e2e: install deposit contract
Browse files Browse the repository at this point in the history
  • Loading branch information
marijanp committed Apr 3, 2024
1 parent 9935cd8 commit 9cdd94b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ in
./tests/end-to-end.nix
{
inherit mkKairosHostConfig;
inherit (self.packages.${pkgs.system}) kairos;
inherit (self.packages.${pkgs.system}) kairos kairos-contracts;
cctlModule = self.nixosModules.cctl;
inherit (inputs.csprpkgs.packages.${pkgs.system}) casper-client-rs;
};
Expand Down
71 changes: 40 additions & 31 deletions nixos/tests/end-to-end.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, mkKairosHostConfig
, kairos
, testResources ? ../../kairos-cli/tests/fixtures
, kairos-contracts
, cctlModule
, casper-client-rs
}:
Expand Down Expand Up @@ -29,50 +30,58 @@ nixosTest {
};
};

testScript = ''
import json
testScript =
let
cctlUsersDirectory = "/var/lib/cctl/assets/users";
in
''
import json
start_all()
start_all()
kairos.wait_for_unit("cctl.service")
kairos.wait_for_unit("cctl.service")
kairos.wait_for_unit("kairos.service")
kairos.wait_for_unit("nginx.service")
kairos.wait_for_open_port(80)
kairos.wait_for_unit("kairos.service")
kairos.wait_for_unit("nginx.service")
kairos.wait_for_open_port(80)
client.wait_for_unit ("multi-user.target")
client.wait_for_unit ("multi-user.target")
kairos.succeed("casper-client get-node-status --node-address http://localhost:11101")
kairos.succeed("casper-client get-node-status --node-address http://localhost:11101")
deposit_request = { "public_key": "publickey", "amount": 10 }
# REST API
client.succeed("curl -X POST http://kairos/api/v1/deposit -H 'Content-Type: application/json' -d '{}'".format(json.dumps(deposit_request)))
# chain-name see: https://github.com/casper-network/cctl/blob/745155d080934c409d98266f912b8fd2b7e28a00/utils/constants.sh#L66
# port see: https://github.com/casper-network/cctl/blob/745155d080934c409d98266f912b8fd2b7e28a00/utils/constants.sh#L13
kairos.succeed("casper-client put-deploy --node-address http://localhost:11101 --chain-name cspr-dev-cctl --secret-key $(ls ${cctlUsersDirectory}/user-1/secret_key.pem) --payment-amount 5000000000000 --session-path ${kairos-contracts}/bin/deposit-contract-optimized.wasm")
transfer_request = { "from": "publickey", "signature": "signature", "to": "publickey", "amount": 10 }
client.succeed("curl -X POST http://kairos/api/v1/transfer -H 'Content-Type: application/json' -d '{}'".format(json.dumps(transfer_request)))
# REST API
deposit_request = { "public_key": "publickey", "amount": 10 }
client.succeed("curl -X POST http://kairos/api/v1/deposit -H 'Content-Type: application/json' -d '{}'".format(json.dumps(deposit_request)))
withdraw_request = { "public_key": "publickey", "signature": "signature", "amount": 10 }
client.succeed("curl -X POST http://kairos/api/v1/withdraw -H 'Content-Type: application/json' -d '{}'".format(json.dumps(withdraw_request)))
transfer_request = { "from": "publickey", "signature": "signature", "to": "publickey", "amount": 10 }
client.succeed("curl -X POST http://kairos/api/v1/transfer -H 'Content-Type: application/json' -d '{}'".format(json.dumps(transfer_request)))
# CLI with ed25519
cli_output = client.succeed("kairos-cli deposit --amount 1000 --private-key ${testResources}/ed25519/secret_key.pem")
assert "ok\n" in cli_output
withdraw_request = { "public_key": "publickey", "signature": "signature", "amount": 10 }
client.succeed("curl -X POST http://kairos/api/v1/withdraw -H 'Content-Type: application/json' -d '{}'".format(json.dumps(withdraw_request)))
cli_output = client.succeed("kairos-cli transfer --recipient '01a26419a7d82b2263deaedea32d35eee8ae1c850bd477f62a82939f06e80df356' --amount 1000 --private-key ${testResources}/ed25519/secret_key.pem")
assert "ok\n" in cli_output
# CLI with ed25519
cli_output = client.succeed("kairos-cli deposit --amount 1000 --private-key ${testResources}/ed25519/secret_key.pem")
assert "ok\n" in cli_output
cli_output = client.succeed("kairos-cli withdraw --amount 1000 --private-key ${testResources}/ed25519/secret_key.pem")
assert "ok\n" in cli_output
cli_output = client.succeed("kairos-cli transfer --recipient '01a26419a7d82b2263deaedea32d35eee8ae1c850bd477f62a82939f06e80df356' --amount 1000 --private-key ${testResources}/ed25519/secret_key.pem")
assert "ok\n" in cli_output
# CLI with secp256k1
cli_output = client.succeed("kairos-cli deposit --amount 1000 --private-key ${testResources}/secp256k1/secret_key.pem")
assert "ok\n" in cli_output
cli_output = client.succeed("kairos-cli withdraw --amount 1000 --private-key ${testResources}/ed25519/secret_key.pem")
assert "ok\n" in cli_output
cli_output = client.succeed("kairos-cli transfer --recipient '01a26419a7d82b2263deaedea32d35eee8ae1c850bd477f62a82939f06e80df356' --amount 1000 --private-key ${testResources}/secp256k1/secret_key.pem")
assert "ok\n" in cli_output
# CLI with secp256k1
cli_output = client.succeed("kairos-cli deposit --amount 1000 --private-key ${testResources}/secp256k1/secret_key.pem")
assert "ok\n" in cli_output
cli_output = client.succeed("kairos-cli withdraw --amount 1000 --private-key ${testResources}/secp256k1/secret_key.pem")
assert "ok\n" in cli_output
'';
cli_output = client.succeed("kairos-cli transfer --recipient '01a26419a7d82b2263deaedea32d35eee8ae1c850bd477f62a82939f06e80df356' --amount 1000 --private-key ${testResources}/secp256k1/secret_key.pem")
assert "ok\n" in cli_output
cli_output = client.succeed("kairos-cli withdraw --amount 1000 --private-key ${testResources}/secp256k1/secret_key.pem")
assert "ok\n" in cli_output
'';
}

0 comments on commit 9cdd94b

Please sign in to comment.