This repository has been archived by the owner on Dec 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[all] Introduction of AppRegistry and significant code improvements t…
…o facilitate it (#163) * wip * wip * passing tests2 * apps folder tests pass * lint * cleaner code * cleaner code * install protocol tests * set state tests * test improvements * setup protocol tests * some fixes * tests pass for all cf ops * touch ups * code cleanup * start of cleaning up proposer tests * update waffle * clean up tests for install proposer * continue to ensure tests pass * remove useless file * remove bad test * tests for all proposers * parallelize tests * rearrange deps * still wip * remove warning on yarn * some cleanups to package * considerable improvements to code quality in machine * remove 4447 json network * checkpointing stuff * commitment tests passing * mostly tested machine functionality * better testing * make explicit unused files * nice script stuff * fix tests after ethers update * updates * clean up tests to handle immutable * code cleanup * add comment * remove files that should not be here * remove files that should not be here * remove yarn clean * remove machine dependency on cf.js * minor readme touch up * fix lint * remove bold and normal in build.sh * Update packages/machine/src/models/state-channel.ts Co-Authored-By: snario <[email protected]> * Update packages/machine/src/ethereum/install.ts Co-Authored-By: snario <[email protected]> * Update packages/machine/src/models/app-instance.ts Co-Authored-By: snario <[email protected]> * move utils to module import * typo * add doc * typo * replace console.log with tests * import from ethers/* * change dependencies to devDepencies for apps package * switch to resolver map * type arbitrary state objects better * use template literals for error messages * inline Map mutations for cleaner code * abridge if statement * Delegatecall -> DelegateCall * Update packages/machine/src/ethereum/utils/free-balance.ts Co-Authored-By: snario <[email protected]> * remove unused class * Update packages/machine/src/ethereum/uninstall.ts Co-Authored-By: snario <[email protected]> * Update packages/machine/src/ethereum/uninstall.ts Co-Authored-By: snario <[email protected]> * Update packages/machine/src/ethereum/install.ts Co-Authored-By: snario <[email protected]> * symlink .soliumrc.json * use ethers module imports some more * shorten tsconfig in @apps * add --detectOpenHandles back * shorten lines in .gitignore * re-sort .soliumrc.json file * uncomment critical line in StateChannelTransaction * Update packages/contracts/contracts/libs/LibStaticCall.sol Co-Authored-By: snario <[email protected]> * better documentation of appStates mapping * better documentation of appResolutions mapping * rename _id to id in all .sol files * better docs on setState method * remove test:windows because its the same * re-version @types to 0.0.1 * rename TIMEOUT variable to ONCHAIN_CHALLENGE_TIMEOUT in a test * import Wallet in constants.ts * remove some commented out code * fresh conflict-free yarn.lock file * rename monotonicSeqNo according to Xuanjis's proposed scheme '#163 (comment)' * use ReadonlyMap not Readonly<Map * add ethereum-waffle typescript typings * remove ts-ignore * update ethers to 0.4.20 * remove unnecessary build step for @types * remove some more tsignores * remove unused imports * reintroduce script to build types * add apps to build string * better variable naming * fix @types build process * add ganache-cli to test process of machine * fix typo * undo export of cf * Add infrastructure to run ganache-cli tests in machine * Fix ordering of fields in tuple causing encoding to be incorrect * Fix incorrect block.number / finalizesAt value comparison * Add MinimumViableMultisig to the migrations (for use with proxyfactory) * Remove --reset flag on truffle migrate for contracts * Rename appState to encodedAppState on SetStateCommitment for clarity * Use encodePacked not encode for getTransactionHash on Multisig * Add encodedTerms method on AppInstance * Change default timeouts to 10 not 100 (for tests) * Update the types folder to correctly export types and enums * Update yarn.lock * Working blockchain test * rename file * Fix timeout test after value change * Switch arrow notation to function for encodeTransactions * Add missing variable usage in test.sh * more descriptive test description * Fix a linting error * add types to front of build.sh string * use relative importing in contracts as it turns out it is causing double compilation * fix an incorrect merge from earlier of master * nearly finished working merge of virtualAppAgreement test * Remove multisig.ts util file * testing rename of files to see how git treats the rename * Rename files to old names to fix git history * Add build symlink * ensure tests pass * fix some linting issues * update circleci config * dont delete .env when cleaning * imrpoved usage of exit signals for bash trap * ensure circleci runs tests correctly * update some README * Update README.md * Rename truffle.js to truffle-config.js * Replace ethers usage to always import from module (#364) * Replace all ethers utils with module imports * Fixed a few places I missed the first time * Update rollup for cf.js to include ethers.constants * Rename appCfAddress to appInstanceId (#372) * Add @firebase/app-types to devDependencies on node * fix some linting issues * Add apps back to build file * Update packages/machine/test/integration/setup-then-set-state.spec.ts Co-Authored-By: snario <[email protected]> * Revert syntax error from github suggestion * Remove duplicate code * yarn.lock * fix solium to 1.1.8 * update waffle
- Loading branch information
Showing
232 changed files
with
8,159 additions
and
8,323 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
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,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 | ||
} | ||
} |
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
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
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
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 @@ | ||
build |
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,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" | ||
] | ||
}; |
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,2 @@ | ||
node_modules | ||
coverageEnv |
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 @@ | ||
../../.soliumrc.json |
2 changes: 1 addition & 1 deletion
2
...tracts/appDefinitions/CommitRevealApp.sol → packages/apps/contracts/CommitRevealApp.sol
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
2 changes: 1 addition & 1 deletion
2
.../contracts/appDefinitions/CountingApp.sol → packages/apps/contracts/CountingApp.sol
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
4 changes: 2 additions & 2 deletions
4
...ontracts/contracts/appDefinitions/Nim.sol → packages/apps/contracts/NimApp.sol
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
2 changes: 1 addition & 1 deletion
2
...s/contracts/appDefinitions/PaymentApp.sol → packages/apps/contracts/PaymentApp.sol
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
4 changes: 2 additions & 2 deletions
4
...ts/contracts/appDefinitions/TicTacToe.sol → packages/apps/contracts/TicTacToeApp.sol
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
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,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": [ | ||
"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.2.0", | ||
"ethers": "4.0.20", | ||
"mocha": "^4.1.0", | ||
"solium": "1.1.8", | ||
"ts-mocha": "^2.0.0", | ||
"tslint": "^5.11.0" | ||
} | ||
} |
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,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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.