Contracts Plugins is a set of usefull classes to deploy Decentraland contracts for testing purposes.
npm i --save-dev contracts-plugins
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.
The contracts allowed are based on the accounts from set when running ganache:
index | name |
---|---|
0 | deployer |
1 | user |
2 | anotherUser |
3 | operator |
4 | anotherOperator |
5 | updateOperator |
6 | anotherUpdateOperator |
7 | buyer |
8 | anotherBuyer |
9 | bidder |
10 | anotherBidder |
11 | hacker |
Use ths script
Every contract is deployed by the deployer
account.
Simulates Decentraland MANA contract
Deploy the MANA contract, set initial balances for all the accounts and return the contrcact reployed
mana.deploy(options)
Min amount
into every account of accounts
.
mana.addBalances(accounts: string[], amount: string)
Remove balances from accounts
.
mana.removeBalances(accounts: string[])
Get the deployed MANA contract
mana.getContract()
ERC721 generic contract
Deploy an ERC721 contract and mint initial tokens:
1
to user2
to anotherUser
Get the deployed erc721 contract
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
}
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
}
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.