Skip to content

Commit

Permalink
Updated RngBlockhash to use latest DrawManager
Browse files Browse the repository at this point in the history
  • Loading branch information
asselstine committed Mar 12, 2024
1 parent b802a5b commit 633ccf3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 60 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ src = 'src'
out = 'out'
test = 'test'
libs = ['lib']
solc = "0.8.21"
solc = "0.8.24"
fs_permissions = [{ access = "read", path = "./broadcast" }]
gas_reports = ["Foo"]

Expand Down
16 changes: 0 additions & 16 deletions script/Foo.s.sol

This file was deleted.

18 changes: 16 additions & 2 deletions src/RngBlockhash.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
pragma solidity ^0.8.24;

import "forge-std/console2.sol";

import { IRng } from "pt-v5-draw-manager/interfaces/IRng.sol";
import { DrawManager } from "pt-v5-draw-manager/DrawManager.sol";

/**
* @title RngBlockhash
* @notice A simple contract for generating random numbers using blockhashes
* @dev This contract is intended to be used as a reference implementation for the IRng interface
*/
contract RngBlockhash is IRng {

/**
Expand Down Expand Up @@ -45,7 +53,7 @@ contract RngBlockhash is IRng {
/// @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. The calling contract
/// should "lock" all activity until the result is available via the `requestId`
function requestRandomNumber()
external
public
payable
virtual
returns (uint32 requestId, uint32 lockBlock)
Expand Down Expand Up @@ -89,6 +97,12 @@ contract RngBlockhash is IRng {
return requestLockBlock[rngRequestId];
}

function startDraw(DrawManager _drawManager, address _rewardRecipient) external payable returns (uint24) {
(uint32 requestId,) = requestRandomNumber();
console2.log("startDraw requestId: %d", requestId);
return _drawManager.startDraw(_rewardRecipient, requestId);
}

/// @dev Checks if the request for randomness from the 3rd-party service has completed
/// @param requestId The ID of the request used to get the results of the RNG service
/// @return True if the request has completed and a random number is available, false otherwise
Expand Down
40 changes: 0 additions & 40 deletions test/Foo.t.sol

This file was deleted.

26 changes: 26 additions & 0 deletions test/RngBlockhash.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.24;

import "forge-std/Test.sol";
import { DrawManager } from "pt-v5-draw-manager/DrawManager.sol";

import { RngBlockhash } from "../src/RngBlockhash.sol";

contract RngBlockhashTest is Test {

RngBlockhash rng;
DrawManager drawManager;

function setUp() public {
rng = new RngBlockhash();
drawManager = DrawManager(makeAddr("drawManager"));
vm.etch(address(drawManager), "drawManager"); // to ensure calls fail if not mocked
}

function test_startDraw() public {
address recipient = makeAddr("recipient");
vm.mockCall(address(drawManager), abi.encodeWithSelector(drawManager.startDraw.selector, recipient, 1), abi.encode(22));
assertEq(rng.startDraw(drawManager, recipient), 22);
}

}

0 comments on commit 633ccf3

Please sign in to comment.