Saturday, September 25, 2021

Ethereum Programming 11 decentragram 1

//cmd
truffle migrate --reset
truffle test
Contract: Decentragram
    deployment
      √ deploys successfully
      √ has a name (203ms)


  2 passing (291ms)

--------------------------------
//migrations/2_deploy_contracts.js

const Decentragram = artifacts.require("Decentragram");

module.exports = function (deployer) {
  deployer.deploy(Decentragram);
};

---------------------------
//src/contracs/Decentragram.sol

pragma solidity ^0.5.0;

contract Decentragram {
  // Code goes here...
  string public name = "Decentragram";
}

----------------------
//test/test.js

const Decentragram = artifacts.require('./Decentragram.sol')

require('chai')
  .use(require('chai-as-promised'))
  .should()

contract('Decentragram', ([deployer, author, tipper]) => {
  let decentragram

  before(async () => {
    decentragram = await Decentragram.deployed()
  })

  describe('deployment', async () => {
    it('deploys successfully', async () => {
      const address = await decentragram.address
      assert.notEqual(address, 0x0)
      assert.notEqual(address, '')
      assert.notEqual(address, null)
      assert.notEqual(address, undefined)
    })

    it('has a name', async () => {
      const name = await decentragram.name()
      assert.equal(name, 'Decentragram')
    })
  })
})

reference:

No comments:

Post a Comment