1

I have tested a contract on truffle using the command:

 truffle test

I got following message:

D:\Funding4\contracts>truffle test Compiling .\contracts\Funding4.sol... Compiling .\contracts\Migrations.sol... Compiling .\test\Funding4Test.sol... Compiling truffle/Assert.sol... Compiling truffle/DeployedAddresses.sol...


  Funding4Test
    √ testSettingAnOwnerOfDeployedContract (169ms)


  1 passing (1s)


D:\Funding4\contracts>

After the execution, I checked Ganache, it shows me 8 blocks. I can't understand why it has 8 blocks. It has compiled 5 files. How its showing 8 blocks? It should show 5 blocks. Somebody please guide me.

Blocks in Ganachi

I have attached the picture of Ganache.

Zulfi.

1
  • Can you share your test file? Probably you are making some transactions there, and each transaction gets its own block... Commented Oct 16, 2018 at 5:30

1 Answer 1

1

Ganache creates a block on demand, if you send at least one transaction Ganache creates a block. You need to check your test carefully and count all deployments, all (non pure/view) function calls.

For instance blocks 2, 4, 8 are look like function call, based on used gas

UPDATED

When you write test in Solidity it becomes complicated to track all transactions, because truffle does amount of extra transactions for deployment, migration, hooks, etc.

Transcription:

  1. Deploy Migrations contract
  2. Call setCompleted() in Migrations contract
  3. Deploy Funding4 contract
  4. Call setCompleted() in Migrations contract
  5. Deploy Assert contract
  6. Deploy contract (not sure about purpose of the contract, looks like proxy with relations to Migrations contract and Funding4 contract)
  7. Deploy TestFunding4 contract
  8. Call testSettingAnOwnerOfDeployedContract() in TestFunding4 contract
5
  • My test file is: 'import "truffle/DeployedAddresses.sol"; import "truffle/Assert.sol"; import "../contracts/Funding4.sol"; contract Funding4Test { function testSettingAnOwnerOfDeployedContract() public{ Funding4 funding = Funding4(DeployedAddresses.Funding4()); Assert.equal(funding.owner(), msg.sender, "An owner is different than a deployer"); }' I think there are 3 functions plus one additional in Assert.equal(....). Please guide me.
    – zak100
    Commented Oct 16, 2018 at 15:05
  • pragma solidity ^0.4.24; contract Funding4{ address public owner; constructor( ) public{ owner = msg.sender; } } Okay msg.sender is a transaction but funding.owner() should not involve any ether. Also I don't know about DeployedAadresses.Funding4() and testSettingAnOwnerOfDeployedContract() if they are transactions or not. Also owner is a variable. Why we have parentheses with it?? Please guide me.
    – zak100
    Commented Oct 16, 2018 at 20:21
  • @zak100 put some details about the question
    – Aquila
    Commented Oct 17, 2018 at 10:54
  • Thanks, how you know that 2, 4, 8 are function calls?
    – zak100
    Commented Oct 18, 2018 at 17:56
  • @zak100 based on gas usage
    – Aquila
    Commented Oct 18, 2018 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.