2

First of all, sorry about the code written in Portuguese.

I have the following contract:

    contract GerenciadorBoletos {
     struct Boleto {
         uint codigoBarra;
         uint codigoBarraDigitavel;
         uint cpfOuCnpjBeneficiario;
         uint cpfOuCnpjPagador;
         uint valorOriginal;
         uint dataVencimento;
     }

     mapping(uint => Boleto) public registroBoletos;

     function inserirBoleto(
         uint codigoBarra,
         uint codigoBarraDigitavel,
         uint cpfOuCnpjBeneficiario,
         uint cpfOuCnpjPagador,
         uint valorOriginal,
         uint dataVencimento
     ) {
         Boleto memory b = Boleto(
             codigoBarra,
             codigoBarraDigitavel,
             cpfOuCnpjBeneficiario,
             cpfOuCnpjPagador,
             valorOriginal,
             dataVencimento
         );

         /* I need to do some validations before store it, but there is no code yet */

         registroBoletos[b.codigoBarra] = b;
     }
 }

Then I'm running some mocha test suites with web3.js

    // generates a new registry
    function gerarBoletoValido() {
        return {
            codigoBarra: BigNumber.random(44).toString().slice(2),
            codigoBarraDigitavel: BigNumber.random(47).toString().slice(2),
            cpfOuCnpjBeneficiario: BigNumber.random(14).toString().slice(2),
            cpfOuCnpjPagador: BigNumber.random(11).toString().slice(2),
            valorOriginal: parseInt(Math.random() * 1000),
            dataVencimento: Date.now() + 3*24*3600,
            dataLimitePagamento: Date.now() + 7*24*3600,
            metodoCalculo: MetodoCalculo.INTERNO,
            multa: parseInt(Math.random() * 100),
            juros: parseInt(Math.random() * 100) % 11,
            desconto: parseInt(Math.random() * 100) % 11,
        }
    }
var boletoValido = gerarBoletoValido();
it('Deve inserir com sucesso um boleto com os dados válidos', function(done){
     gerenciadorBoleto.inserirBoleto.sendTransaction(
     boletoValido.codigoBarra,
     boletoValido.codigoBarraDigitavel,
     boletoValido.cpfOuCnpjBeneficiario,
     boletoValido.cpfOuCnpjPagador,
     boletoValido.valorOriginal,
     boletoValido.dataVencimento,
     {
         from: web3.eth.accounts[0],
         gas: 3000000,
     },
     function(e, result) {
         expect(e).to.not.exist;
         expect(result).to.exist;
         result.should.be.above(0);
         expect(String(gerenciadorBoleto.registroBoletos(boletoValido.codigoBarra)[0])).to.be.equal(String(boletoValido.codigoBarra));
         done();
     });
});

The problem is that the last assertion shows that nothing is being inserted:

     Uncaught AssertionError: expected '0' to equal '41227991517789294285860497224073582695415194'
          + expected - actual
      -0
      +41227991517789294285860497224073582695415194

What am I missing?

Richard
  • 4,934
  • 2
  • 7
  • 25
Henrique Barcelos
  • 2,481
  • 4
  • 20
  • 38

0 Answers0