Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
Truffle test not changing/saving smart contract variables

Hi whenever I test in truffle and I call a function that should change a variables value inside the contract and then try and access this value, the value does not change. Below I have code to try and debug this issue for another project. The function works perfectly in remix

On my end I call increaseIterator() and then console.log the value and it is still 0. In remix the value would increase to 1. Please help

Test:

const Test = artifacts.require("testing");
const { expectRevert } = require("@openzeppelin/test-helpers");
const { web3 } = require("@openzeppelin/test-helpers/src/setup");

contract('testing', (accounts) => {
    let testing
    beforeEach (async() => {
        testing = await Test.new();
        await web3.eth.sendTransaction({from: accounts[0], to: accounts[1], value: 1000})
    })

    it('should increase', async() => {
        const beforeIncrease = await testing.returnIterator();
        console.log("before increase: " + beforeIncrease);

        testing.send.increaseIterator();

        const afterIncrease = await testing.returnIterator();
        console.log("after increase: " + afterIncrease);
    })
})

Smart contract:

pragma solidity 0.8.14;

contract testing {
uint iterator;

constructor () {
    iterator = 0;
}

function increaseIterator() public {
    iterator++;
}

function returnIterator() public view returns (uint) {
    return iterator;
}
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda