class and type updates

revert-603-optF
aniket-engg 4 years ago committed by Aniket
parent febab2efc2
commit 0c4348a6ee
  1. 2
      libs/remix-simulator/src/genesis.ts
  2. 2
      libs/remix-simulator/src/index.ts
  3. 96
      libs/remix-simulator/src/methods/misc.ts
  4. 34
      libs/remix-simulator/src/methods/net.ts
  5. 17
      libs/remix-simulator/src/provider.ts
  6. 113
      libs/remix-simulator/src/utils/logs.ts
  7. 14
      libs/remix-simulator/test/accounts.ts

@ -2,7 +2,7 @@ import EthJSBlock from 'ethereumjs-block'
import { BN } from 'ethereumjs-util'
export function generateBlock (executionContext) {
const block = new EthJSBlock({
const block: EthJSBlock = new EthJSBlock({
header: {
timestamp: (new Date().getTime() / 1000 | 0),
number: 0,

@ -1,3 +1 @@
export { Provider } from './provider'
// export { Provider }

@ -1,62 +1,60 @@
const version = require('../../package.json').version
import web3 from 'web3'
export class Misc {
methods () {
return {
web3_clientVersion: this.web3_clientVersion.bind(this),
eth_protocolVersion: this.eth_protocolVersion.bind(this),
eth_syncing: this.eth_syncing.bind(this),
eth_mining: this.eth_mining.bind(this),
eth_hashrate: this.eth_hashrate.bind(this),
web3_sha3: this.web3_sha3.bind(this),
eth_getCompilers: this.eth_getCompilers.bind(this),
eth_compileSolidity: this.eth_compileSolidity.bind(this),
eth_compileLLL: this.eth_compileLLL.bind(this),
eth_compileSerpent: this.eth_compileSerpent.bind(this)
}
import Web3 from 'web3'
export function methods () {
return {
web3_clientVersion: this.web3_clientVersion.bind(this),
eth_protocolVersion: this.eth_protocolVersion.bind(this),
eth_syncing: this.eth_syncing.bind(this),
eth_mining: this.eth_mining.bind(this),
eth_hashrate: this.eth_hashrate.bind(this),
web3_sha3: this.web3_sha3.bind(this),
eth_getCompilers: this.eth_getCompilers.bind(this),
eth_compileSolidity: this.eth_compileSolidity.bind(this),
eth_compileLLL: this.eth_compileLLL.bind(this),
eth_compileSerpent: this.eth_compileSerpent.bind(this)
}
}
web3_clientVersion (payload, cb) {
cb(null, 'Remix Simulator/' + version)
}
export function web3_clientVersion (payload, cb) {
cb(null, 'Remix Simulator/' + version)
}
eth_protocolVersion (payload, cb) {
cb(null, '0x3f')
}
export function eth_protocolVersion (payload, cb) {
cb(null, '0x3f')
}
eth_syncing (payload, cb) {
cb(null, false)
}
export function eth_syncing (payload, cb) {
cb(null, false)
}
eth_mining (payload, cb) {
// TODO: should depend on the state
cb(null, false)
}
export function eth_mining (payload, cb) {
// TODO: should depend on the state
cb(null, false)
}
eth_hashrate (payload, cb) {
cb(null, '0x0')
}
export function eth_hashrate (payload, cb) {
cb(null, '0x0')
}
web3_sha3 (payload, cb) {
const str = payload.params[0]
cb(null, web3.utils.sha3(str))
}
export function web3_sha3 (payload, cb) {
const str: string = payload.params[0]
cb(null, Web3.utils.sha3(str))
}
eth_getCompilers (payload, cb) {
cb(null, [])
}
export function eth_getCompilers (payload, cb) {
cb(null, [])
}
eth_compileSolidity (payload, cb) {
cb(null, 'unsupported')
}
export function eth_compileSolidity (payload, cb) {
cb(null, 'unsupported')
}
eth_compileLLL (payload, cb) {
cb(null, 'unsupported')
}
export function eth_compileLLL (payload, cb) {
cb(null, 'unsupported')
}
eth_compileSerpent (payload, cb) {
cb(null, 'unsupported')
}
export function eth_compileSerpent (payload, cb) {
cb(null, 'unsupported')
}

@ -1,24 +1,20 @@
export class Net {
methods () {
return {
net_version: this.net_version,
net_listening: this.net_listening,
net_peerCount: this.net_peerCount
}
export function methods (): Record<string, unknown> {
return {
net_version: this.net_version,
net_listening: this.net_listening,
net_peerCount: this.net_peerCount
}
}
net_version (payload, cb) {
// should be configured networkId
cb(null, 1337)
}
export function net_version (payload, cb): void {
// should be configured networkId
cb(null, 1337)
}
net_listening (payload, cb) {
cb(null, true)
}
export function net_listening (payload, cb): void {
cb(null, true)
}
net_peerCount (payload, cb) {
cb(null, 0)
}
export function net_peerCount (payload, cb): void {
cb(null, 0)
}

@ -2,14 +2,13 @@ import { Blocks } from './methods/blocks'
import { execution } from '@remix-project/remix-lib'
const { executionContext } = execution
import { Logger } from './utils/logs'
const logger = new Logger()
import { info } from './utils/logs'
import merge from 'merge'
import { Accounts } from './methods/accounts'
import { Filters } from './methods/filters'
import { Misc } from './methods/misc'
import { Net } from './methods/net'
import { methods as miscMethods } from './methods/misc'
import { methods as netMethods } from './methods/net'
import { Transactions } from './methods/transactions'
import { Debug } from './methods/debug'
import { generateBlock } from './genesis'
@ -31,9 +30,9 @@ export class Provider {
this.methods = {}
this.methods = merge(this.methods, this.Accounts.methods())
this.methods = merge(this.methods, (new Blocks(this.executionContext, options)).methods())
this.methods = merge(this.methods, (new Misc()).methods())
this.methods = merge(this.methods, miscMethods())
this.methods = merge(this.methods, (new Filters(this.executionContext)).methods())
this.methods = merge(this.methods, (new Net()).methods())
this.methods = merge(this.methods, netMethods())
this.methods = merge(this.methods, this.Transactions.methods())
this.methods = merge(this.methods, (new Debug(this.executionContext)).methods())
@ -51,13 +50,13 @@ export class Provider {
const method = this.methods[payload.method]
if (this.options.logDetails) {
logger.info(payload)
info(payload)
}
if (method) {
return method.call(method, payload, (err, result) => {
if (this.options.logDetails) {
logger.info(err)
logger.info(result)
info(err)
info(result)
}
if (err) {
return callback(err)

@ -4,75 +4,72 @@ import gray from 'ansi-gray'
import timestamp from 'time-stamp'
import supportsColor from 'color-support'
export class Logger {
private hasFlag(flag) {
return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
}
private addColor(str) {
if (this.hasFlag('no-color')) {
return str
}
if (this.hasFlag('color')) {
return gray(str)
}
if (supportsColor()) {
return gray(str)
}
function hasFlag(flag) {
return ((typeof (process) !== 'undefined') && (process.argv.indexOf('--' + flag) !== -1))
}
function addColor(str) {
if (this.hasFlag('no-color')) {
return str
}
private stdout(arg) {
if (typeof (process) === 'undefined' || !process.stdout) return
process.stdout.write(arg)
if (this.hasFlag('color')) {
return gray(str)
}
private stderr(arg) {
if (typeof (process) === 'undefined' || process.stderr) return
process.stderr.write(arg)
if (supportsColor()) {
return gray(str)
}
private getTimestamp() {
const coloredTimestamp = this.addColor(timestamp('HH:mm:ss'))
return '[' + coloredTimestamp + ']'
}
return str
}
log(...args: any[]) {
const time = this.getTimestamp()
this.stdout(time + ' ')
console.log(args)
return this
}
function stdout(arg) {
if (typeof (process) === 'undefined' || !process.stdout) return
process.stdout.write(arg)
}
info(...args: any[]) {
const time = this.getTimestamp()
this.stdout(time + ' ')
console.info(args)
return this
}
function stderr(arg) {
if (typeof (process) === 'undefined' || process.stderr) return
process.stderr.write(arg)
}
dir(...args: any[]) {
const time = this.getTimestamp()
this.stdout(time + ' ')
console.dir(args)
return this
}
function getTimestamp() {
const coloredTimestamp = this.addColor(timestamp('HH:mm:ss'))
return '[' + coloredTimestamp + ']'
}
warn(...args: any[]) {
const time = this.getTimestamp()
this.stderr(time + ' ')
console.warn(args)
return this
}
export function log(...args: any[]) {
const time = this.getTimestamp()
this.stdout(time + ' ')
console.log(args)
return this
}
error(...args: any[]) {
const time = this.getTimestamp()
this.stderr(time + ' ')
console.error(args)
return this
}
export function info(...args: any[]) {
const time = this.getTimestamp()
this.stdout(time + ' ')
console.info(args)
return this
}
export function dir(...args: any[]) {
const time = this.getTimestamp()
this.stdout(time + ' ')
console.dir(args)
return this
}
export function warn(...args: any[]) {
const time = this.getTimestamp()
this.stderr(time + ' ')
console.warn(args)
return this
}
export function error(...args: any[]) {
const time = this.getTimestamp()
this.stderr(time + ' ')
console.error(args)
return this
}

@ -12,17 +12,17 @@ describe('Accounts', () => {
describe('eth_getAccounts', () => {
it('should get a list of accounts', async function () {
const accounts = await web3.eth.getAccounts()
const accounts: string[] = await web3.eth.getAccounts()
assert.notEqual(accounts.length, 0)
})
})
describe('eth_getBalance', () => {
it('should get a account balance', async () => {
const accounts = await web3.eth.getAccounts()
const balance0 = await web3.eth.getBalance(accounts[0])
const balance1 = await web3.eth.getBalance(accounts[1])
const balance2 = await web3.eth.getBalance(accounts[2])
const accounts: string[] = await web3.eth.getAccounts()
const balance0: string = await web3.eth.getBalance(accounts[0])
const balance1: string = await web3.eth.getBalance(accounts[1])
const balance2: string = await web3.eth.getBalance(accounts[2])
assert.deepEqual(balance0, '100000000000000000000')
assert.deepEqual(balance1, '100000000000000000000')
@ -32,8 +32,8 @@ describe('Accounts', () => {
describe('eth_sign', () => {
it('should sign payloads', async () => {
const accounts = await web3.eth.getAccounts()
const signature = await web3.eth.sign('Hello world', accounts[0])
const accounts: string[] = await web3.eth.getAccounts()
const signature: string = await web3.eth.sign('Hello world', accounts[0])
assert.deepEqual(signature.length, 132)
})

Loading…
Cancel
Save