Обновлен код
Вот обновленный тест, который работает с вашим кодом.
const NFToken = artifacts.require('NFTokenMock');
contract('NFTokenMock', (accounts) => {
let nftoken;
const id1 = 1;
const id2 = 2;
const id3 = 3;
const id4 = 40000;
beforeEach(async () => {
nftoken = await NFToken.new();
});
it('returns correct balanceOf after mint', async () => {
await nftoken.mint(accounts[0], id1);
const count = await nftoken.balanceOf(accounts[0]);
assert.equal(count.toNumber(), 1);
});
});
Попробуй
Для настройки трюфеля требуются кучи котла. Давайте попробуем.
mkdir tmp && cd tmp
Затем положите это в свой пакет. Json
{
"dependencies": {
"@0xcert/ethereum-erc721": "^2.0.0-rc1",
"truffle": "^5.0.2",
"web3": "^1.0.0-beta.37"
}
}
и запустить npm install
. Также нам нужен специальный хак, чтобы получить Truffle, используя нужную нам версию компилятора Solidity (0.5.1):
(cd node_modules/truffle && npm install solc@0.5.1)
Теперь настройте проект Truffle:
mkdir contracts
echo > contracts/Migrations.sol <<EOL
pragma solidity ^0.5.1;
// Boilerplate required, https://github.com/trufflesuite/truffle/issues/1382
contract Migrations {}
EOL
mkdir Migrations
echo > Migrations/1.js <<EOL
// Boilerplate required, https://github.com/trufflesuite/truffle/issues/1382
module.exports = ($)=>{};
EOL
Вот ваш контракт. Сохраните его в контрактах / nf-token-mock.sol:
pragma solidity 0.5.1;
import "@0xcert/ethereum-erc721/src/contracts/tokens/nf-token.sol";
import "@0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol";
/**
* @dev This is an example contract implementation of NFToken.
*/
contract NFTokenMock is
NFToken,
Ownable
{
/**
* @dev Mints a new NFT.
* @param _to The address that will own the minted NFT.
* @param _tokenId of the NFT to be minted by the msg.sender.
*/
function mint(
address _to,
uint256 _tokenId
)
external
onlyOwner
{
super._mint(_to, _tokenId);
}
}
И сохраните вышеуказанный тестовый файл в test / go.js.
Если вам повезет, наберите: npx truffle test
и вы должны увидеть
Using network 'test'.
Compiling ./contracts/Migrations.sol...
Contract: NFTokenMock
✓ correctly checks all the supported interfaces (55ms)
✓ correctly approves account (156ms)
2 passing (420ms)