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": {
"lokijs": "^1.5.6",
"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 Events = require('events');
const Web3 = require('web3');
const Web3Eth = require('web3-eth');
class EventSyncer {
constructor(provider, dbFilename) {
this.events = new Events();
this.web3 = new Web3(provider);
this.web3 = new Web3Eth(provider);
this.dbFilename = dbFilename || 'phoenix.db';
}

View File

@ -10,14 +10,13 @@ import withObservables from '@nozbe/with-observables'
const { scan, map } = require('rxjs/operators');
import { of } from 'rxjs';
const phoenix = new Phoenix(web3);
const phoenix = new Phoenix(web3.currentProvider);
const RankItem = ({items, onUpvote, onDownvote}) => {
return items.map((item, i) => <div key={i} className="item">
<b>{i+1}</b> - {item.addr}<br />
Upvotes: {item.upvotes} - Downvotes: {item.downvotes}<br />
<button onClick={onUpvote(item.addr)}>Upvote</button> | <button onClick={onDownvote(item.addr)}>Downvote</button>
return items.map((item, i) => <div key={i} className="item">
<b>{i+1}</b> - {item.addr}<br />
Upvotes: {item.upvotes} - Downvotes: {item.downvotes}<br />
<button onClick={onUpvote(item.addr)}>Upvote</button> | <button onClick={onDownvote(item.addr)}>Downvote</button>
</div>);
};
@ -33,58 +32,54 @@ class App extends React.Component {
}
componentDidMount(){
EmbarkJS.onReady((err) => {
if(err){
console.error(err);
return;
}
phoenix.init(() => {
observables.items = phoenix
.trackEvent(Ranking, 'Rating', {filter: {}, fromBlock: 1})
.pipe(
scan((acc, curr) => {
const votes = {...acc[curr.addr]} || {};
return {
...acc,
[curr.addr]: {
upvotes: (votes.upvotes || 0) + (curr.rating >= 3 ? 1 : 0),
downvotes: (votes.downvotes || 0) + (curr.rating < 3 ? 1 : 0)
}
}
}, {}),
map(summary => {
return Object.keys(summary).map(k => {
return {addr: k, ...summary[k]}
})
})
);
//(async () => {
EmbarkJS.onReady(async (err) => {
if(err){
console.error(err);
return;
}
await phoenix.init()
observables.items = phoenix
.trackEvent(Ranking, 'Rating', {filter: {}, fromBlock: 1})
.pipe(
scan((acc, curr) => {
const votes = {...acc[curr.addr]} || {};
return {
...acc,
[curr.addr]: {
upvotes: (votes.upvotes || 0) + (curr.rating >= 3 ? 1 : 0),
downvotes: (votes.downvotes || 0) + (curr.rating < 3 ? 1 : 0)
}
}
}, {}),
map(summary => {
return Object.keys(summary).map(k => {
return {addr: k, ...summary[k]}
})
})
);
this.setState({ready: true});
});
});
//})();
}
upvote = address => () => {
Ranking.methods.rate(address, 5).send();
}
upvote = address => () => {
Ranking.methods.rate(address, 5).send();
}
downvote = address => () => {
Ranking.methods.rate(address, 1).send();
}
downvote = address => () => {
Ranking.methods.rate(address, 1).send();
}
render() {
const {ready} = this.state;
if(!ready) return <span>Loading...</span>;
return <EnhancedRankItem items={observables.items} onUpvote={this.upvote} onDownvote={this.downvote} />;
}
render() {
const {ready} = this.state;
if(!ready) return <span>Loading...</span>;
return <EnhancedRankItem items={observables.items} onUpvote={this.upvote} onDownvote={this.downvote} />;
}
}
ReactDOM.render(<App />, document.getElementById('content'));

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,7 @@ import { map, scan} from 'rxjs/operators';
import Web3 from 'web3';
import withObservables from '@nozbe/with-observables'
const web3 = new Web3("ws://localhost:8545");
const web3 = new Web3("ws://localhost:8545");
const Escrow = ({escrow}) => {
console.log("Received new escrow property", escrow);
@ -17,7 +16,6 @@ const enhance = withObservables(['escrow'], ({ escrow }) => ({ escrow }));
const EnhancedEscrow = enhance(Escrow)
class App extends React.Component {
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[0], accounts[2]).send({from: accounts[0]})
const eventSyncer = new Phoenix(web3);
eventSyncer.init(() => {
const replayObj = eventSyncer.trackEvent(this.EscrowContract, 'Created', {filter: {buyer: accounts[0]}, fromBlock: 1});
this.setState({
escrow: replayObj.asObservable()
});
const eventSyncer = new Phoenix(web3.currentProvider);
await eventSyncer.init();
const replayObj = eventSyncer.trackEvent(this.EscrowContract, 'Created', {filter: {buyer: accounts[0]}, fromBlock: 1});
this.setState({
escrow: replayObj.asObservable()
});
})();
}
createTrx = async () => {

1228
yarn.lock

File diff suppressed because it is too large Load Diff