diff --git a/remix-simulator/package.json b/remix-simulator/package.json index e3d2116695..26d4c15c13 100644 --- a/remix-simulator/package.json +++ b/remix-simulator/package.json @@ -82,5 +82,8 @@ } ] ] + }, + "devDependencies": { + "mocha": "^5.2.0" } } diff --git a/remix-simulator/test/accounts.js b/remix-simulator/test/accounts.js new file mode 100644 index 0000000000..689baed8d7 --- /dev/null +++ b/remix-simulator/test/accounts.js @@ -0,0 +1,19 @@ +var Web3 = require('web3') +var RemixSim = require('../index.js') +let web3 = new Web3() +var assert = require('assert') + +describe("Accounts", function() { + + before(function() { + let provider = new RemixSim.Provider() + web3.setProvider(provider) + }) + + it("should get a list of accounts", async function() { + let accounts = await web3.eth.getAccounts() + assert.notEqual(accounts.length, 0) + }) + +}); + diff --git a/remix-simulator/test/blocks.js b/remix-simulator/test/blocks.js new file mode 100644 index 0000000000..80ba0bd635 --- /dev/null +++ b/remix-simulator/test/blocks.js @@ -0,0 +1,48 @@ +var Web3 = require('web3') +var RemixSim = require('../index.js') +let web3 = new Web3(); +var assert = require('assert') + +describe("blocks", function() { + + before(function() { + let provider = new RemixSim.Provider() + web3.setProvider(provider) + }) + + it("should get block given its number", async function() { + let block = await web3.eth.getBlock(1) + + let expectedBlock = { + difficulty: '0', + extraData: '0x', + gasLimit: 8000000, + gasUsed: 0, + hash: '0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f', + logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + miner: '0x3333333333333333333333333333333333333333', + mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + nonce: '0x0000000000000042', + number: 0, + parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', + receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', + sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', + size: 504, + stateRoot: '0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff', + timestamp: 0, + totalDifficulty: '0', + transactions: [], + transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', + uncles: [] + } + + assert.deepEqual(block, expectedBlock) + }) + + it("should get gas price", async function() { + let gasPrice = await web3.eth.getGasPrice() + assert.equal(gasPrice, 1) + }) + +}); + diff --git a/remix-simulator/test/misc.js b/remix-simulator/test/misc.js new file mode 100644 index 0000000000..0f8e8b8467 --- /dev/null +++ b/remix-simulator/test/misc.js @@ -0,0 +1,50 @@ +var Web3 = require('web3') +var RemixSim = require('../index.js') +let web3 = new Web3(); +var assert = require('assert') + +describe("Misc", function() { + + before(function() { + let provider = new RemixSim.Provider() + web3.setProvider(provider) + }) + + it("should get correct remix simulator version", async function(done) { + web3._requestManager.send({method: 'web3_clientVersion', params: []}, (err, version) => { + let remix_version = require('../package.json').version + assert.equal(version, "Remix Simulator/" + remix_version) + done(); + }) + }) + + it("should get protocol version", async function() { + web3._requestManager.send({method: 'eth_protocolVersion', params: []}, (err, result) => { + assert.equal(result, "0x3f") + }) + }) + + it("should get if is syncing", async function() { + let isSyncing = await web3.eth.isSyncing() + assert.equal(isSyncing, false) + }) + + it("should get if is mining", async function() { + let isMining = await web3.eth.isMining() + assert.equal(isMining, false) + }) + + it("should get hashrate", async function() { + let hashrate = await web3.eth.getHashrate() + assert.equal(hashrate, 0) + }) + + it("should get result of a sha3", async function() { + web3._requestManager.send({method: 'web3_sha3', params: ["0x68656c6c6f20776f726c64"]}, (err, result) => { + assert.equal(result, "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad") + }) + }) + +}); + + diff --git a/remix-simulator/test/whisper.js b/remix-simulator/test/whisper.js new file mode 100644 index 0000000000..54565acbd2 --- /dev/null +++ b/remix-simulator/test/whisper.js @@ -0,0 +1,19 @@ +var Web3 = require('web3') +var RemixSim = require('../index.js') +let web3 = new Web3(); +var assert = require('assert') + +describe("Whisper", function() { + + before(function() { + let provider = new RemixSim.Provider() + web3.setProvider(provider) + }) + + it("should get correct remix simulator version", async function() { + let version = await web3.shh.getVersion() + assert.equal(version, 5) + }) + +}); + diff --git a/remix-tests/package.json b/remix-tests/package.json index c4c295b684..6b386390d2 100644 --- a/remix-tests/package.json +++ b/remix-tests/package.json @@ -46,7 +46,7 @@ "signale": "^1.2.1", "solc": "^0.4.24", "standard": "^10.0.3", - "web3": "1.0.0-beta.27", + "web3": "1.0.0-beta.34", "winston": "^3.0.0" }, "devDependencies": {