update tests; use web3-eth

This commit is contained in:
Iuri Matias 2019-08-21 14:51:13 -04:00
parent 0ae7023c6b
commit 7fe20a8e9f
8 changed files with 9557 additions and 3981 deletions

2609
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -32,6 +32,6 @@
"dependencies": { "dependencies": {
"lokijs": "^1.5.6", "lokijs": "^1.5.6",
"rxjs": "^6.5.2", "rxjs": "^6.5.2",
"web3": "^1.0.0-beta.37" "web3-eth": "^1.2.1"
} }
} }

View File

@ -4,13 +4,13 @@ const { randomString } = require('./utils.js');
const Database = require('./database.js'); const Database = require('./database.js');
const Events = require('events'); const Events = require('events');
const Web3 = require('web3'); const Web3Eth = require('web3-eth');
class EventSyncer { class EventSyncer {
constructor(provider, dbFilename) { constructor(provider, dbFilename) {
this.events = new Events(); this.events = new Events();
this.web3 = new Web3(provider); this.web3 = new Web3Eth(provider);
this.dbFilename = dbFilename || 'phoenix.db'; this.dbFilename = dbFilename || 'phoenix.db';
} }

View File

@ -10,8 +10,7 @@ import withObservables from '@nozbe/with-observables'
const { scan, map } = require('rxjs/operators'); const { scan, map } = require('rxjs/operators');
import { of } from 'rxjs'; import { of } from 'rxjs';
const phoenix = new Phoenix(web3.currentProvider);
const phoenix = new Phoenix(web3);
const RankItem = ({items, onUpvote, onDownvote}) => { const RankItem = ({items, onUpvote, onDownvote}) => {
return items.map((item, i) => <div key={i} className="item"> return items.map((item, i) => <div key={i} className="item">
@ -33,13 +32,15 @@ class App extends React.Component {
} }
componentDidMount(){ componentDidMount(){
EmbarkJS.onReady((err) => { //(async () => {
EmbarkJS.onReady(async (err) => {
if(err){ if(err){
console.error(err); console.error(err);
return; return;
} }
phoenix.init(() => { await phoenix.init()
observables.items = phoenix observables.items = phoenix
.trackEvent(Ranking, 'Rating', {filter: {}, fromBlock: 1}) .trackEvent(Ranking, 'Rating', {filter: {}, fromBlock: 1})
.pipe( .pipe(
@ -62,7 +63,7 @@ class App extends React.Component {
this.setState({ready: true}); this.setState({ready: true});
}); });
}); //})();
} }
upvote = address => () => { upvote = address => () => {
@ -80,11 +81,5 @@ class App extends React.Component {
} }
} }
ReactDOM.render(<App />, document.getElementById('content')); ReactDOM.render(<App />, document.getElementById('content'));

View File

@ -11,6 +11,7 @@
"devDependencies": {}, "devDependencies": {},
"dependencies": { "dependencies": {
"@nozbe/with-observables": "^1.0.5", "@nozbe/with-observables": "^1.0.5",
"embark": "^4.1.0",
"phoenix": "../../", "phoenix": "../../",
"react": "^16.9.0", "react": "^16.9.0",
"react-dom": "^16.9.0", "react-dom": "^16.9.0",

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,6 @@ import withObservables from '@nozbe/with-observables'
const web3 = new Web3("ws://localhost:8545"); const web3 = new Web3("ws://localhost:8545");
const Escrow = ({escrow}) => { const Escrow = ({escrow}) => {
console.log("Received new escrow property", escrow); console.log("Received new escrow property", escrow);
return <ul><li>{escrow.buyer} {escrow.seller} - <b>EscrowID:{escrow.escrowId}</b></li></ul>; return <ul><li>{escrow.buyer} {escrow.seller} - <b>EscrowID:{escrow.escrowId}</b></li></ul>;
@ -17,7 +16,6 @@ const enhance = withObservables(['escrow'], ({ escrow }) => ({ escrow }));
const EnhancedEscrow = enhance(Escrow) const EnhancedEscrow = enhance(Escrow)
class App extends React.Component { class App extends React.Component {
state = { state = {
@ -39,18 +37,14 @@ class App extends React.Component {
await this.EscrowContract.methods.createEscrow(1, accounts[1], accounts[0]).send({from: accounts[0]}) await this.EscrowContract.methods.createEscrow(1, accounts[1], accounts[0]).send({from: accounts[0]})
await this.EscrowContract.methods.createEscrow(1, accounts[0], accounts[2]).send({from: accounts[0]}) await this.EscrowContract.methods.createEscrow(1, accounts[0], accounts[2]).send({from: accounts[0]})
const eventSyncer = new Phoenix(web3); const eventSyncer = new Phoenix(web3.currentProvider);
eventSyncer.init(() => { await eventSyncer.init();
const replayObj = eventSyncer.trackEvent(this.EscrowContract, 'Created', {filter: {buyer: accounts[0]}, fromBlock: 1}); const replayObj = eventSyncer.trackEvent(this.EscrowContract, 'Created', {filter: {buyer: accounts[0]}, fromBlock: 1});
this.setState({ this.setState({
escrow: replayObj.asObservable() escrow: replayObj.asObservable()
}); });
});
})(); })();
} }
createTrx = async () => { createTrx = async () => {

1228
yarn.lock

File diff suppressed because it is too large Load Diff