I want to test the following contract.
The contract contracts/Token.sol
is using ERC721 contract and Open Zeppelin architecture.
And I wrote the test code test/Token.js
following but I ran the truffle test
, the transaction was reverted, and said Error: Returned error: VM Exception while processing transaction: revert
.
await proxy.methods.mint().send({from: sender})
has some problem.
How do I test the ERC721 minting function?
Thank you!
contracts/Token.sol
pragma solidity ^0.5.8;
import "@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/ERC721Full.sol";
import "@openzeppelin/upgrades/contracts/Initializable.sol";
contract Token is Initializable, ERC721Full {
string public tokenName;
uint256 internal nextTokenId;
function mint() external {
uint256 tokenId = nextTokenId;
nextTokenId = nextTokenId.add(1);
super._mint(msg.sender, tokenId);
}
function initialize(string memory _tokenName) public {
tokenName = _tokenName;
nextTokenId = 0;
}
function setTokenURI(uint256 _tokenId, string calldata _message) external {
super._setTokenURI(_tokenId, _message);
}
}
test/Token.js
const { TestHelper } = require('@openzeppelin/cli');
const { Contracts, ZWeb3 } = require('@openzeppelin/upgrades');
ZWeb3.initialize(web3.currentProvider);
const ABNToken = Contracts.getFromLocal('ABNToken');
const tokenName = "start";
web3.eth.getAccounts(function(error, result) {
if (error) console.log("Couldn't get accounts")
sender = result[0]
})
require('chai').should();
contract('ABNToken', function () {
let proxy
beforeEach(async function () {
this.project = await TestHelper();
proxy = await this.project.createProxy(ABNToken);
proxy.options.from = sender;
await proxy.methods.initialize(tokenName).send({from: sender});
})
it('Initialize function test', async function () {
let tokenname = await proxy.methods.tokenName().call();
tokenname.should.eq(tokenName);
})
it('Mint function test', async function () {
console.log(proxy.methods)
await proxy.methods.mint().send({from: sender})
})
})