Select ‘Create Bucket’ in the top right corner to create a new bucket.
3. Enter a bucket name and choose the IPFS storage network to create the bucket.
Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.
5. Open a terminal window. Then, set up an Access Key file for use with S3FS-FUSE.
Set up a credentials file for S3FS at ${HOME}/.passwd-s3fs. You will need to save your Filebase Access and Secret keys to this file and give it owner permissions. You can do so with the following commands:
7. Now, navigate into the mounted Filebase bucket.
cd /path/to/mounted/bucket
8. Create a new folder for your project, then navigate inside that folder:
mkdir waffle-tutorial
cd waffle-tutorial
9. Next, install the ethereum-waffle package:
npm install --save-dev ethereum-waffle
10. Install the OpenZeppelin package, we’ll be using this for our smart contract functionality:
npm install @openzeppelin/contracts@^4.6.0 -D
11. Make a new directory called src, then create a new file called BasicToken.sol. Open this file in your IDE, and insert the following content:
// SPDX-License-Identifier: MITpragmasolidity ^0.8.0;import"@openzeppelin/contracts/token/ERC20/ERC20.sol";// Example class - a mock class using delivering from ERC20contractBasicTokenisERC20 {constructor(uint256 initialBalance) ERC20("Basic", "BSC") {_mint(msg.sender, initialBalance);}}
12. Then, at the root of your project, create a new file called package.json. Insert the following content:
{"scripts": {"build":"waffle"}}
13. Create another new file called waffle.json that contains the following content:
14. Create new directories called build and contracts at the root of your project, since they are used in the waffle.json file.
mkdir build
mkdir contracts
15. Then build the project with the command:
npm run build
16. Now it’s time to test the smart contract. Run the following command to install Chai to be used for a test environment:
npm install --save-dev mocha chai
17. Make another new directory in the root of your project called test, then create a new file called BasicToken.test.ts in this directory. Open this new file in your IDE, and insert the following content:
import {expect, use} from'chai';import {Contract} from'ethers';import {deployContract, MockProvider, solidity} from'ethereum-waffle';import BasicToken from'../build/BasicToken.json';use(solidity);describe('BasicToken', () => {const [wallet,walletTo] =newMockProvider().getWallets();let token:Contract;beforeEach(async () => {token =awaitdeployContract(wallet, BasicToken, [1000]);});it('Assigns initial balance',async () => {expect(awaittoken.balanceOf(wallet.address)).to.equal(1000);});it('Transfer adds amount to destination account',async () => {awaittoken.transfer(walletTo.address,7);expect(awaittoken.balanceOf(walletTo.address)).to.equal(7);});it('Transfer emits event',async () => {awaitexpect(token.transfer(walletTo.address,7)).to.emit(token,'Transfer').withArgs(wallet.address,walletTo.address,7);});it('Can not transfer above the amount',async () => {awaitexpect(token.transfer(walletTo.address,1007)).to.be.reverted;});it('Can not transfer from empty account',async () => {consttokenFromOtherWallet=token.connect(walletTo);awaitexpect(tokenFromOtherWallet.transfer(wallet.address,1)).to.be.reverted;});it('Calls totalSupply on BasicToken contract',async () => {awaittoken.totalSupply();expect('totalSupply').to.be.calledOnContract(token);});it('Calls balanceOf with sender address on BasicToken contract',async () => {awaittoken.balanceOf(wallet.address);expect('balanceOf').to.be.calledOnContractWith(token, [wallet.address]);});});
18. Open your package.json file and insert the following content:
19. Then, add a new file called .mocharc.json in the root of your project:
{"spec":"test/**/*.test.{js,ts}"}
20. Then, run your test with:
npm test
This test should return the following output:
BasicToken
✓ Assigns initial balance (84ms)
✓ Transfer adds amount to destination account (404ms)
✓ Transfer emits event (219ms)
✓ Can not transfer above the amount (32ms)
✓ Can not transfer from empty account (95ms)
✓ Calls totalSupply on BasicToken contract (67ms)
✓ Calls balanceOf with sender address on BasicToken contract (75ms)
7 passing (8s)