Best JavaScript code snippet using mountebank
Whitelist.js
Source: Whitelist.js
1/* global artifacts, contract, it, assert */2/* eslint-disable prefer-reflect */3const Whitelist = artifacts.require('Whitelist');4const utils = require('./helpers/Utils');5const invalidAccount = '0x0';6contract('Whitelist', accounts => {7 it('verifies that a given address is not whitelisted after construction', async () => {8 let whitelist = await Whitelist.new();9 let isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);10 assert(!isWhitelisted);11 });12 it('verifies that the owner can add an address to the whitelist', async () => {13 let whitelist = await Whitelist.new();14 await whitelist.addAddress(accounts[1]);15 let isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);16 assert(isWhitelisted);17 });18 it('should throw when a non owner tries to add an address to the whitelist', async () => {19 let whitelist = await Whitelist.new();20 await utils.catchRevert(whitelist.addAddress(accounts[1], { from: accounts[2] }));21 });22 it('should throw when the owner tries to add an invalid address to the whitelist', async () => {23 let whitelist = await Whitelist.new();24 await utils.catchRevert(whitelist.addAddress(invalidAccount));25 });26 it('verifies that the owner can add multiple addresses to the whitelist', async () => {27 let whitelist = await Whitelist.new();28 await whitelist.addAddresses([accounts[1], accounts[2]]);29 let isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);30 assert(isWhitelisted);31 isWhitelisted = await whitelist.isWhitelisted.call(accounts[2]);32 assert(isWhitelisted);33 });34 it('should throw when a non owner tries to add multiple addresses to the whitelist', async () => {35 let whitelist = await Whitelist.new();36 await utils.catchRevert(whitelist.addAddresses([accounts[1], accounts[2]], { from: accounts[2] }));37 });38 it('verifies that the owner can remove an address from the whitelist', async () => {39 let whitelist = await Whitelist.new();40 await whitelist.addAddress(accounts[1]);41 let isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);42 assert(isWhitelisted);43 await whitelist.removeAddress(accounts[1]);44 isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);45 assert(!isWhitelisted);46 });47 it('should throw when a non owner tries to remove an address from the whitelist', async () => {48 let whitelist = await Whitelist.new();49 await whitelist.addAddress(accounts[1]);50 let isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);51 assert(isWhitelisted);52 await utils.catchRevert(whitelist.removeAddress(accounts[1], { from: accounts[2] }));53 });54 it('verifies that the owner can remove multiple addresses from the whitelist', async () => {55 let whitelist = await Whitelist.new();56 await whitelist.addAddresses([accounts[1], accounts[2], accounts[3]]);57 let isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);58 assert(isWhitelisted);59 isWhitelisted = await whitelist.isWhitelisted.call(accounts[2]);60 assert(isWhitelisted);61 isWhitelisted = await whitelist.isWhitelisted.call(accounts[3]);62 assert(isWhitelisted);63 await whitelist.removeAddresses([accounts[1], accounts[3]]);64 isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);65 assert(!isWhitelisted);66 isWhitelisted = await whitelist.isWhitelisted.call(accounts[2]);67 assert(isWhitelisted);68 isWhitelisted = await whitelist.isWhitelisted.call(accounts[3]);69 assert(!isWhitelisted);70 });71 it('should throw when a non owner tries to remove multiple address from the whitelist', async () => {72 let whitelist = await Whitelist.new();73 await whitelist.addAddresses([accounts[1], accounts[2], accounts[3]]);74 let isWhitelisted = await whitelist.isWhitelisted.call(accounts[1]);75 assert(isWhitelisted);76 isWhitelisted = await whitelist.isWhitelisted.call(accounts[2]);77 assert(isWhitelisted);78 isWhitelisted = await whitelist.isWhitelisted.call(accounts[3]);79 assert(isWhitelisted);80 await utils.catchRevert(whitelist.removeAddresses([accounts[1], accounts[3]], { from: accounts[2] }));81 });82 it('verifies that an address can be added unless it is already added and removed unless it is already removed', async () => {83 let whitelist = await Whitelist.new();84 let status0 = await whitelist.isWhitelisted.call(accounts[1]);85 let response1 = await whitelist.addAddress(accounts[1]);86 let status1 = await whitelist.isWhitelisted.call(accounts[1]);87 let response2 = await whitelist.addAddress(accounts[1]);88 let status2 = await whitelist.isWhitelisted.call(accounts[1]);89 let response3 = await whitelist.removeAddress(accounts[1]);90 let status3 = await whitelist.isWhitelisted.call(accounts[1]);91 let response4 = await whitelist.removeAddress(accounts[1]);92 let status4 = await whitelist.isWhitelisted.call(accounts[1]);93 assert(!status0 && status1 && status2 && !status3 && !status4);94 assert(response1.logs.length == 1 && response1.logs[0].event == "AddressAddition" && response1.logs[0].args._address == accounts[1]);95 assert(response2.logs.length == 0);96 assert(response3.logs.length == 1 && response3.logs[0].event == "AddressRemoval" && response3.logs[0].args._address == accounts[1]);97 assert(response4.logs.length == 0);98 });...
is-whitelisted.test.ts
Source: is-whitelisted.test.ts
1import "jest-extended";2import { isWhitelisted } from "../../../packages/core-utils/src";3describe("isWhitelisted", () => {4 it("should allow everyone", () => {5 expect(isWhitelisted(["*"], "127.0.0.1")).toBeTrue();6 expect(isWhitelisted(["*"], "192.168.1.1")).toBeTrue();7 expect(isWhitelisted(["*"], "168.1.1.1")).toBeTrue();8 });9 it("should allow addresses with prefixes", () => {10 expect(isWhitelisted(["127.*"], "127.0.0.1")).toBeTrue();11 expect(isWhitelisted(["127.*"], "127.0.0.2")).toBeTrue();12 expect(isWhitelisted(["127.*"], "128.0.0.1")).toBeFalse();13 });14 it("should allow addresses with suffixes", () => {15 expect(isWhitelisted(["*.127"], "1.1.1.127")).toBeTrue();16 expect(isWhitelisted(["*.127"], "1.1.1.127")).toBeTrue();17 expect(isWhitelisted(["*.127"], "1.1.1.128")).toBeFalse();18 });...
Using AI Code Generation
1var isWhitelisted = require('mountebank').isWhitelisted;2var assert = require('assert');3describe('isWhitelisted', function () {4 it('should return true for whitelisted host', function () {5 assert.ok(isWhitelisted('www.google.com'));6 });7 it('should return false for non-whitelisted host', function () {8 assert.ok(!isWhitelisted('www.google.com'));9 });10});11describe('isWhitelisted', function () {12 it('should return true for whitelisted host', function () {13 assert.ok(isWhitelisted('www.google.com'));14 });15 it('should return false for non-whitelisted host', function () {16 assert.ok(!isWhitelisted('www.google.com'));17 });18});19describe('isWhitelisted', function () {20 it('should return true for whitelisted host', function () {21 assert.ok(isWhitelisted('www.google.com'));22 });23 it('should return false for non-whitelisted host', function () {24 assert.ok(!isWhitelisted('www.google.com'));25 });26});27describe('isWhitelisted', function () {28 it('should return true for whitelisted host', function () {29 assert.ok(isWhitelisted('www.google.com'));30 });31 it('should return false for non-whitelisted host', function () {32 assert.ok(!isWhitelisted('www.google.com'));33 });34});35describe('isWhitelisted', function () {36 it('should return true for whitelisted host', function () {37 assert.ok(isWhitelisted('www.google.com'));38 });39 it('should return false for non-whitelisted host', function () {40 assert.ok(!isWhitelisted('www.google.com'));41 });42});43describe('isWhitelisted', function () {44 it('should return true for whitelisted host', function () {45 assert.ok(isWhitelisted('www.google.com'));46 });47 it('should return false for non-whitelisted host', function () {48 assert.ok(!
Check out the latest blogs from LambdaTest on this topic:
Agile software development stems from a philosophy that being agile means creating and responding to change swiftly. Agile means having the ability to adapt and respond to change without dissolving into chaos. Being Agile involves teamwork built on diverse capabilities, skills, and talents. Team members include both the business and software development sides working together to produce working software that meets or exceeds customer expectations continuously.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
In 2007, Steve Jobs launched the first iPhone, which revolutionized the world. But because of that, many businesses dealt with the problem of changing the layout of websites from desktop to mobile by delivering completely different mobile-compatible websites under the subdomain of ‘m’ (e.g., https://m.facebook.com). And we were all trying to figure out how to work in this new world of contending with mobile and desktop screen sizes.
Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.
Software Risk Management (SRM) combines a set of tools, processes, and methods for managing risks in the software development lifecycle. In SRM, we want to make informed decisions about what can go wrong at various levels within a company (e.g., business, project, and software related).
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!