Chainlink

使用 Remix 的單元測試外掛測試 requestRandomness

  • March 29, 2021

當我測試rollDice哪個執行requestRandomness

function rollDice(uint256 userProvidedSeed, address roller) public onlyOwner returns (bytes32) { 
   require(wagered.get(roller) > 0, "Need money to make money yo!");
   require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK to pay fee");
   bytes32 requestId = requestRandomness(keyHash, fee, userProvidedSeed);
   rollers.set(requestId, roller);
   assert(rollers.get(requestId) == roller);
   emit DiceRolled(requestId, roller);
   return requestId;
}

測試案例

/// #sender: account-0
function play() public {
   game.rollDice(45, acc2);
}

我明白了????

"Transaction has been reverted by the EVM: { "transactionHash": "0xbcfea3fd3d45efca90b9b7a73de47ccd105c872a297deb5a849b4f622384f20e", "transactionIndex": 0, "blockHash": "0x935d9441827fc1dddb34db8591a7d4ceb456826913458c8808850696acd2230c", "blockNumber": 120, "gasUsed": 5000000, "cumulativeGasUsed": 5000000, "status": false, "to": "0x703879Ca741c310b92A39D72B34C6D73D13420E0", "events": {} }"

為了呼叫 Chainlink VRF,您需要使用 LINK 為其提供資金。讓智能合約也收到一些連結。

引用自:https://ethereum.stackexchange.com/questions/96376