2.2.0 • Published 3 years ago

decentraland-contract-plugins v2.2.0

Weekly downloads
7
License
ISC
Repository
github
Last release
3 years ago

Contracts Plugins

⚠️ Work in progress - Collaboration is accepted

⚠️ Buidler Tasks are work in progress

Contracts Plugins is a set of usefull classes to deploy Decentraland contracts for testing purposes.

Table

Install

npm i --save-dev contracts-plugins

Get started

To deploy your Decentraland fake contracts just import the contract you want to use and deploy it. Every contract is deployed within initial settings to let you focus only in testing your new contracts.

exchange.spec.ts

import { Mana, ADDRESS_INDEXES } from 'contracts-plugins'

const BN = web3.utils.BN
const expect = require('chai').use(require('bn-chai')(BN)).expect

describe('Exchange', function() {
  let accounts
  let deployer
  let mana
  let manaContract

  beforeEach(async function() {
    accounts = await web3.eth.getAccounts()
    deployer = accounts[ADDRESS_INDEXES.deployer]

    mana = new Mana({ accounts, artifacts })
    manaContract = await mana.deploy({
      txParams: {
        from: deployer,
        gas: 6e6,
        gasPrice: 21e9
      }
    })
  })

  it('should set initial balances', async function() {
    for (let account of accounts) {
      let balance = await manaContract.balanceOf(account)
      expect(balance).to.eq.BN(web3.utils.toWei('1000', 'ether'))
    }
  })
})

Contracts could need other contract addresses to be deployed and be ready for testing as the Marketplace contract.

Addresses

The contracts allowed are based on the accounts from set when running ganache:

indexname
0deployer
1user
2anotherUser
3operator
4anotherOperator
5updateOperator
6anotherUpdateOperator
7buyer
8anotherBuyer
9bidder
10anotherBidder
11hacker

Use ths script

Contracts

Every contract is deployed by the deployer account.

MANA

Simulates Decentraland MANA contract

deploy

Deploy the MANA contract, set initial balances for all the accounts and return the contrcact reployed

mana.deploy(options)

addBalances

Min amount into every account of accounts.

mana.addBalances(accounts: string[], amount: string)

removeBalances

Remove balances from accounts.

mana.removeBalances(accounts: string[])

getContract

Get the deployed MANA contract

mana.getContract()

ERC721

ERC721 generic contract

deploy

Deploy an ERC721 contract and mint initial tokens:

getContract

Get the deployed erc721 contract

Marketplace

deploy

The marketplace contract needs to be initialized with an erc20 token as the accepted token and an erc721 token as the legacyNFT (related to marketplace v1). This contracts can be passed as properties of the deploy options. If not they will instanceated and deployed.

options

type Marketplaceptions = {
  mana: Mana | null
  erc721: Erc721 | null
  txParams: TxParams
}

Bid

deploy

The marketplace contract needs to be initialized with an erc20 token as the accepted token and an erc721 token as the legacyNFT (related to marketplace v1). This contracts can be passed as properties of the deploy options. If not they will instanceated and deployed.

options

type Marketplaceptions = {
  mana: Mana | null
  erc721: Erc721 | null
  txParams: TxParams
}

Listing

deploy

The marketplace contract needs to be initialized with an erc20 token as the accepted token and an erc721 token as the legacyNFT (related to marketplace v1). This contracts can be passed as properties of the deploy options. If not they will instanceated and deployed.

2.2.0

3 years ago

2.1.0

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.0

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago