This repository has been archived by the owner on Sep 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #466 from magmo/adjudicator-watcher-common-data
Server adjudicator watcher
- Loading branch information
Showing
33 changed files
with
388 additions
and
88 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,24 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Jest Chain Current", | ||
"type": "node", | ||
"request": "launch", | ||
"args": [ | ||
"node_modules/.bin/jest", | ||
"--runInBand", | ||
"--env=jsdom", | ||
"--config=${workspaceRoot}/config/jest/jest.chain.config.js", | ||
"${relativeFile}" | ||
], | ||
"cwd": "${workspaceRoot}", | ||
"protocol": "inspector", | ||
"console": "integratedTerminal", | ||
"internalConsoleOptions": "neverOpen" | ||
} | ||
] | ||
} |
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 @@ | ||
web: cd packages/server && yarn start | ||
adjudicator-watcher: cd packages/server && yarn start:adjudicator-watcher |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,5 @@ | ||
#!/bin/bash | ||
parentPath=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) | ||
|
||
cd "${parentPath}/.." | ||
cp ../wallet/build/contracts/* build/contracts/ |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
var config = require('./jest.config'); | ||
config.testMatch = ['<rootDir>/src/**/__chain-test__/?(*.)test.ts?(x)']; | ||
module.exports = config; |
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 @@ | ||
const { resolve } = require('path'); | ||
const root = resolve(__dirname, '../../'); | ||
|
||
module.exports = { | ||
rootDir: root, | ||
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}'], | ||
setupFiles: [], | ||
setupFilesAfterEnv: ['./src/config/knexSetupTeardown.ts'], | ||
testMatch: ['<rootDir>/**/__test__/**/?(*.)(spec|test).ts'], | ||
testEnvironment: 'node', | ||
testURL: 'http://localhost', | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$'], | ||
moduleFileExtensions: [ | ||
'web.ts', | ||
'ts', | ||
'web.tsx', | ||
'tsx', | ||
'web.js', | ||
'js', | ||
'web.jsx', | ||
'jsx', | ||
'json', | ||
'node', | ||
'mjs', | ||
], | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: './tsconfig.json', | ||
}, | ||
}, | ||
}; |
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,23 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
contract Migrations { | ||
address public owner; | ||
uint public last_completed_migration; | ||
|
||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
modifier restricted() { | ||
if (msg.sender == owner) _; | ||
} | ||
|
||
function setCompleted(uint completed) public restricted { | ||
last_completed_migration = completed; | ||
} | ||
|
||
function upgrade(address new_address) public restricted { | ||
Migrations upgraded = Migrations(new_address); | ||
upgraded.setCompleted(last_completed_migration); | ||
} | ||
} |
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,7 @@ | ||
pragma solidity ^0.5.0; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import "fmg-core/contracts/Commitment.sol"; | ||
import "fmg-nitro-adjudicator/contracts/ConsensusCommitment.sol"; | ||
import "fmg-nitro-adjudicator/contracts/NitroAdjudicator.sol"; | ||
import "fmg-nitro-adjudicator/contracts/ConsensusApp.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
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,28 @@ | ||
import * as path from 'path'; | ||
|
||
const commonDataPrefix = 'magmo-wallet-common/prebuilt-contracts'; | ||
const devPathPrefix = '../../build/contracts'; | ||
|
||
const commitmentJson = 'Commitment.json'; | ||
const rulesJson = 'Rules.json'; | ||
const nitroAdjudicatorJson = 'NitroAdjudicator.json'; | ||
const rpsGameJson = 'RockPaperScissorsGame.json'; | ||
|
||
interface Artifact { | ||
abi: any; | ||
contractName: string; | ||
networks: { [key: string]: { address: string } }; | ||
} | ||
|
||
let commitmentArtifact: Artifact = require(path.join(commonDataPrefix, commitmentJson)); | ||
let rulesArtifact: Artifact = require(path.join(commonDataPrefix, rulesJson)); | ||
let nitroAdjudicatorArtifact: Artifact = require(path.join(commonDataPrefix, nitroAdjudicatorJson)); | ||
let rpsGameArtifact: Artifact = require(path.join(commonDataPrefix, rpsGameJson)); | ||
|
||
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development') { | ||
commitmentArtifact = require(path.join(devPathPrefix, commitmentJson)); | ||
rulesArtifact = require(path.join(devPathPrefix, rulesJson)); | ||
nitroAdjudicatorArtifact = require(path.join(devPathPrefix, nitroAdjudicatorJson)); | ||
} | ||
|
||
export { commitmentArtifact, rulesArtifact, nitroAdjudicatorArtifact, rpsGameArtifact }; |
42 changes: 42 additions & 0 deletions
42
packages/server/src/wallet/adjudicator-watcher/__chain-test__/adjudicator-watcher.test.ts
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,42 @@ | ||
import { ethers } from 'ethers'; | ||
import { bigNumberify } from 'ethers/utils'; | ||
import { channelID } from 'fmg-core/lib/channel'; | ||
import { listen } from '..'; | ||
import AllocatorChannel from '../../models/allocatorChannel'; | ||
import { channel, depositContract } from './utils'; | ||
|
||
jest.setTimeout(60000); | ||
const channelId = channelID(channel); | ||
let removeListeners = null; | ||
|
||
async function getHoldings() { | ||
return (await AllocatorChannel.query() | ||
.where('channel_id', channelId) | ||
.first() | ||
.select('holdings')).holdings; | ||
} | ||
|
||
describe('adjudicator listener', () => { | ||
const provider: ethers.providers.JsonRpcProvider = new ethers.providers.JsonRpcProvider( | ||
`http://localhost:${process.env.DEV_GANACHE_PORT}`, | ||
); | ||
|
||
it('should handle a funds received event when channel is in the database', async done => { | ||
const preEventHoldings = await getHoldings(); | ||
|
||
const eventCallback = async eventType => { | ||
const postEventHoldings = await getHoldings(); | ||
|
||
const eventDeposit = bigNumberify(postEventHoldings).sub(bigNumberify(preEventHoldings)); | ||
expect(eventDeposit.toNumber()).toBeGreaterThanOrEqual(5); | ||
done(); | ||
}; | ||
|
||
removeListeners = await listen(eventCallback); | ||
await depositContract(provider, channelId); | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
removeListeners(); | ||
}); |
Oops, something went wrong.