Socket
Socket
Sign inDemoInstall

@beamnetwork/chai-beam

Package Overview
Dependencies
330
Maintainers
5
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.4 to 0.3.5

58

index.js
/* eslint-env mocha */
/* global assert, contract */
/* global assert, contract, web3 */

@@ -12,2 +12,9 @@ const { expect } = require('chai')

/**
* Return true iff test is executed under ganache
*/
async function isGanache() {
return (await web3.eth.net.getId()) === 4447
}
/**
* Asserts that the promise will throw a revert error when executing.

@@ -20,8 +27,11 @@ * Fails if the promise does not throw a revert error

await promise
expect.fail(new Error('The promise did not revert'))
} catch (error) {
let msg = error.message || message || ''
msg = msg.toString()
assert(msg.includes('VM Exception while processing transaction: revert'), `Expected revert, Error: ${message || error.message}`)
if (!await isGanache()) {
return
}
const msg = (error.message || '').toString()
assert(msg.includes('revert'), `Expected revert, Error: ${message || error.message}`)
return
}
expect.fail(new Error(message || 'The promise did not revert'))
}

@@ -35,24 +45,24 @@ /**

await promise
expect.fail(new Error('The promise did not revert'))
} catch (error) {
let msg = error.message || ''
msg = msg.toString()
assert(revertMessage, 'Need to include an expected revertMessage')
if (!await isGanache()) {
return
}
const msg = (error.message || '').toString()
assert(msg.includes('VM Exception while processing transaction: revert', `Expected revert, Error: ${msg}`))
assert(msg.includes(revertMessage), `Expected revert to contain message: ${revertMessage} \n Actual Message: ${msg}`)
return
}
expect.fail(new Error('The promise did not revert'))
}
/**
* Asserts that the promis will throw an invalid opcode error.
* Fails if the promise does not throw the invalid opcode error
* Inspired by https://github.com/OpenZeppelin/openzeppelin-solidity/blob/947de54ceea3abe4783ac2e417b6d9bfb93d708e/test/helpers/assertRevert.js
* Awaits the promise, and if the promise causes a revert ignores it.
* If the promise causes a non-revert error, the function will throw
*/
async function assertJump(promise, message) {
async function ignoreRevert(promise) {
try {
await promise
expect.fail(new Error('Expected invalid opcode not received'))
} catch (error) {
let msg = error.message || message || ''
msg = msg.toString()
assert(msg.includes('VM Exception while processing transaction: invalid opcode'), `Expected invalid opcode, Error: ${message || error.message}`)
if (error.message.search('revert') < 0) throw error
}

@@ -62,11 +72,18 @@ }

/**
* Awaits the promise, and if the promise causes a revert ignores it.
* If the promise causes a non-revert error, the function will throw
* Asserts that the promis will throw an invalid opcode error.
* Fails if the promise does not throw the invalid opcode error
* Inspired by https://github.com/OpenZeppelin/openzeppelin-solidity/blob/947de54ceea3abe4783ac2e417b6d9bfb93d708e/test/helpers/assertRevert.js
*/
async function ignoreRevert(promise) {
async function assertJump(promise, message) {
try {
await promise
} catch (error) {
if (error.message.search('revert') < 0) throw error
if (!await isGanache()) {
return
}
const msg = (error.message || '').toString()
assert(msg.includes('VM Exception while processing transaction: invalid opcode'), `Expected invalid opcode, Error: ${message || error.message}`)
return
}
expect.fail(new Error(message || 'Expected invalid opcode not received'))
}

@@ -139,3 +156,4 @@

expectNotEvent,
isGanache,
ZERO_ADDRESS,
}
{
"name": "@beamnetwork/chai-beam",
"version": "0.3.4",
"version": "0.3.5",
"description": "Beam plugins for chai",

@@ -30,3 +30,3 @@ "main": "index.js",

"devDependencies": {
"eslint": "^5.6.1",
"eslint": "^5.12.1",
"eslint-config-airbnb": "^17.1.0",

@@ -36,8 +36,8 @@ "eslint-config-airbnb-base": "^13.1.0",

"eslint-plugin-chai-friendly": "^0.4.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-mocha": "^5.2.0",
"eslint-plugin-import": "^2.16.0",
"eslint-plugin-mocha": "^5.2.1",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.1.0",
"truffle": "5.0.0-beta.1"
"truffle": "^5.0.2"
},

@@ -47,4 +47,4 @@ "dependencies": {

"ethjs-abi": "^0.2.1",
"web3": "^1.0.0-beta.36"
"web3": "^1.0.0-beta.41"
}
}

@@ -8,3 +8,3 @@ /* eslint-env mocha */

// eslint-disable-next-line
assertRevert, assertRevertMessage, assertJump, ignoreRevert, ignoreJump, expectEvent, expectNotEvent
assertRevert, assertRevertMessage, assertJump, ignoreRevert, ignoreJump, expectEvent, expectNotEvent, isGanache
} = require('../index.js')

@@ -36,3 +36,3 @@

it('should print the correct message when a throw occures', async () => {
it('should print the correct message when a throw does not occur', async () => {
const message = 'a seriously descriptive message'

@@ -59,3 +59,3 @@ let threw = false

} catch (e) {
assert(e.message.toString().includes('Expected revert to contain message: undefined'), 'revert did not contain the correct message')
assert(e.message.toString().includes('Need to include an expected revertMessage'), 'revert did not contain the correct message')
threw = true

@@ -69,2 +69,5 @@ }

it('should fail when revert with wrong message thrown', async () => {
if (!await isGanache()) {
return
}
let threw = false

@@ -118,3 +121,3 @@ try {

it('should print the correct message when a throw occures', async () => {
it('should print the correct message when a throw does not occur', async () => {
const message = 'a seriously descriptive message'

@@ -121,0 +124,0 @@ let threw = false

module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// to customize your Truffle configuration!
networks: {
geth: {
host: '127.0.0.1',
port: 8545,
network_id: '*',
websockets: false,
},
},
solc: {
optimizer: {
enabled: true,
runs: 200,
},
},
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc