@apeswap.finance/test-helpers

0.2.0 • Public • Published

ApeSwap Test Helpers

A suite of Solidity smart contract test helpers. Use to easily test contracts against popular ApeSwap features.

NOTICE:

This project uses @openzeppelin/test-environment under the hood to deploy contracts to the development. Using this helper module assumes you are using @openzeppelin/test-environment for testing as well.

Overview

Installation

yarn add -D @apeswapfinance/test-helpers

OR

npm install --save-dev @apeswapfinance/test-helpers

Configruation

As this module is hosted as a GitHub package, create a .npmrc file in the root of your project with these details:

@apeswapfinance:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}

In your environment, set NPM_TOKEN to your github access token.

export NPM_TOKEN=<github-access-token>

Hardhat (formerly Buidler)

Install web3 and the hardhat-web3 plugin.

npm install --save-dev @nomiclabs/hardhat-web3 web3

Remember to include the plugin in your configuration as explained in the installation instructions.

Usage

Import @apeswapfinance/test-helpers in your test files to access helper deploy functions.

Mock Farm

const {
  dex,  // Deploy/manage a test dex
  farm, // Deploy/manage a test farm
} = require('@apeswapfinance/test-helpers');
const { accounts, contract } = require('@openzeppelin/test-environment');
const { assert } = require('chai');

describe('MasterApe', function () {
    const [owner, feeTo, alice, bob, carol] = accounts;

    beforeEach(async () => {
        const {
            bananaToken,
            bananaSplitBar,
            masterApe,
        } = await farm.deployMockFarm(accounts); // accounts passed will be used in the deployment
        this.masterApe = masterApe;
    });

    it('should have proper pool length', async () => {
        assert.equal((await this.masterApe.poolLength()).toString(), '1');
    });
});

Mock Dex

const {
  dex,  // Deploy/manage a test dex
  farm, // Deploy/manage a test farm
} = require('@apeswapfinance/test-helpers');
const { accounts, contract } = require('@openzeppelin/test-environment');
const { assert } = require('chai');

describe('ApeFactory', function () {
    this.timeout(10000);
    const [owner, feeTo, alice, bob, carol] = accounts;

    beforeEach(async () => {
        const {
            dexFactory,
            mockWBNB,
            mockTokens,
            dexPairs
        } = await dex.deployMockDex(accounts, 5); // accounts passed will be used in the deployment
        this.dexFactory = dexFactory;
    });

    it('should have proper pair length', async () => {
        assert.equal((await this.dexFactory.allPairsLength()).toString(), '5');
    });
});

License

MIT

Dependents (0)

Package Sidebar

Install

npm i @apeswap.finance/test-helpers

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

370 kB

Total Files

20

Last publish

Collaborators

  • defifofum