0

It took me awhile to diagnose the problem. At first I just noticed that the states of my contracts were being affected by previous tests when running truffle test I then looked in the terminal tab in which I was running geth for my private network. I looked through the transactions and contract deployments and noticed that every time another test file begins execution all of my contracts are deployed again as expected. Then I realised that even after this all the transactions coming through from the tests were interacting with the first deployed contracts from the first test. All the contract instances returned by .deployed() in the second through last tests were referring to the contracts originally deployed in the in the first test. Below is a more simplified version of what I would see in the tab where I was running my geth node.

//executing test/first.js
Submitted contract creation fullhash=0xTransactionHash0 contract=0xContractAddress0
Submitted contract creation fullhash=0xTransactionHash1 contract=0xContractAddress1
Submitted transaction fullhash=0xTransactionHash2 recipient=0xContractAddress1
//executing test/second.js
Submitted contract creation fullhash=0xTransactionHash3 contract=0xContractAddress2
Submitted contract creation fullhash=0xTransactionHash4 contract=0xContractAddress3
Submitted transaction fullhash=0xTransactionHash5 recipient=0xContractAddress1

geth version => 1.9.12-stable

truffle version => Truffle v5.1.20 (core: 5.1.20) Solidity v0.5.16 (solc-js) Node v8.10.0 Web3.js v1.2.1

Here is my startnode.sh file

geth --networkid 122349 --mine --minerthreads 2 --datadir "." --nodiscover --rpc --rpcport "8545" --port "30303" --rpccorsdomain "*" --nat "any" --rpcapi eth,web3,personal,net,debug --unlock 0 --password ./password.sec --ipcpath "~/.ethereum/geth.ipc" --allow-insecure-unlock --targetgaslimit '9000000'

I don't have this problem when I use ganache-cli this seems to be specific to geth. If any of you have any ideas as to what the cause of this error could be or and suggestions as to how I could potentially fix this I really apreciate them. Thank you all!

2 Answers 2

0

Hello just a while after posting this question I found that this can be solved by using .new() instead of .deployed() the use of .new() ensures that the contract will deployed again and will return the instance at a new address

0

What causes .deployed() to return same contract instances in each test?

Creating a brand new blockchain every time you run your tests would yield this behavior.


The states of my contracts were being affected by previous tests when running truffle test.

I don't have this problem when I use ganache-cli; this seems to be specific to geth.

By default:

  • Ganache initializes a new blockchain every time you start it (unless you specify the --db flag)
  • Geth continues running on the existing blockchain (unless you delete it beforehand)

That explains your observation (and the problem that you're dealing with).

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.