Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const Web3Eth = require('web3-eth');
const {deployRatingContract, mine} = require('./utils-web3');
const Subspace = require('../dist/node.js');
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(ganache.provider());
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]})
function createTestSetup () {
// raw data source
const dataProvider = GanacheCore.provider()
// create block tracker
const blockTracker = new BlockTracker({
provider: dataProvider,
pollingInterval: 100,
})
// create higher level
const engine = new JsonRpcEngine()
const provider = providerFromEngine(engine)
// add block ref middleware
engine.push(createBlockRefMiddleware({ provider, blockTracker }))
// hit tracker
const hitTracker = createHitTrackerMiddleware()
engine.push(hitTracker)
// add data source
engine.push(providerAsMiddleware(dataProvider))
const query = new EthQuery(provider)
const initProviderWeb3 = async ganacheOptions => {
// Spawn Ganache test blockchain
const provider = Ganache.provider(ganacheOptions || defaultGanacheOptions);
const web3 = new Web3(provider);
const accounts = await web3.eth.getAccounts();
return { provider, web3, accounts };
};
function createTestSetup () {
// raw data source
const ganacheProvider = GanacheCore.provider()
// create higher level
const engine = new JsonRpcEngine()
const provider = providerFromEngine(engine)
const query = new EthQuery(provider)
const ganacheQuery = new EthQuery(ganacheProvider)
return { engine, provider, ganacheProvider, query, ganacheQuery }
}
constructor({ loader, minerAddress, privateKey, provider, realProviderPort = 8545, useJsTree = false, dbPath = "./reputationStates.sqlite" }) {
this.loader = loader;
this.minerAddress = minerAddress;
this.dbPath = dbPath;
this.useJsTree = useJsTree;
if (!this.useJsTree) {
const ganacheProvider = ganache.provider({
network_id: 515,
vmErrorsOnRPCResponse: false,
locked: false,
verbose: true,
accounts: [
{
balance: "0x10000000000000000000000000",
secretKey
}
]
});
this.ganacheProvider = new ethers.providers.Web3Provider(ganacheProvider);
this.ganacheWallet = new ethers.Wallet(secretKey, this.ganacheProvider);
}
// This will have to support provider.getSigner https://docs.ethers.io/ethers.js/html/api-providers.html#jsonrpcprovider
const ganache = require("ganache-core");
const Web3Eth = require('web3-eth');
const Subspace = require('../dist/node.js');
console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")
let eth = new Web3Eth(ganache.provider());
async function run() {
let accounts = await eth.getAccounts();
setTimeout(async () => {
await eth.sendTransaction({from: accounts[0], to: accounts[1], value: "100000000"});
await eth.sendTransaction({from: accounts[2], to: accounts[0], value: "999999999"});
await eth.sendTransaction({from: accounts[2], to: accounts[0], value: "232433434"});
}, 2000);
const subspace = new Subspace(eth.currentProvider);
await subspace.init();
subspace.trackBalance(accounts[0]).subscribe((balance) => {
console.log("accounts[0] balance is ", balance);
constructor(opts: Ganache.GanacheOpts) {
super();
this._ganacheProvider = Ganache.provider(opts);
}
/**
function provider(outputFolder, buildLocation, options, should_compile) {
if (should_compile === undefined) {
should_compile = true;
}
const outputLocationEVM = path.resolve(outputFolder, filenameEVM);
const outputLocationAO = path.resolve(outputFolder, filenameAO);
const stack = callsite();
const rootPath = path.dirname(stack[1].getFileName());
if (!buildLocation) {
buildLocation = path.resolve(rootPath, "build/contracts");
}
options.allowUnlimitedContractSize = true;
const arbProvider = ganache.provider(options);
const contractCode = {};
let storageTrackFuncGen = function(address_string) {
return function(err, code) {
contractCode[address_string] = code;
};
};
arbProvider.engine.on("block", function(block) {
for (let [address_string, value] of Object.entries(storage)) {
arbProvider.engine.manager.eth_getCode(
address_string,
"latest",
storageTrackFuncGen(address_string)
);