0

I want my function to be able to accept an array of Hashed secrets as a parameter and since solidity doesn't allow for strings, I had to use a byte32[].

The string parameter is an intake for the user's secret which I am hashing with Keccak256 which should convert it to a byte32 value.

Since (or so I think) the hashed secret string is a byte32 and so is the hashed secret stored in the first element of the byte32 array, the assertion should evaluate to true when comparing them

Test:

it("Checking secrets", function() {
    return myContract.deployed().then(function(instance){
      contract = instance;
      return contract.test.call("hello", ["1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"])
      .then(function(testVals){
        assert.equal(testVals[0].valueOf(), testVals[1][0].valueOf())
      })
  });
});

Function:

function test(string val1, bytes32[] val2) public returns(bytes32, bytes32[]){
        return(keccak256(val1), val2);
    }

Result:

AssertionError: expected '0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8' to equal '0x3163386166663935303638356332656434626333313734663334373232383762'
  • 3
    Try a leading 0x, i.e. 0x1c8aff95... – smarx Jun 8 '18 at 3:02
  • wow such a silly mistake lol... thank you so much for checking back in with me since the AM. – JonathanScialpi Jun 8 '18 at 3:05
0

@smarx was correct. I had to add a leading "0x" to the hashes I was passing to the byte32 array:

it("Checking secrets", function() {
    return myContract.deployed().then(function(instance){
      contract = instance;
      return contract.test.call("hello", ["0x1c8aff950685c2ed4bc3174f3472287b56d9517b9c948127319a09a7a36deac8"])
      .then(function(testVals){
        assert.equal(testVals[0].valueOf(), testVals[1][0].valueOf())
      })
  });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.