-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
7,649 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
export NODE_IMAGE=public.ecr.aws/p6e8q1z1/aleph-node:latest | ||
# key derived from "//0" | ||
export NODE_ID=5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH | ||
export ALICE=5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY | ||
|
||
mkdir -p docker/data/ | ||
|
||
# generate chainspec | ||
docker run --rm -v $(pwd)/docker/data:/data --entrypoint "/bin/sh" -e RUST_LOG=debug "${NODE_IMAGE}" -c \ | ||
"aleph-node bootstrap-chain --base-path /data --account-ids $NODE_ID --faucet-account-id $ALICE --sudo-account-id $NODE_ID --chain-id a0smnet --token-symbol SZERO --chain-name 'Aleph Zero Smartnet' > /data/chainspec.smartnet.json" | ||
|
||
# Get bootnode peer id | ||
export BOOTNODE_PEER_ID=$(docker run --rm -v $(pwd)/docker/data:/data --entrypoint "/bin/sh" -e RUST_LOG=info "${NODE_IMAGE}" -c "aleph-node key inspect-node-key --file /data/$NODE_ID/p2p_secret") | ||
|
||
docker-compose -f docker/smartnet-compose.yml up --remove-orphans | ||
|
||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
name: e2e-tests-contracts | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- 'contracts/**' | ||
push: | ||
paths: | ||
- 'contracts/**' | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
run-tests: | ||
name: Run smart contracts test suite | ||
runs-on: ubuntu-latest | ||
env: | ||
RUST_BACKTRACE: full | ||
steps: | ||
|
||
- name: Install binaryen | ||
run: | | ||
wget https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz | ||
tar xvzf binaryen-version_101-x86_64-linux.tar.gz | ||
cd binaryen-version_101 | ||
sudo cp -r bin/* /bin | ||
sudo cp -r include/* /usr/include | ||
sudo cp -r lib64/* /lib64 | ||
- name: Display binaryen version | ||
shell: bash | ||
run: wasm-opt --version | ||
|
||
- name: Checkout Source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Rust Toolchain | ||
uses: actions-rs/toolchain@v1 | ||
|
||
- name: Install WASM target | ||
run: rustup target add wasm32-unknown-unknown | ||
|
||
- name: Install rust-src | ||
run: rustup component add rust-src | ||
|
||
- name: Restore cache | ||
uses: ./.github/actions/restore-cache | ||
with: | ||
target-key: e2e-contracts | ||
cargo-key: e2e-contracts | ||
cache-version: v2 | ||
cargo-targets: e2e-tests-contracts/target/ | ||
|
||
- name: Install cargo-contract | ||
run: | | ||
cargo install cargo-dylint dylint-link --force | ||
# revision merging Hans's PR changes [fix for node URL parsing ] | ||
cargo install --git https://github.com/paritytech/cargo-contract.git --rev 5e6f941805e3d6032dbfa17771a887a362cb3460 --force | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_MAINNET_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_MAINNET_SECRET_ACCESS_KEY }} | ||
aws-region: eu-central-1 | ||
|
||
- name: Login to Public Amazon ECR | ||
id: login-public-ecr | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: public.ecr.aws | ||
username: ${{ secrets.AWS_MAINNET_ACCESS_KEY_ID }} | ||
password: ${{ secrets.AWS_MAINNET_SECRET_ACCESS_KEY }} | ||
env: | ||
AWS_REGION: us-east-1 | ||
|
||
- name: Run one-node smartnet | ||
shell: bash | ||
run: ./.github/scripts/run_smartnet.sh & | ||
|
||
# wait some while docker pulls the image and starts the node | ||
- name: Sleep for a while | ||
shell: bash | ||
run: sleep 2 | ||
|
||
- name: Run e2e tests | ||
shell: bash | ||
run: | | ||
source ./contracts/env/dev && ./contracts/scripts/deploy.sh && ./contracts/scripts/test.sh | ||
- name: Cleanup cache | ||
uses: ./.github/actions/post-cache | ||
|
||
slack: | ||
name: Slack notification | ||
runs-on: ubuntu-latest | ||
needs: [run-tests] | ||
if: always() | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Send Slack message | ||
uses: ./.github/actions/slack-notification | ||
with: | ||
notify-on: "failure" | ||
env: | ||
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,5 @@ exclude = [ | |
"fork-off", | ||
"benches/payout-stakers", | ||
"bin/cliain", | ||
"contracts", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# TheButton | ||
|
||
Series of smart contract based games, with varying tokenomics. | ||
TheButton is loosely based on the famous [game](https://en.wikipedia.org/wiki/The_Button_(Reddit)) on reddit. | ||
|
||
- Button lives for a set time. | ||
- Pressing the button extends its life. | ||
- Users are rewarded for playing the game. | ||
- Everybody can play only once. | ||
|
||
``` | ||
|______|_______| | ||
| | | | ||
start now deadline | ||
``` | ||
|
||
## EarlyBirdSpecial | ||
|
||
There is a pre-minted amount of tokens (a classic ERC20 standard). | ||
Users are rewarded for pressing as early on as possible: | ||
|
||
``` | ||
score = deadline - now | ||
``` | ||
|
||
There are two built-in incentives: | ||
* playing for the score: If you clicked in the 10th second of TheButton's life, which is set for example to 900 blocks, you get rewarded based on the score of 900-10=890 (and the button's life now will end at block 910). | ||
* playing to be ThePressiah: the last player to click gets 50% of the total reward pool. | ||
|
||
## BackToTheFuture | ||
|
||
In this scenario the rewards are reversed - players get rewarded for extending the button's life further into the future, i.e.: | ||
|
||
``` | ||
score = now - start | ||
``` | ||
|
||
The Pressiah gets 50% of the total reward pool. | ||
|
||
## ThePressiahCometh | ||
|
||
Game continues in perpetuity (but in practice as long as there are accounts that can still play it) | ||
|
||
- In each iteration of the game TheButton lives for a number of blocks | ||
- Clicking TheButton resets its countdown timer (extending the button's life further into the future) | ||
- Tokens are continuously minted at the end of each iteration | ||
- Players are rewarded for playing, with the ultimate goal of being the Pressiah (the last person to click the button) | ||
- Reward rules: | ||
- If you’re not ThePressiah, you get _k_ tokens if you pressed the button as the _k-th_ person in a row. | ||
- ThePressiah of the iteration with _k_ button presses gets [k*(k+1)]/2 tokens. | ||
|
||
# Development | ||
|
||
## Prerequisites | ||
|
||
- Rust nightly | ||
- cargo-contract with bug fixes around URL parsing: `cargo install --git https://github.com/paritytech/cargo-contract.git --rev 5e6f941805e3d6032dbfa17771a887a362cb3460 --force` | ||
|
||
## Instructions | ||
|
||
Firstly bootstrap a one-node `smartnet` chain: | ||
|
||
```bash | ||
./.github/scripts/run_smartnet.sh | ||
``` | ||
|
||
Secondly `deploy` script takes care of compiling and deploying the contracts. | ||
|
||
```bash | ||
source contracts/env/dev && ./contracts/scripts/deploy.sh | ||
``` | ||
|
||
Specifically it will: | ||
|
||
- Deploy the token contracts. | ||
- Deploy the game contracts. | ||
- Set access control. | ||
- Transfer token balances to the game contracts. | ||
- Whitelist accounts for playing the games. | ||
|
||
Third `test.sh` script plays the game from two well-known dev addresses. | ||
|
||
```bash | ||
./contracts/scripts/test.sh | ||
``` | ||
|
||
It will: | ||
|
||
- Interact with the games from the whitelisted accounts. | ||
- Wait past the game deadline, trigger the game end and reward distribution. |
Oops, something went wrong.