Vuilder(opens new window) is the Solidity++ smart contract development kit to help developers reduce complexity of compilation, library linking, testing, and deployment of the contract. Vuilder has the following common commands:
Copy
npx vuilder node // start a local gvite node
npx vuilder compile // compile contract
npx vuilder test // test contract
npx ts-node deploy.ts // execute a ts file
The following sections show how to use Vuilder with an example.
The settings below should not be modified due to the mnemonic phrase for local network has been set up by default.
Copy
{"networks":{"local":{"http":"http://127.0.0.1:23456/","ws":"http://127.0.0.1:23457/","mnemonic":"record deliver increase organ subject whisper private tourist final athlete unit jacket arrow trick sweet chuckle direct print master post senior pluck whale taxi"}}}
Write test cases in HelloWorld.spec.ts
Copy
vim test/HelloWorld.spec.ts
Copy
import{ expect }from"chai";const vuilder =require("@vite/vuilder");import config from"./vite.config.json";letprovider: any;letdeployer: any;describe("test HelloWorld",()=>{before(asyncfunction(){
provider = vuilder.newProvider(config.networks.local.http);
console.log(await provider.request("ledger_getSnapshotChainHeight"));
deployer = vuilder.newAccount(config.networks.local.mnemonic,0, provider);
console.log('deployer', deployer.address);});it('test set function',async()=>{// compileconst compiledContracts =await vuilder.compile('HelloWorld.solpp');expect(compiledContracts).to.have.property('HelloWorld');// deploylet helloWorld = compiledContracts.HelloWorld;
helloWorld.setDeployer(deployer).setProvider(provider);await helloWorld.deploy({});expect(helloWorld.address).to.be.a('string');
console.log(helloWorld.address);// check default value of datalet result =await helloWorld.query('data',[]);
console.log('return', result);expect(result).to.be.an('array').with.lengthOf(1);expect(result![0]).to.be.equal('123');// call HelloWorld.set(456);awaithelloWorld.call('set',['456'],{});// check value of data
result =await helloWorld.query('data',[]);
console.log('return', result);expect(result).to.be.an('array').with.lengthOf(1);expect(result![0]).to.be.equal('456');});});
Write test cases in transfer.spec.ts
Copy
vim test/transfer.spec.ts
Copy
import{ describe }from"mocha";import{ expect }from"chai";import*as vuilder from"@vite/vuilder";import config from"./vite.config.json";letprovider: any;letdeployer: vuilder.UserAccount;describe('test transfer',()=>{before(asyncfunction(){
provider = vuilder.newProvider(config.networks.local.http);
console.log(await provider.request("ledger_getSnapshotChainHeight"));
deployer = vuilder.newAccount(config.networks.local.mnemonic,0, provider);
console.log('deployer', deployer.address);});it('test contract',async()=>{// compileconst compiledContracts =await vuilder.compile('transfer.solpp');expect(compiledContracts).to.have.property('TransferVite');// init user accountsconst alice = vuilder.newAccount(config.networks.local.mnemonic,1, provider);
console.log('alice', alice.address);const bob = vuilder.newAccount(config.networks.local.mnemonic,2, provider);
console.log('bob', bob.address);await deployer.sendToken(alice.address,'200');await alice.receiveAll();await deployer.sendToken(bob.address,'100');await bob.receiveAll();// deploylet transferVite = compiledContracts.TransferVite;
transferVite.setDeployer(deployer).setProvider(provider);await transferVite.deploy({tokenId:'tti_5649544520544f4b454e6e40',amount:'600'});expect(transferVite.address).to.be.a('string');
console.log(transferVite.address);let balanceA =await transferVite.balance();expect(balanceA).to.be.equal('600');// Alice sent 50 to the contract Aconst block =await alice.sendToken(transferVite.address,'50');await vuilder.utils.waitFor(()=>{return vuilder.isReceived(provider, block.hash);},"Wait for receiving token");// check balance of A
balanceA =await transferVite.balance();// console.log('balance of A:', balanceA);expect(balanceA).to.be.equal('650');// check events of Alet events =await transferVite.getPastEvents('Received',{fromHeight:0,toHeight:0});expect(events[0]?.returnValues?.sender).to.be.equal(alice.address);expect(events[0]?.returnValues?.token).to.be.equal('tti_5649544520544f4b454e6e40');expect(events[0]?.returnValues?.amount).to.be.equal('50');// check balance of Alicelet balanceAlice =await alice.balance();// console.log('balance of Alice:', balanceAlice);expect(balanceAlice).to.be.equal('150');// Alice call contract A.sendViteTo() to send token to BobawaittransferVite.call('sendViteTo',[bob.address,30],{caller: alice,amount:"100"});// check balance of Bob before receivinglet balanceBob =await bob.balance();// console.log('balance of Bob:', balanceBob);expect(balanceBob).to.be.equal('100');// Bob recevie the moneyawait bob.receiveAll();// check balance of Bob after receiving
balanceBob =await bob.balance();// console.log('balance of Bob:', balanceBob);expect(balanceBob).to.be.equal('130');// check balance of A
balanceA =await transferVite.balance();// console.log('balance of A:', balanceA);expect(balanceA).to.be.equal('720');});});