2019-09-09 01:35:05 +00:00
|
|
|
const Web3Eth = require('web3-eth');
|
|
|
|
const {deployRatingContract, mine} = require('./utils-web3');
|
2020-02-03 23:51:19 +00:00
|
|
|
const Subspace = require('../dist/index.js').default;
|
2019-09-09 01:35:05 +00:00
|
|
|
const ganache = require("ganache-core");
|
|
|
|
|
|
|
|
console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")
|
2020-03-04 18:24:51 +00:00
|
|
|
let eth = new Web3Eth("http://localhost:8545");
|
2019-09-09 01:35:05 +00:00
|
|
|
|
|
|
|
async function run() {
|
|
|
|
let accounts = await eth.getAccounts();
|
|
|
|
var RatingContract = await deployRatingContract(eth)
|
|
|
|
|
|
|
|
// Events are generated in these blocks:
|
|
|
|
// x x x x x x x x x
|
|
|
|
// 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
|
|
|
|
await mine(eth);
|
|
|
|
await RatingContract.methods.doRating(1, 5).send({from: accounts[0]})
|
|
|
|
await mine(eth);
|
|
|
|
await mine(eth);
|
|
|
|
await RatingContract.methods.doRating(2, 3).send({from: accounts[0]})
|
|
|
|
await RatingContract.methods.doRating(3, 1).send({from: accounts[0]})
|
|
|
|
await RatingContract.methods.doRating(4, 5).send({from: accounts[0]})
|
|
|
|
await RatingContract.methods.doRating(5, 5).send({from: accounts[0]})
|
|
|
|
await mine(eth);
|
|
|
|
await RatingContract.methods.doRating(6, 5).send({from: accounts[0]})
|
|
|
|
await mine(eth);
|
|
|
|
await mine(eth);
|
|
|
|
await RatingContract.methods.doRating(7, 5).send({from: accounts[0]})
|
|
|
|
await RatingContract.methods.doRating(8, 5).send({from: accounts[0]})
|
|
|
|
await mine(eth);
|
|
|
|
await mine(eth);
|
|
|
|
await mine(eth);
|
2020-03-04 18:24:51 +00:00
|
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
setInterval(async () => {
|
|
|
|
await RatingContract.methods.doRating(1, 1).send({from: accounts[0]})
|
|
|
|
}, 2000);
|
|
|
|
}, 3000)
|
2019-09-09 01:35:05 +00:00
|
|
|
await mine(eth);
|
|
|
|
|
2019-09-27 20:04:01 +00:00
|
|
|
const subspace = new Subspace(eth.currentProvider);
|
|
|
|
await subspace.init()
|
2019-09-09 01:35:05 +00:00
|
|
|
|
2020-03-04 18:24:51 +00:00
|
|
|
|
2019-09-09 01:35:05 +00:00
|
|
|
// Testing single block with a event
|
2020-03-04 18:24:51 +00:00
|
|
|
subspace.trackEvent(RatingContract, 'Rating', {fromBlock: 3}).subscribe({
|
|
|
|
next(x) { console.log('got value ', x)},
|
|
|
|
error(err) { console.log("ERROR")},
|
|
|
|
complete() { console.log('done')}
|
2019-09-09 01:35:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2020-03-04 18:24:51 +00:00
|
|
|
console.log(".....")
|
2019-09-09 01:35:05 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-04 18:24:51 +00:00
|
|
|
run();
|