fix: tests

This commit is contained in:
Richard Ramos 2020-03-04 14:48:08 -04:00
parent a2a133f2cf
commit 85c4d9300a
8 changed files with 76 additions and 59 deletions

View File

@ -1,9 +1,9 @@
const { map, scan, last, distinctUntilChanged } = require('rxjs/operators');
const Web3Eth = require('web3-eth');
const Web3 = require('web3');
const {deployEscrowContract} = require('./utils-web3');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("ws://localhost:8545");
let web3 = new Web3("ws://localhost:8545");
let myscan = scan((acc, curr) => {
acc.push(curr);
@ -13,8 +13,8 @@ let myscan = scan((acc, curr) => {
let mymap = map(arr => arr.reduce((acc, current) => acc + current, 0) / arr.length)
async function run() {
let accounts = await eth.getAccounts();
var EscrowContract = await deployEscrowContract(eth)
let accounts = await web3.eth.getAccounts();
var EscrowContract = await deployEscrowContract(web3.eth)
await EscrowContract.methods.createEscrow(1, accounts[0], accounts[1]).send({from: accounts[0]})
await EscrowContract.methods.createEscrow(1, accounts[1], accounts[2]).send({from: accounts[0]})
@ -27,7 +27,7 @@ async function run() {
// console.dir(event)
})
const subspace = new Subspace(eth.currentProvider);
const subspace = new Subspace(web3);
await subspace.init()
console.dir("getting escrows created by " + accounts[0])

View File

@ -1,8 +1,8 @@
const { map, scan, last, distinctUntilChanged } = require('rxjs/operators');
const Web3Eth = require('web3-eth');
const Web3 = require('web3');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("ws://localhost:8545");
let web3 = new Web3("ws://localhost:8545");
let myscan = scan((acc, curr) => {
acc.push(curr);
@ -12,7 +12,7 @@ let myscan = scan((acc, curr) => {
let mymap = map(arr => arr.reduce((acc, current) => acc + current, 0) / arr.length)
async function deployContract() {
let accounts = await eth.getAccounts();
let accounts = await web3.eth.getAccounts();
// pragma solidity ^0.5.0;
// contract SimpleStorage {
@ -92,7 +92,7 @@ async function deployContract() {
}
]
var contract = new eth.Contract(abi)
var contract = new web3.eth.Contract(abi)
let instance = await contract.deploy({
data: '0x608060405234801561001057600080fd5b5061017c806100206000396000f3fe608060405260043610610046576000357c0100000000000000000000000000000000000000000000000000000000900480631ab06ee51461004b5780639507d39a14610090575b600080fd5b34801561005757600080fd5b5061008e6004803603604081101561006e57600080fd5b810190808035906020019092919080359060200190929190505050610112565b005b34801561009c57600080fd5b506100c9600480360360208110156100b357600080fd5b810190808035906020019092919050505061012d565b604051808381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019250505060405180910390f35b80600080848152602001908152602001600020819055505050565b60008060008084815260200190815260200160002054338090509150915091509156fea165627a7a7230582054f962728d2f5acbfde67516616e1b90e3aca5df27a213cbbabc16387d9af7d90029',
arguments: []
@ -104,18 +104,13 @@ async function deployContract() {
}
async function run() {
let accounts = await eth.getAccounts();
let accounts = await web3.eth.getAccounts();
var SimpleStorageContract = await deployContract()
console.dir(SimpleStorageContract.options.address)
console.log("F")
const subspace = new Subspace(eth.currentProvider);
console.log("B")
const subspace = new Subspace(web3);
await subspace.init();
console.log("C")
await SimpleStorageContract.methods.set(2, 500).send({ from: accounts[0], gas: 4700000 })
console.log("A")
subspace.trackProperty(SimpleStorageContract, 'get', [2], {from: "0x0000000000000000000000000000000000000012"} ).map("1").subscribe((v) => {
subspace.trackProperty(SimpleStorageContract, 'get', [2], {from: "0x0000000000000000000000000000000000000012"} ).subscribe((v) => {
console.dir("value is ")
console.dir(v)
})

View File

@ -1,28 +1,28 @@
const ganache = require("ganache-core");
const Web3Eth = require('web3-eth');
const Web3 = require('web3');
const Subspace = require('../dist/index.js').default;
console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")
let eth = new Web3Eth(ganache.provider());
let web3 = new Web3(ganache.provider());
async function run() {
let accounts = await eth.getAccounts();
let accounts = await web3.eth.getAccounts();
console.log(accounts);
setTimeout(() => {
console.log("ABC")
eth.getBalance(accounts[0]).then(console.log);
web3.eth.getBalance(accounts[0]).then(console.log);
}, 3000)
setTimeout(async () => {
await eth.sendTransaction({from: accounts[0], to: accounts[1], value: "100000000"});
await eth.sendTransaction({from: accounts[1], to: accounts[0], value: "999999999"});
await eth.sendTransaction({from: accounts[0], to: accounts[1], value: "232433434"});
await web3.eth.sendTransaction({from: accounts[0], to: accounts[1], value: "100000000"});
await web3.eth.sendTransaction({from: accounts[1], to: accounts[0], value: "999999999"});
await web3.eth.sendTransaction({from: accounts[0], to: accounts[1], value: "232433434"});
}, 2000);
const subspace = new Subspace(eth.currentProvider);
const subspace = new Subspace(web3);
await subspace.init();

View File

@ -1,10 +1,10 @@
const Web3Eth = require('web3-eth');
const Web3 = require('web3');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("ws://localhost:8545");
let web3 = new Web3("ws://localhost:8545");
async function deployContract() {
let accounts = await eth.getAccounts();
let accounts = await web3.eth.getAccounts();
// pragma solidity ^0.5.0;
// contract ERC20Token {
@ -39,7 +39,7 @@ async function deployContract() {
}
];
var contract = new eth.Contract(abi)
var contract = new web3.eth.Contract(abi)
let instance = await contract.deploy({
data: '0x608060405234801561001057600080fd5b5060d58061001f6000396000f3fe6080604052600436106039576000357c01000000000000000000000000000000000000000000000000000000009004806370a0823114603e575b600080fd5b348015604957600080fd5b50608960048036036020811015605e57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050609f565b6040518082815260200191505060405180910390f35b600043905091905056fea165627a7a72305820267fb09927dce2942fe73ac7487c4f1565dae60b08aa5434a22cb1f71366bd090029',
arguments: []
@ -51,12 +51,12 @@ async function deployContract() {
}
async function run() {
let accounts = await eth.getAccounts();
let accounts = await web3.eth.getAccounts();
var DummyERC20Token = await deployContract()
console.dir(DummyERC20Token.options.address)
const subspace = new Subspace(eth.currentProvider);
const subspace = new Subspace(web3);
await subspace.init();
subspace.trackBalance(accounts[0], DummyERC20Token.options.address).pipe().subscribe((balance) => {

View File

@ -1,54 +1,79 @@
const Web3Eth = require('web3-eth');
const Web3 = require('web3');
const {deployRatingContract, mine} = require('./utils-web3');
const Subspace = require('../dist/index.js').default;
const ganache = require("ganache-core");
console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")
let eth = new Web3Eth("http://localhost:8545");
let web3 = new Web3("http://localhost:8545");
async function run() {
let accounts = await eth.getAccounts();
var RatingContract = await deployRatingContract(eth)
let accounts = await web3.eth.getAccounts();
var RatingContract = await deployRatingContract(web3.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 mine(web3.eth);
await RatingContract.methods.doRating(1, 5).send({from: accounts[0]})
await mine(eth);
await mine(eth);
await mine(web3.eth);
await mine(web3.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 mine(web3.eth);
await RatingContract.methods.doRating(6, 5).send({from: accounts[0]})
await mine(eth);
await mine(eth);
await mine(web3.eth);
await mine(web3.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);
await mine(web3.eth);
await mine(web3.eth);
await mine(web3.eth);
setTimeout(async () => {
setInterval(async () => {
await RatingContract.methods.doRating(1, 1).send({from: accounts[0]})
}, 2000);
}, 3000)
await mine(eth);
await mine(web3.eth);
const subspace = new Subspace(eth.currentProvider);
const subspace = new Subspace(web3);
await subspace.init()
// Testing single block with a event
subspace.trackEvent(RatingContract, 'Rating', {fromBlock: 3}).subscribe({
next(x) { console.log('got value ', x)},
error(err) { console.log("ERROR")},
complete() { console.log('done')}
subspace.trackEvent(RatingContract, 'Rating', {fromBlock: 3, toBlock: 3}).subscribe((v) => {
console.log("A", v)
});
// Testing blocks that have no events in between
subspace.trackEvent(RatingContract, 'Rating', {fromBlock: 8, toBlock: 11}).subscribe((v) => {
console.log("B", v)
});
// Testing blocks that begin with no events
subspace.trackEvent(RatingContract, 'Rating', {fromBlock: 12, toBlock: 15}).subscribe((v) => {
console.log("C", v)
});
// Testing all blocks
subspace.trackEvent(RatingContract, 'Rating', {}).subscribe((v) => {
console.log("D", v)
});
// Testing blocks that end in no events
subspace.trackEvent(RatingContract, 'Rating', {fromBlock: 14, toBlock: 18}).subscribe((v) => {
console.log("E", v)
});
setTimeout(() => {
// Testing if events come from the DB instead of a subscription
subspace.trackEvent(RatingContract, 'Rating', {fromBlock: 7, toBlock: 11}).subscribe((v) => {
console.log("E", v)
});
}, 5000);
console.log(".....")

View File

@ -1,10 +1,10 @@
const Web3Eth = require('web3-eth');
const Web3 = require('web3-eth');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("wss://mainnet.infura.io/ws/v3/_____________");
let ethweb3 = new Web3("wss://mainnet.infura.io/ws/v3/_____________");
async function run() {
const subspace = new Subspace(eth.currentProvider);
const subspace = new Subspace(web3);
await subspace.init()
// Testing single block with a event

View File

@ -1,10 +1,10 @@
const Web3Eth = require('web3-eth');
const Web3 = require('web3');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("https://mainnet.infura.io/v3/562ba55287324547adbdd59b1dabc869");
let web3 = new Web3("https://mainnet.infura.io/v3/562ba55287324547adbdd59b1dabc869");
async function run() {
const subspace = new Subspace(eth.currentProvider);
const subspace = new Subspace(web3);
await subspace.init()
subspace.trackBlockNumber().subscribe((v) => console.log("Blocknumber", v));

View File

@ -120,9 +120,6 @@ async function deployRatingContract(eth) {
var contract = new eth.Contract(abi);
contract.options.address = "0x80bc8c15741b89df78a3553a02412c26cf601d23";
return contract;
let instance = await contract.deploy({
data: '0x608060405234801561001057600080fd5b5060e78061001f6000396000f3fe6080604052600436106039576000357c010000000000000000000000000000000000000000000000000000000090048063f60781a914603e575b600080fd5b348015604957600080fd5b50607d60048036036040811015605e57600080fd5b810190808035906020019092919080359060200190929190505050607f565b005b817ffdefdf8d82459f7b1eb157e5c44cbe6ee73d8ddd387511fe3622a3ee663b4697826040518082815260200191505060405180910390a2505056fea165627a7a7230582067833697a0e2bccb8bd624c0b06b2183641addb24f7931d8ec3979982bb663790029',
arguments: []