Skip to content
This repository has been archived by the owner on Dec 13, 2019. It is now read-only.

[all] Introduction of AppRegistry and significant code improvements to facilitate it #163

Merged
merged 176 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from 168 commits
Commits
Show all changes
176 commits
Select commit Hold shift + click to select a range
eb57b4e
wip
snario Nov 29, 2018
f595e92
wip
snario Nov 29, 2018
ea3e638
Merge branch 'master' into liam/appInstanceAdjudicator
snario Nov 29, 2018
ee87e1d
passing tests2
snario Nov 30, 2018
57a22af
Merge branch 'master' into liam/appInstanceAdjudicator
snario Nov 30, 2018
d1ec21b
apps folder tests pass
snario Nov 30, 2018
50c3b58
lint
snario Dec 1, 2018
2c5f1c6
cleaner code
snario Dec 2, 2018
d476dda
cleaner code
snario Dec 3, 2018
e530a54
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 3, 2018
7204893
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 3, 2018
040c6cd
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 4, 2018
a4c8246
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 4, 2018
06eef49
install protocol tests
snario Dec 6, 2018
ab6a721
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 6, 2018
74b0131
set state tests
snario Dec 6, 2018
3c3efb9
test improvements
snario Dec 6, 2018
5209268
setup protocol tests
snario Dec 6, 2018
97db455
some fixes
snario Dec 6, 2018
a2b74fc
tests pass for all cf ops
snario Dec 6, 2018
f01f3e1
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 6, 2018
ea5b857
touch ups
snario Dec 7, 2018
ac98d9f
code cleanup
snario Dec 7, 2018
21cb39d
start of cleaning up proposer tests
snario Dec 8, 2018
c1e811e
Merge branch 'master' into liam/ar
snario Dec 8, 2018
3587ced
update waffle
snario Dec 8, 2018
4943c1c
clean up tests for install proposer
snario Dec 8, 2018
371a949
continue to ensure tests pass
snario Dec 10, 2018
ea1942c
remove useless file
snario Dec 10, 2018
2e9d1d0
remove bad test
snario Dec 10, 2018
d3df803
tests for all proposers
snario Dec 11, 2018
9c65232
parallelize tests
snario Dec 11, 2018
f4c90eb
rearrange deps
snario Dec 11, 2018
8a2ec40
still wip
snario Dec 12, 2018
199cda1
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 12, 2018
f477edb
remove warning on yarn
snario Dec 12, 2018
7742628
some cleanups to package
snario Dec 12, 2018
672c909
considerable improvements to code quality in machine
snario Dec 13, 2018
ee0f1ea
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 13, 2018
f6b964d
remove 4447 json network
snario Dec 13, 2018
be670e9
checkpointing stuff
snario Dec 14, 2018
e7e5b83
commitment tests passing
snario Dec 14, 2018
5bb84c2
mostly tested machine functionality
snario Dec 14, 2018
6cc7f5f
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 14, 2018
ef9599e
better testing
snario Dec 14, 2018
83ff327
make explicit unused files
snario Dec 14, 2018
9b5ba1d
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 14, 2018
386bc1f
nice script stuff
snario Dec 14, 2018
6ff7e9d
fix tests after ethers update
snario Dec 14, 2018
52a4e33
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 17, 2018
45abda0
updates
snario Dec 17, 2018
dacfb17
immutable channel class
snario Dec 17, 2018
e888d8f
clean up tests to handle immutable
snario Dec 17, 2018
e59b079
code cleanup
snario Dec 17, 2018
578a7e2
add comment
snario Dec 18, 2018
401bcfe
remove files that should not be here
snario Dec 18, 2018
66d6e05
remove files that should not be here
snario Dec 18, 2018
c15821e
remove yarn clean
snario Dec 18, 2018
6610a43
remove machine dependency on cf.js
snario Dec 18, 2018
64a649c
minor readme touch up
snario Dec 18, 2018
ba1f7b2
fix lint
snario Dec 18, 2018
db3e6cf
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 18, 2018
bc7a13c
remove bold and normal in build.sh
snario Dec 18, 2018
76cba94
Update packages/machine/src/models/state-channel.ts
joelalejandro Dec 18, 2018
68f9935
Update packages/machine/src/ethereum/install.ts
joelalejandro Dec 18, 2018
eb72fe0
Update packages/machine/src/models/app-instance.ts
joelalejandro Dec 18, 2018
85e7bf6
move utils to module import
snario Dec 19, 2018
934e785
typo
snario Dec 19, 2018
412e8e2
add doc
snario Dec 19, 2018
2efe499
typo
snario Dec 19, 2018
4f06b36
replace console.log with tests
snario Dec 19, 2018
bad5319
import from ethers/*
snario Dec 19, 2018
99a0c1f
change dependencies to devDepencies for apps package
snario Dec 19, 2018
a46535f
switch to resolver map
snario Dec 19, 2018
f4c1afb
type arbitrary state objects better
snario Dec 19, 2018
a846fea
use template literals for error messages
snario Dec 19, 2018
970cf7c
inline Map mutations for cleaner code
snario Dec 19, 2018
e80f659
abridge if statement
snario Dec 19, 2018
581fd42
Delegatecall -> DelegateCall
snario Dec 19, 2018
cdd8fd8
Update packages/machine/src/ethereum/utils/free-balance.ts
joelalejandro Dec 19, 2018
e8d0645
remove unused class
snario Dec 19, 2018
2ebe4f6
Update packages/machine/src/ethereum/uninstall.ts
joelalejandro Dec 19, 2018
a54a8dc
Update packages/machine/src/ethereum/uninstall.ts
joelalejandro Dec 19, 2018
e981fbd
Update packages/machine/src/ethereum/install.ts
joelalejandro Dec 19, 2018
f4f1f48
symlink .soliumrc.json
snario Dec 19, 2018
b846285
use ethers module imports some more
snario Dec 19, 2018
c2b6e30
shorten tsconfig in @apps
snario Dec 19, 2018
f0a10b3
add --detectOpenHandles back
snario Dec 19, 2018
76cc5df
shorten lines in .gitignore
snario Dec 19, 2018
b4bcde8
re-sort .soliumrc.json file
snario Dec 19, 2018
95e878d
uncomment critical line in StateChannelTransaction
snario Dec 19, 2018
9dad2a7
Update packages/contracts/contracts/libs/LibStaticCall.sol
cf19drofxots Dec 19, 2018
e7370f3
better documentation of appStates mapping
snario Dec 19, 2018
292aef8
better documentation of appResolutions mapping
snario Dec 19, 2018
e6f3f7a
rename _id to id in all .sol files
snario Dec 19, 2018
218f30e
better docs on setState method
snario Dec 19, 2018
3975b7c
remove test:windows because its the same
snario Dec 19, 2018
911f235
re-version @types to 0.0.1
snario Dec 19, 2018
4907627
rename TIMEOUT variable to ONCHAIN_CHALLENGE_TIMEOUT in a test
snario Dec 19, 2018
c153b3f
import Wallet in constants.ts
snario Dec 19, 2018
e800771
remove some commented out code
snario Dec 19, 2018
16bc59a
fresh conflict-free yarn.lock file
snario Dec 19, 2018
ecce80f
rename monotonicSeqNo according to Xuanjis's proposed scheme 'https:/…
snario Dec 19, 2018
093d578
use ReadonlyMap not Readonly<Map
snario Dec 19, 2018
ea105e7
Merge branch 'liam/appInstanceAdjudicator' of github.com:counterfactu…
snario Dec 19, 2018
491cea7
add ethereum-waffle typescript typings
snario Dec 19, 2018
98729cb
remove ts-ignore
snario Dec 19, 2018
52a6814
update ethers to 0.4.20
snario Dec 19, 2018
73b08c1
remove unnecessary build step for @types
snario Dec 19, 2018
de4a5df
remove some more tsignores
snario Dec 19, 2018
65022e7
remove unused imports
snario Dec 19, 2018
1223a0b
reintroduce script to build types
snario Dec 19, 2018
cadbbb1
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 19, 2018
c2f5abe
add apps to build string
snario Dec 19, 2018
2f11b37
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 20, 2018
7d73f57
better variable naming
snario Dec 20, 2018
4853e63
fix @types build process
snario Dec 20, 2018
730a2ac
add ganache-cli to test process of machine
snario Dec 20, 2018
efdf6d9
fix typo
snario Dec 20, 2018
fa4b7d8
undo export of cf
snario Dec 20, 2018
1f617ad
Add infrastructure to run ganache-cli tests in machine
snario Dec 21, 2018
7cbe3ab
Fix ordering of fields in tuple causing encoding to be incorrect
snario Dec 21, 2018
76fdc9a
Fix incorrect block.number / finalizesAt value comparison
snario Dec 21, 2018
c84d736
Add MinimumViableMultisig to the migrations (for use with proxyfactory)
snario Dec 21, 2018
7eb2c77
Remove --reset flag on truffle migrate for contracts
snario Dec 21, 2018
dc930e1
Rename appState to encodedAppState on SetStateCommitment for clarity
snario Dec 21, 2018
6ea67a4
Use encodePacked not encode for getTransactionHash on Multisig
snario Dec 21, 2018
cf34e0e
Add encodedTerms method on AppInstance
snario Dec 21, 2018
aab77d6
Change default timeouts to 10 not 100 (for tests)
snario Dec 21, 2018
e3560fa
Update the types folder to correctly export types and enums
snario Dec 21, 2018
a6f2885
Update yarn.lock
snario Dec 21, 2018
39c8717
Working blockchain test
snario Dec 21, 2018
e2a0518
rename file
snario Dec 21, 2018
89b838a
Fix timeout test after value change
snario Dec 21, 2018
487716e
Switch arrow notation to function for encodeTransactions
snario Dec 21, 2018
6828278
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 21, 2018
d90e743
Add missing variable usage in test.sh
snario Dec 21, 2018
999093b
more descriptive test description
snario Dec 21, 2018
ddd8513
Fix a linting error
snario Dec 21, 2018
8b1ccab
add types to front of build.sh string
snario Dec 21, 2018
150bee9
use relative importing in contracts as it turns out it is causing dou…
snario Dec 21, 2018
5e21aee
fix an incorrect merge from earlier of master
snario Dec 21, 2018
6266e1e
nearly finished working merge of virtualAppAgreement test
snario Dec 22, 2018
2c14b11
Remove multisig.ts util file
snario Dec 22, 2018
92bf855
testing rename of files to see how git treats the rename
snario Dec 22, 2018
d9147dc
Rename files to old names to fix git history
snario Dec 22, 2018
bea5f87
Add build symlink
snario Dec 22, 2018
8e97134
ensure tests pass
snario Dec 22, 2018
75e3b08
fix some linting issues
snario Dec 22, 2018
a5453a6
update circleci config
snario Dec 22, 2018
ce4a2db
dont delete .env when cleaning
snario Dec 22, 2018
cfd97e2
imrpoved usage of exit signals for bash trap
snario Dec 25, 2018
1e8075a
ensure circleci runs tests correctly
snario Dec 25, 2018
64b8185
update some README
snario Dec 25, 2018
fce9bc6
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 25, 2018
0426c95
Merge branch 'master' into liam/appInstanceAdjudicator
cf19drofxots Dec 26, 2018
7b82b34
Update README.md
snario Dec 26, 2018
8314c17
Rename truffle.js to truffle-config.js
snario Dec 26, 2018
99c3bc1
Replace ethers usage to always import from module (#364)
snario Dec 26, 2018
54793be
Rename appCfAddress to appInstanceId (#372)
snario Dec 26, 2018
689b703
Add @firebase/app-types to devDependencies on node
snario Dec 26, 2018
fba8b74
Merge branch 'master' of github.com:counterfactual/monorepo
snario Dec 26, 2018
6c2f324
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 26, 2018
e936b21
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 26, 2018
0b3b846
fix some linting issues
snario Dec 26, 2018
b47b480
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 26, 2018
22e7d4d
Add apps back to build file
snario Dec 26, 2018
a4d0d82
Update packages/machine/test/integration/setup-then-set-state.spec.ts
cf19drofxots Dec 26, 2018
89ba64b
Revert syntax error from github suggestion
snario Dec 26, 2018
559f86e
Remove duplicate code
snario Dec 27, 2018
907b397
yarn.lock
ldct Dec 27, 2018
0e6363c
Merge branch 'master' into liam/appInstanceAdjudicator
ldct Dec 27, 2018
a0f616d
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 27, 2018
6e861e4
fix solium to 1.1.8
snario Dec 27, 2018
93b78ea
update waffle
snario Dec 27, 2018
53f264d
Merge branch 'master' into liam/appInstanceAdjudicator
snario Dec 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
version: 2

jobs:
build:
docker:
Expand All @@ -9,26 +10,22 @@ jobs:
- restore_cache:
key: dependency-cache-{{ checksum ".dependencies_checksum" }}
- run: yarn
- run: yarn build
- save_cache:
key: dependency-cache-{{ checksum ".dependencies_checksum" }}
paths:
- node_modules

run-tests:
docker:
- image: circleci/node:10-browsers
- image: circleci/node:10
steps:
- checkout
- run: cat packages/*/package.json | shasum > .dependencies_checksum
- restore_cache:
key: dependency-cache-{{ checksum ".dependencies_checksum" }}
- run: yarn # symlink packages' node_modules
- run: yarn build
- run:
name: "Run ganache"
command: yarn ganache:ci
background: true
- run: cd packages/contracts/ && yarn migrate --network ganache
- run: yarn test:ci-non-playground

run-playground-tests:
Expand Down
28 changes: 28 additions & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"extends": "solium:all",
"plugins": ["security"],
"rules": {
"arg-overflow": ["error", 8],
"array-declarations": 1,
"camelcase": 1,
"deprecated-suicide": 1,
"imports-on-top": 1,
"indentation": ["error", 2],
"lbrace": 0,
"max-len": ["error", 80],
"mixedcase": 0,
"no-empty-blocks": 1,
"no-experimental": 0,
"no-unused-vars": 1,
"operator-whitespace": 1,
"pragma-on-top": 1,
"quotes": 1,
"security/enforce-explicit-visibility": ["error"],
"security/no-block-members": ["warning"],
"security/no-inline-assembly": 0,
"security/no-low-level-calls": 0,
"uppercase": 1,
"variable-declarations": 1,
"whitespace": 1
}
}
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,7 @@ yarn lint:fix

### Tests

Presently for some of the tests to work, you need to have a `ganache-cli` instance running in the background. To do this, run using:

```shell
yarn ganache
```

You also need to migrate the contracts in the contracts package to generate a `networks` file which the `machine` package directly consume (for now).

```shell
cd packages/contracts
yarn migrate --network ganache
```

Finally, to run all tests:
To run all tests:

```shell
yarn test
Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

set -e

packages="contracts common-types cf.js machine node node-provider playground-server playground dapp-high-roller"
packages="types apps contracts common-types cf.js machine node node-provider playground-server playground dapp-high-roller"

for package in $packages; do
echo ">>> Building package: $package"
cd packages/$package
echo "⚙️ Building package: ${package}"
cd packages/${package}
yarn build
cd -
done
24 changes: 4 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,19 @@
},
"scripts": {
"build": "sh build.sh",
"clean": "lerna run clean --parallel --no-bail",
"clean": "git clean -Xdf --exclude=\"!.env\"",
snario marked this conversation as resolved.
Show resolved Hide resolved
"clean:dry": "git clean -Xdn --exclude=\"!.env\"",
"test": "lerna run --stream --concurrency 1 test",
"test:ci-non-playground": "lerna run --ignore @counterfactual/playground --ignore @counterfactual/dapp-high-roller --stream test",
"ganache": "ganache-cli --networkId ${npm_package_config_ganacheNetworkID} --verbose --gasLimit ${npm_package_config_ganacheGasLimit} --gasPrice ${npm_package_config_ganacheGasPrice} --port ${npm_package_config_ganachePort} --deterministic --account=\"${npm_package_config_unlockedAccount0},${npm_package_config_etherBalance}\" --account=\"${npm_package_config_unlockedAccount1},${npm_package_config_etherBalance}\" --account=\"${npm_package_config_unlockedAccount2},${npm_package_config_etherBalance}\" --account=\"${npm_package_config_unlockedAccount3},${npm_package_config_etherBalance}\" &> /dev/null &",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we not get top-level ganache anymore? how do some of the machine tests which run against an EVM work? can you reflect these in the README and circleci?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the test that hit the blockchain. I'd like to re-write the test and just hit against a new ganache uniquely used for that test suite. I'll update the README.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the rewrite part of this PR? It was a pretty useful test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add one back in but I think it would be better to do it in a new PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snario has the README been updated to reflect this status?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't they just be added back?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snario that's a pretty useful test (as @IIIIllllIIIIllllIIIIllllIIIIllllIIIIll mentioned) - let's either not remove it or make a tangible PR to add it back that's referenced here, so as to not lose track of it.

"ganache:windows": "ganache-cli --networkId %npm_package_config_ganacheNetworkID% --verbose --gasLimit %npm_package_config_ganacheGasLimit% --gasPrice %npm_package_config_ganacheGasPrice% --port %npm_package_config_ganachePort% --deterministic --account=\"%npm_package_config_unlockedAccount0%,%npm_package_config_etherBalance%\" --account=\"%npm_package_config_unlockedAccount1%,%npm_package_config_etherBalance%\" --account=\"%npm_package_config_unlockedAccount2%,%npm_package_config_etherBalance%\" --account=\"%npm_package_config_unlockedAccount3%,%npm_package_config_etherBalance%\"",
"ganache:ci": "ganache-cli --networkId ${npm_package_config_ganacheNetworkID} --gasLimit ${npm_package_config_ganacheGasLimit} --gasPrice ${npm_package_config_ganacheGasPrice} --port ${npm_package_config_ganachePort} --deterministic --account=\"${npm_package_config_unlockedAccount0},${npm_package_config_etherBalance}\" --account=\"${npm_package_config_unlockedAccount1},${npm_package_config_etherBalance}\" --account=\"${npm_package_config_unlockedAccount2},${npm_package_config_etherBalance}\" --account=\"${npm_package_config_unlockedAccount3},${npm_package_config_etherBalance}\"",
"ganache:stop": "ps aux | grep ganache-cli | grep -v grep | awk '{print $2}' | xargs kill -9",
"test:ci-non-playground": "lerna run --ignore @counterfactual/playground --ignore @counterfactual/dapp-high-roller --stream --concurrency 1 test",
"lint": "lerna run lint --parallel --no-bail",
"lint:fix": "lerna run lint:fix --parallel --no-bail"
},
"config": {
"ganacheNetworkID": 7777777,
"ganachePort": 9545,
"ganacheGasLimit": "0xfffffffffff",
"ganacheGasPrice": "0x01",
"unlockedAccount0": "0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257a",
"unlockedAccount1": "0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257b",
"unlockedAccount2": "0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257c",
"unlockedAccount3": "0xf2f48ee19680706196e2e339e5da3491186e0c4c5030670656b0e0164837257d",
"etherBalance": "1000000000000000000000000"
},
"keywords": [
"ethereum",
"counterfactual",
"state channels",
"off chain"
"state channels"
],
"devDependencies": {
"ganache-cli": "6.2.5",
"lerna": "^3.4.3",
"prettier": "1.15.3",
"tslint": "^5.11.0",
Expand Down
1 change: 1 addition & 0 deletions packages/apps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
11 changes: 11 additions & 0 deletions packages/apps/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
testCommand: 'truffle test --network coverage lib/**/*.spec.js',
skipFiles: [
"external/Proxy.sol",
"external/ProxyFactory.sol",
"lib/StaticCall.sol",
"delegateTargets/MultiSend.sol",
"Registry.sol",
"test/loadContracts.sol"
]
};
2 changes: 2 additions & 0 deletions packages/apps/.soliumignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverageEnv
1 change: 1 addition & 0 deletions packages/apps/.soliumrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity 0.4.25;
pragma experimental "ABIEncoderV2";

import "../lib/Transfer.sol";
import "@counterfactual/contracts/contracts/libs/Transfer.sol";


contract CommitRevealApp {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity 0.4.25;
pragma experimental "ABIEncoderV2";

import "../lib/Transfer.sol";
import "@counterfactual/contracts/contracts/libs/Transfer.sol";


contract CountingApp {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
pragma solidity 0.4.25;
pragma experimental "ABIEncoderV2";

import "../lib/Transfer.sol";
import "@counterfactual/contracts/contracts/libs/Transfer.sol";


/*
Normal-form Nim
https://en.wikipedia.org/wiki/Nim
*/
contract Nim {
contract NimApp {

struct Action {
uint256 pileIdx;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pragma solidity 0.4.25;
pragma experimental "ABIEncoderV2";

import "../lib/Transfer.sol";
import "@counterfactual/contracts/contracts/libs/Transfer.sol";


contract PaymentApp {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pragma solidity 0.4.25;
pragma experimental "ABIEncoderV2";

import "../lib/Transfer.sol";
import "@counterfactual/contracts/contracts/libs/Transfer.sol";


contract TicTacToe {
contract TicTacToeApp {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we add a suffix, it should be AppDefinition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably nicer if we don't require prefixes. In Solidity 0.5 we'll be able to enforce that the programmer inherits from some interface which we can call interface AppDefinition { ... } so it looks like contract TicTacToe is AppDefinition { ... }


enum ActionType {
PLAY,
Expand Down
34 changes: 34 additions & 0 deletions packages/apps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@counterfactual/apps",
"version": "0.0.1",
"description": "Collection of various apps built on Counterfactual",
"repository": "github.com/counterfactual/monorepo",
"license": "MIT",
"private": true,
"files": [
snario marked this conversation as resolved.
Show resolved Hide resolved
"build"
],
"scripts": {
"build": "waffle waffle.json",
"test": "ts-mocha test/*",
"lint:fix": "yarn lint:ts:fix && yarn lint:sol:fix",
"lint": "yarn lint:ts && yarn lint:sol",
"lint:sol:fix": "solium -d contracts/ --fix",
"lint:sol": "solium -d .",
"lint:ts:fix": "tslint -c tslint.json -p . --fix",
"lint:ts": "tslint -c tslint.json -p ."
},
"devDependencies": {
"@counterfactual/contracts": "0.0.3",
"@counterfactual/typescript-typings": "0.0.1",
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.5",
"chai": "^4.2.0",
"ethereum-waffle": "^1.0.5",
"ethers": "4.0.20",
"mocha": "^4.1.0",
"solium": "^1.1.8",
"ts-mocha": "^2.0.0",
"tslint": "^5.11.0"
}
}
117 changes: 117 additions & 0 deletions packages/apps/test/nim.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import chai from "chai";
import * as waffle from "ethereum-waffle";
import { Contract } from "ethers";
import { AddressZero } from "ethers/constants";
import { BigNumber, defaultAbiCoder } from "ethers/utils";

import NimApp from "../build/NimApp.json";

chai.use(waffle.solidity);

const { expect } = chai;

type NimAppState = {
players: string[];
turnNum: BigNumber;
pileHeights: BigNumber[];
};

function decodeAppState(encodedAppState: string): NimAppState {
return defaultAbiCoder.decode(
["tuple(address[2] players, uint256 turnNum, uint256[3] pileHeights)"],
encodedAppState
)[0];
}

describe("Nim", () => {
let nim: Contract;

before(async () => {
const provider = waffle.createMockProvider();
const wallet = (await waffle.getWallets(provider))[0];
nim = await waffle.deployContract(wallet, NimApp);
});

describe("applyAction", () => {
it("can take from a pile", async () => {
const preState = {
players: [AddressZero, AddressZero],
turnNum: 0,
pileHeights: [6, 5, 12]
};

const action = {
pileIdx: 0,
takeAmnt: 5
};

const ret = await nim.functions.applyAction(preState, action);

const postState = decodeAppState(ret);

expect(postState.pileHeights[0]).to.eq(1);
expect(postState.pileHeights[1]).to.eq(5);
expect(postState.pileHeights[2]).to.eq(12);
expect(postState.turnNum).to.eq(1);
});

it("can take to produce an empty pile", async () => {
const preState = {
players: [AddressZero, AddressZero],
turnNum: 0,
pileHeights: [6, 5, 12]
};

const action = {
pileIdx: 0,
takeAmnt: 6
};

const ret = await nim.functions.applyAction(preState, action);

const postState = decodeAppState(ret);

expect(postState.pileHeights[0]).to.eq(0);
expect(postState.pileHeights[1]).to.eq(5);
expect(postState.pileHeights[2]).to.eq(12);
expect(postState.turnNum).to.eq(1);
});

it("should fail for taking too much", async () => {
const preState = {
players: [AddressZero, AddressZero],
turnNum: 0,
pileHeights: [6, 5, 12]
};

const action = {
pileIdx: 0,
takeAmnt: 7
};

await expect(
nim.functions.applyAction(preState, action)
).to.be.revertedWith("invalid pileIdx");
});
});

describe("isFinal", () => {
it("empty state is final", async () => {
const preState = {
players: [AddressZero, AddressZero],
turnNum: 49,
pileHeights: [0, 0, 0]
};
expect(await nim.functions.isStateTerminal(preState)).to.eq(true);
});

it("nonempty state is not final", async () => {
const preState = {
players: [AddressZero, AddressZero],
turnNum: 49,
pileHeights: [0, 1, 0]
};
expect(await nim.functions.isStateTerminal(preState)).to.eq(false);
});
});
});
Loading