I have truffle set up with Ganache. I am running tests on my solidity contract that involve sending ether to the contract and withdrawing it from the contract. Funny thing is my tests are PASSING, but when I look, none of the transactions are going to or coming from the actual address of my deployed contract as shown in Ganache.
The ACCOUNTS in Ganache are having their balances deducted or added to as one would expect, but when looking at the transactions, the contract the tests are interacting with is an address that doesn’t seem to exist. For example, on one deployment the contract address in Ganache was: 0x683EB77121Ab6A40cAE6BD78001E5eD95dbC8872 but the mystery contract address was: 0xe0107F0a6210A7200636F3D15Ee0a3741Fe815F6
Any idea how to resolve this?
Here is the code of my test file:
const CoinFlip = artifacts.require("CoinFlip");
const truffleAssert = require('truffle-assertions');
contract("CoinFlip", async function(accounts) {
it("should make sure the bet is not less than 0.1 ether", async function(){
let instance = await CoinFlip.deployed();
await truffleAssert.fails(instance.bet(0, {from: accounts[1], value: web3.utils.toWei("1000000000000000", "wei")}),
truffleAssert.ErrorType.REVERT);
});
it("should make sure the bet is not more than 10 ether", async function(){
let instance = await CoinFlip.deployed();
await truffleAssert.fails(instance.bet(0, {from: accounts[1], value: web3.utils.toWei("11", "ether")}),
truffleAssert.ErrorType.REVERT);
});
it("should reject a bet if not enough in contract to cover it", async function(){
let instance = await CoinFlip.deployed();
await truffleAssert.fails(instance.bet(0, {from: accounts[1], value: web3.utils.toWei("2", "ether")}),
truffleAssert.ErrorType.REVERT);
});
it("should accept a bet if there is enough in contract to cover it", async function(){
let instance = await CoinFlip.deployed();
console.log(instance.address);
console.log(CoinFlip.address);
await web3.eth.sendTransaction({from: accounts[0], to: instance.address, value: web3.utils.toWei("15", "ether")});
await truffleAssert.passes(instance.bet(0, {from: accounts[1], value: web3.utils.toWei("2", "ether")}),
truffleAssert.ErrorType.REVERT);
});
});
contract()
function is run, your contracts are redeployed to the running Ethereum client so the tests within it run with a clean contract state.". More info: trufflesuite.com/docs/truffle/testing/… – alberto Nov 4 '20 at 19:38