Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ethereum-waffle/mock-contract

Package Overview
Dependencies
Maintainers
1
Versions
143
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethereum-waffle/mock-contract - npm Package Compare versions

Comparing version 4.0.3-dev.cf42065 to 4.0.3-dev.d4cc0eb

6

dist/cjs/src/index.d.ts

@@ -5,2 +5,6 @@ import { Contract, Signer, utils } from 'ethers';

export declare type Stub = ReturnType<typeof stub>;
declare type DeployOptions = {
address: string;
override?: boolean;
};
export interface MockContract extends Contract {

@@ -19,4 +23,4 @@ mock: {

};
export declare function deployMockContract(signer: Signer, abi: ABI): Promise<MockContract>;
export declare function deployMockContract(signer: Signer, abi: ABI, options?: DeployOptions): Promise<MockContract>;
export {};
//# sourceMappingURL=index.d.ts.map

@@ -9,3 +9,31 @@ "use strict";

const Doppelganger_json_1 = __importDefault(require("./Doppelganger.json"));
async function deploy(signer) {
async function deploy(signer, options) {
if (options) {
const { address, override } = options;
const provider = signer.provider;
if (!override && await provider.getCode(address) !== '0x') {
throw new Error(`${address} already contains a contract. ` +
'If you want to override it, set the override parameter.');
}
if (provider._hardhatNetwork) {
if (await provider.send('hardhat_setCode', [
address,
'0x' + Doppelganger_json_1.default.evm.deployedBytecode.object
])) {
return new ethers_1.Contract(address, Doppelganger_json_1.default.abi, signer);
}
else
throw new Error(`Couldn't deploy at ${address}`);
}
else {
if (await provider.send('evm_setAccountCode', [
address,
'0x' + Doppelganger_json_1.default.evm.deployedBytecode.object
])) {
return new ethers_1.Contract(address, Doppelganger_json_1.default.abi, signer);
}
else
throw new Error(`Couldn't deploy at ${address}`);
}
}
const factory = new ethers_1.ContractFactory(Doppelganger_json_1.default.abi, Doppelganger_json_1.default.bytecode, signer);

@@ -43,4 +71,4 @@ return factory.deploy();

}
async function deployMockContract(signer, abi) {
const mockContractInstance = await deploy(signer);
async function deployMockContract(signer, abi, options) {
const mockContractInstance = await deploy(signer, options);
const mock = createMock(abi, mockContractInstance);

@@ -47,0 +75,0 @@ const mockedContract = new ethers_1.Contract(mockContractInstance.address, abi, signer);

@@ -5,2 +5,6 @@ import { Contract, Signer, utils } from 'ethers';

export declare type Stub = ReturnType<typeof stub>;
declare type DeployOptions = {
address: string;
override?: boolean;
};
export interface MockContract extends Contract {

@@ -19,4 +23,4 @@ mock: {

};
export declare function deployMockContract(signer: Signer, abi: ABI): Promise<MockContract>;
export declare function deployMockContract(signer: Signer, abi: ABI, options?: DeployOptions): Promise<MockContract>;
export {};
//# sourceMappingURL=index.d.ts.map
import { Contract, ContractFactory, utils } from 'ethers';
import DoppelgangerContract from './Doppelganger.json';
async function deploy(signer) {
async function deploy(signer, options) {
if (options) {
const { address, override } = options;
const provider = signer.provider;
if (!override && await provider.getCode(address) !== '0x') {
throw new Error(`${address} already contains a contract. ` +
'If you want to override it, set the override parameter.');
}
if (provider._hardhatNetwork) {
if (await provider.send('hardhat_setCode', [
address,
'0x' + DoppelgangerContract.evm.deployedBytecode.object
])) {
return new Contract(address, DoppelgangerContract.abi, signer);
}
else
throw new Error(`Couldn't deploy at ${address}`);
}
else {
if (await provider.send('evm_setAccountCode', [
address,
'0x' + DoppelgangerContract.evm.deployedBytecode.object
])) {
return new Contract(address, DoppelgangerContract.abi, signer);
}
else
throw new Error(`Couldn't deploy at ${address}`);
}
}
const factory = new ContractFactory(DoppelgangerContract.abi, DoppelgangerContract.bytecode, signer);

@@ -36,4 +64,4 @@ return factory.deploy();

}
export async function deployMockContract(signer, abi) {
const mockContractInstance = await deploy(signer);
export async function deployMockContract(signer, abi, options) {
const mockContractInstance = await deploy(signer, options);
const mock = createMock(abi, mockContractInstance);

@@ -40,0 +68,0 @@ const mockedContract = new Contract(mockContractInstance.address, abi, signer);

26

package.json
{
"name": "@ethereum-waffle/mock-contract",
"description": "Mock smart contracts in a smart way.",
"version": "4.0.3-dev.cf42065",
"version": "4.0.3-dev.d4cc0eb",
"author": "Marek Kirejczyk <account@ethworks.io> (http://ethworks.io)",

@@ -39,14 +39,15 @@ "repository": "git@github.com:EthWorks/Waffle.git",

"devDependencies": {
"@ethereum-waffle/chai": "4.0.8-dev.d4cc0eb",
"@ethereum-waffle/compiler": "4.0.3-dev.d4cc0eb",
"@ethereum-waffle/provider": "4.0.5-dev.d4cc0eb",
"@ethersproject/abi": "^5.6.1",
"@ethersproject/providers": "5.6.2",
"eslint": "^7.14.0",
"ethers": "5.6.2",
"@ethersproject/abi": "^5.6.1",
"@ethereum-waffle/chai": "4.0.8-dev.cf42065",
"@ethereum-waffle/compiler": "4.0.3-dev.cf42065",
"mocha": "^8.2.1",
"rimraf": "^3.0.2",
"solc": "0.8.15",
"@ethereum-waffle/provider": "4.0.5-dev.cf42065",
"ts-node": "^9.0.0",
"typechain": "^8.0.0",
"mocha": "^8.2.1",
"rimraf": "^3.0.2",
"typescript": "^4.6.2",
"eslint": "^7.14.0",
"ts-node": "^9.0.0"
"typescript": "^4.6.2"
},

@@ -57,12 +58,11 @@ "peerDependencies": {

"scripts": {
"test": "export NODE_ENV=test && yarn test:build && mocha",
"test": "export NODE_ENV=test && mocha",
"lint": "eslint '{src,test}/**/*.ts'",
"lint:fix": "eslint --fix '{src,test}/**/*.ts'",
"build": "rimraf ./dist && yarn build:sol && yarn build:esm && yarn build:cjs",
"build": "rimraf ./dist && yarn build:sol && yarn build:esm && yarn build:cjs && ts-node ./test/helpers/buildTestContracts.ts",
"build:sol": "ts-node compile.ts",
"build:esm": "tsc -p tsconfig.build.json --outDir dist/esm --module ES6",
"build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs",
"test:build": "ts-node ./test/helpers/buildTestContracts.ts",
"clean": "rimraf ./dist ./test/example/build"
}
}

@@ -5,2 +5,3 @@ import {Contract, ContractFactory, Signer, utils} from 'ethers';

import DoppelgangerContract from './Doppelganger.json';
import type {JsonRpcProvider} from '@ethersproject/providers';

@@ -11,2 +12,7 @@ type ABI = string | Array<utils.Fragment | JsonFragment | string>

type DeployOptions = {
address: string;
override?: boolean;
}
export interface MockContract extends Contract {

@@ -20,3 +26,27 @@ mock: {

async function deploy(signer: Signer) {
async function deploy(signer: Signer, options?: DeployOptions) {
if (options) {
const {address, override} = options;
const provider = signer.provider as JsonRpcProvider;
if (!override && await provider.getCode(address) !== '0x') {
throw new Error(
`${address} already contains a contract. ` +
'If you want to override it, set the override parameter.');
}
if ((provider as any)._hardhatNetwork) {
if (await provider.send('hardhat_setCode', [
address,
'0x' + DoppelgangerContract.evm.deployedBytecode.object
])) {
return new Contract(address, DoppelgangerContract.abi, signer);
} else throw new Error(`Couldn't deploy at ${address}`);
} else {
if (await provider.send('evm_setAccountCode', [
address,
'0x' + DoppelgangerContract.evm.deployedBytecode.object
])) {
return new Contract(address, DoppelgangerContract.abi, signer);
} else throw new Error(`Couldn't deploy at ${address}`);
}
}
const factory = new ContractFactory(DoppelgangerContract.abi, DoppelgangerContract.bytecode, signer);

@@ -59,4 +89,4 @@ return factory.deploy();

export async function deployMockContract(signer: Signer, abi: ABI): Promise<MockContract> {
const mockContractInstance = await deploy(signer);
export async function deployMockContract(signer: Signer, abi: ABI, options?: DeployOptions): Promise<MockContract> {
const mockContractInstance = await deploy(signer, options);

@@ -63,0 +93,0 @@ const mock = createMock(abi, mockContractInstance);

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

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc