Hi, I'm in need of help using Lib ECDSA.
What am I trying to do?
I'm trying to get a subscription and check my Smart Contract if everything is ok.
Below I'm putting my files that I have so far.
When I run the tests it is entering the "else" condition, shouldn't it enter the IF condition? or am i using recover with the wrong parameters?
Would they be able to help me?
pragma solidity >=0.4.22 <0.9.0;
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "./TokenERC20.sol";
contract InstanceCoin{
address contractInstance;
constructor(address _contract){
contractInstance = _contract;
}
function reedemToken(uint _amount, bytes32 _hash, bytes memory _signature) public {
// TokenERC20 token = TokenERC20(contractInstance);
if(ECDSA.recover(_hash, _signature) == msg.sender)
revert("is correct");
else
revert("is not correct"); //revert just test
}
}
My file Test Unit js is:
const InstanceCoin = artifacts.require('coins/InstanceCoin');
const EthCrypto = require("eth-crypto");
const signerIdentity = EthCrypto.createIdentity();
const message = EthCrypto.hash.keccak256 ([
{type: "uint256", value: "500"},
]);
const signature = EthCrypto.sign(signerIdentity.privateKey, message);
console.log(`message: ${message}`);
console.log(`signature: ${signature}`);
console.log(`signer public key: ${signerIdentity.address}`);
contract("InstanceCoin", (accounts) => {
let [alice, bob, cain, dan] = accounts;
let contractInstance;
beforeEach(async () => {
contractInstance = await InstanceCoin.deployed();
});
describe("deploys", async () => {
it("just only test", async () => {
await contractInstance.reedemToken(10, message, signature, {from: alice});
});
});
})
Output test:
Error: Returned error: VM Exception while processing transaction: revert is not correct -- Reason given: is not correct.