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

228
Visualizações
Unable to compare the ETH values in a Truffle testing

I'm testing a payment feature of a smart contract on Truffle, but I'm unable to compare the ETH values:

Smart Contract

uint256 public price; 
uint256 payment;

constructor(
    uint256 _price,
) public payable {
    require(
        _price > 0,
        "The price has to be greater than 0."
    );
    
    price = _price;
}
                                        
// The caller of the method should provide the correct amount of ETH as required.
function pay() public payable {
    require(
        msg.value == price,
        "Incorrect price."
    );

    payment = msg.value;
}

Testing

contract('Payment Test', (accounts) => {
  let contract, priceInput;
  beforeEach(async function () {
    priceInput = web3.utils.toWei("1", "ether");
    contract = await MyContract.deployed(priceInput, { from: accounts[0] });
  });

  it("Successfully make a payment", async () => {
    try {
    // Using the same amount used in the constructor here "priceInput"
      await contract.pay({ from: accounts[1], value: priceInput });
    } catch (e) {
      console.log(e)
    }

    // assertions
  });
})

I'm getting the revert error:

'RuntimeError: VM Exception while processing transaction: revert Incorrect price.\n'

I've tried number literals like 100, instead of web3.utils.toWei("1", "ether"), as the value to pass, but get the same result.

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