Skip to content

Commit

Permalink
fixup! feat: migrated all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RasenGUY committed Nov 25, 2023
1 parent f4ca314 commit 35d0e6d
Show file tree
Hide file tree
Showing 95 changed files with 3,918 additions and 1,129 deletions.
3 changes: 1 addition & 2 deletions contracts/FeeManager.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableMapUpgradeable.sol";

import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "hardhat/console.sol";

Expand Down
10 changes: 5 additions & 5 deletions contracts/WegaGameController.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;

import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableMapUpgradeable.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "hardhat/console.sol";

Expand Down Expand Up @@ -35,8 +35,8 @@ contract WegaGameController is
UUPSUpgradeable
{

using EnumerableMapUpgradeable for EnumerableMapUpgradeable.UintToUintMap;
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet;
using EnumerableMap for EnumerableMap.UintToUintMap;
using EnumerableSet for EnumerableSet.UintSet;
using Strings for string;
using Arrays for uint256[];

Expand All @@ -46,7 +46,7 @@ contract WegaGameController is
mapping(bytes32 => IWega.Wega) private _games;
mapping(uint256 => address) _registeredGames;
mapping(uint256 => GameSettings) _gameSettings;
EnumerableSetUpgradeable.UintSet _gameNameHashes;
EnumerableSet.UintSet _gameNameHashes;

function initialize(
address erc20EscrowAddress,
Expand Down
8 changes: 4 additions & 4 deletions contracts/WegaRandomizerController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pragma solidity ^0.8.19;
* oracle implementation for random numbers
* @dev note this is draft contract not meant to be used in production
*/
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableMapUpgradeable.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";

import "@openzeppelin/contracts/utils/math/Math.sol";

import "./IWegaRandomizerController.sol";
Expand All @@ -23,9 +23,9 @@ import "./randomizer/WegaRandomizer.sol";

contract WegaRandomizerController is AccessControlErrors, WegaProtocolAdminRole, UUPSUpgradeable, IWegaRandomizerController {

using EnumerableMapUpgradeable for EnumerableMapUpgradeable.UintToUintMap;
using EnumerableMap for EnumerableMap.UintToUintMap;
using Math for uint256;
using CountersUpgradeable for CountersUpgradeable.Counter;


address public RANDOMIZER;
bytes32 public constant GAME_CONTROLLER_ROLE = keccak256('GAME_CONTROLLER_ROLE');
Expand Down
6 changes: 0 additions & 6 deletions contracts/escrow/IWegaERC20Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ interface IWegaERC20Escrow {
uint256 nonce
) external view returns (bytes32 escrowHash_);

/**
* @notice retrieves the current nonce of account that wants to create a wager
* @param account is the account that will create the wager
*/
function currentNonce(address account) external view returns (uint256);

/**
* @notice retrieves all erc20 wager requests in existance
*/
Expand Down
47 changes: 20 additions & 27 deletions contracts/escrow/WegaERC20Escrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
pragma solidity ^0.8.14;

// lib imports
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableMapUpgradeable.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/utils/Nonces.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

// protocol imports
Expand All @@ -32,11 +33,12 @@ contract WegaERC20Escrow is
IERC20EscrowEvents,
WegaProtocolAdminRole,
WegaEscrowErrors,
ReentrancyGuardUpgradeable,
Nonces,
UUPSUpgradeable
{
using CountersUpgradeable for CountersUpgradeable.Counter;
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.Bytes32Set;
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
using EnumerableSet for EnumerableSet.Bytes32Set;
using EnumerableSet for EnumerableSet.AddressSet;
using Math for uint256;

bytes32 public GAME_CONTROLLER_ROLE;
Expand All @@ -48,10 +50,7 @@ contract WegaERC20Escrow is
mapping(bytes32 => mapping(address => uint256)) private _deposits;

// for keeping track of depositor addresses
mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) _depositors;

// mapping of creators -> nonces
mapping(address => CountersUpgradeable.Counter) private _wagerNonces;
mapping(bytes32 => EnumerableSet.AddressSet) _depositors;

// request balance
mapping(bytes32 => uint256) private _escrowBalances;
Expand All @@ -60,7 +59,7 @@ contract WegaERC20Escrow is
mapping(address => uint256) private _accountBalances;

// stores all the transfer Ids, will be used enumeration
EnumerableSetUpgradeable.Bytes32Set private _escrowHashes;
EnumerableSet.Bytes32Set private _escrowHashes;

// fees
IFeeManager internal _feeManager;
Expand Down Expand Up @@ -133,11 +132,11 @@ contract WegaERC20Escrow is
wagerRequest_.tokenAddress = tokenAddress;
wagerRequest_.wagerAmount = wagerAmount;
wagerRequest_.totalWager = wagerAmount * requiredPlayerNum;
wagerRequest_.nonce = currentNonce(account);
wagerRequest_.nonce = nonces(account);

// increment user nonce
_wagerNonces[account].increment();

_useNonce(account);
// create escrowHash
bytes32 escrowHash_ = hash(
wagerRequest_.tokenAddress,
Expand All @@ -162,7 +161,7 @@ contract WegaERC20Escrow is
_escrowBalances[escrowHash_] += wagerAmount;

// deposit to escrow
IERC20Upgradeable(wagerRequest_.tokenAddress).transferFrom(
ERC20Upgradeable(wagerRequest_.tokenAddress).transferFrom(
account,
address(this),
wagerAmount
Expand Down Expand Up @@ -190,12 +189,6 @@ contract WegaERC20Escrow is
);
}

function currentNonce(
address account
) public view override returns (uint256) {
return _wagerNonces[account].current();
}

function getWagerRequests()
external
view
Expand Down Expand Up @@ -243,7 +236,7 @@ contract WegaERC20Escrow is

// transfer tokens to escrow
_escrowBalances[escrowHash] += wagerAmount;
IERC20Upgradeable(request.tokenAddress).transferFrom(
ERC20Upgradeable(request.tokenAddress).transferFrom(
account,
address(this),
wagerAmount
Expand Down Expand Up @@ -284,7 +277,7 @@ contract WegaERC20Escrow is
emit SetWithdrawers(escrowHash, winners_);
}

function withdraw(bytes32 escrowHash) public {
function withdraw(bytes32 escrowHash) public nonReentrant {
ERC20WagerRequest memory request = _wagerRequests[escrowHash];
require(request.state == TransactionState.READY, INVALID_REQUEST_STATE);
require(_accountBalances[_msgSender()] > 0 ether, INVALID_WITHDRAW_BALANCE);
Expand All @@ -298,16 +291,16 @@ contract WegaERC20Escrow is
uint256 feeAmount,
uint256 sendAmount
) = _feeManager.calculateFeesForTransfer(address(this), transferAmount);
IERC20Upgradeable(request.tokenAddress).transfer(
ERC20Upgradeable(request.tokenAddress).transfer(
_msgSender(),
sendAmount
);
IERC20Upgradeable(request.tokenAddress).transfer(
ERC20Upgradeable(request.tokenAddress).transfer(
feeTaker,
feeAmount
);
} else {
IERC20Upgradeable(request.tokenAddress).transfer(
ERC20Upgradeable(request.tokenAddress).transfer(
_msgSender(),
transferAmount
);
Expand Down
10 changes: 4 additions & 6 deletions contracts/games/Wega.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ pragma solidity ^0.8.19;
* oracle implementation for random numbers
* @dev note this is draft contract not meant to be used in production
*/
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableMapUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol";

import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

Expand All @@ -28,7 +27,7 @@ import "./IWega.sol";
abstract contract Wega is IWega, WegaProtocolAdminRole, UUPSUpgradeable {

using EnumerableMap for EnumerableMap.UintToUintMap;
using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet;
using EnumerableSet for EnumerableSet.AddressSet;
using Math for uint256;
using Arrays for uint256[];

Expand All @@ -37,8 +36,7 @@ abstract contract Wega is IWega, WegaProtocolAdminRole, UUPSUpgradeable {
// escrowHash -> address of the player -> results
mapping(bytes32 => mapping(address => uint256[])) private _gameResults;
mapping(bytes32 => mapping(address => uint256)) private _playerScores;
mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _winners;
CountersUpgradeable.Counter internal _nonces;
mapping(bytes32 => EnumerableSet.AddressSet) private _winners;
bytes32 public GAME_CONTROLLER_ROLE;


Expand Down
4 changes: 1 addition & 3 deletions contracts/games/WegaCoinFlipGame.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pragma solidity ^0.8.19;
* @notice a simple decentralized onchain coinflip game
* @dev note this is draft contract not meant to be used in production
*/
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableMapUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

Expand All @@ -19,8 +18,7 @@ import "./Wega.sol";
contract WegaCoinFlipGame is Wega {

using Arrays for uint256[];
using CountersUpgradeable for CountersUpgradeable.Counter;


function play(
bytes32 escrowHash,
address[] memory currentPlayers,
Expand Down
3 changes: 0 additions & 3 deletions contracts/games/WegaDiceGame.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ pragma solidity ^0.8.19;
* @notice a simple decentralized dice game
* @dev note this is draft contract not meant to be used in production
*/
import "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableMapUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";

import "../escrow/WegaERC20Escrow.sol";
Expand All @@ -20,7 +18,6 @@ import "./Wega.sol";
contract WegaDiceGame is Wega {

using Arrays for uint256[];
using CountersUpgradeable for CountersUpgradeable.Counter;

function play(
bytes32 escrowHash,
Expand Down
2 changes: 1 addition & 1 deletion contracts/roles/WegaEscrowManagerRole.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract contract WegaEscrowManagerRole is OwnableUpgradeable, AccessControlErr

// solhint-disable-next-line func-name-mixedcase
function __WegaEscrowManagerRole_init() internal onlyInitializing {
__Ownable_init(); // set the msgSender as owner
__Ownable_init(_msgSender()); // set the msgSender as owner
__AccessControl_init(); // also make the owner a controller ADMIN
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setRoleAdmin(WEGA_ESCROW_MANAGER_ROLE, DEFAULT_ADMIN_ROLE);
Expand Down
2 changes: 1 addition & 1 deletion contracts/roles/WegaFeeAdminRole.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract contract WegaFeeAdminRole is OwnableUpgradeable, AccessControlErrors,

// solhint-disable-next-line func-name-mixedcase
function __WegaFeeAdminRole_init() internal onlyInitializing {
__Ownable_init(); // set the msgSender as owner
__Ownable_init(_msgSender()); // set the msgSender as owner
__AccessControl_init(); // also make the owner a controller ADMIN
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setRoleAdmin(WEGA_FEE_MANAGER_ROLE, DEFAULT_ADMIN_ROLE);
Expand Down
2 changes: 1 addition & 1 deletion contracts/roles/WegaGameManagerRole.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract contract WegaGameManagerRole is OwnableUpgradeable, AccessControlError

// solhint-disable-next-line func-name-mixedcase
function __WegaGameManagerRole_init() internal onlyInitializing {
__Ownable_init(); // set the msgSender as owner
__Ownable_init(_msgSender()); // set the msgSender as owner
__AccessControl_init(); // also make the owner a controller ADMIN
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setRoleAdmin(WEGA_GAME_MANAGER_ROLE, DEFAULT_ADMIN_ROLE);
Expand Down
2 changes: 1 addition & 1 deletion contracts/roles/WegaProtocolAdminRole.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ abstract contract WegaProtocolAdminRole is OwnableUpgradeable, AccessControlErr

// solhint-disable-next-line func-name-mixedcase
function __WegaProtocolAdminRole_init() internal onlyInitializing {
__Ownable_init(); // set the msgSender as owner
__Ownable_init(_msgSender()); // set the msgSender as owner
__AccessControl_init(); // also make the owner a controller ADMIN
_grantRole(DEFAULT_ADMIN_ROLE, _msgSender());
_setRoleAdmin(WEGA_PROTOCOL_ADMIN_ROLE, DEFAULT_ADMIN_ROLE);
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// require("@nomicfoundation/hardhat-chai-matchers");
import '@openzeppelin/hardhat-upgrades';
import "@nomicfoundation/hardhat-toolbox";
import "@nomicfoundation/hardhat-chai-matchers";


import path from 'path';
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
"@ethereumjs/tx": "^4.0.2",
"@ethersproject/abi": "^5.7.0",
"@ethersproject/providers": "^5.7.2",
"@nomicfoundation/hardhat-chai-matchers": "1",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.2",
"@nomicfoundation/hardhat-ethers": "^3.0.5",
"@nomicfoundation/hardhat-network-helpers": "^1.0.9",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomiclabs/hardhat-ganache": "^2.0.1",
"@nomiclabs/hardhat-solhint": "^2.0.1",
"@openzeppelin/contracts": "^5.0.0",
"@openzeppelin/contracts-upgradeable": "^4.8.0",
"@openzeppelin/contracts-upgradeable": "^5.0.0",
"@openzeppelin/hardhat-upgrades": "^2.4.1",
"@openzeppelin/upgrades-core": "^1.20.5",
"@typechain/ethers-v6": "^0.5.1",
Expand All @@ -27,7 +27,7 @@
"@types/node": "^18.11.13",
"chai": "^4.3.10",
"dotenv": "^16.0.3",
"ethers": "6.6.2",
"ethers": "^6.8.1",
"hardhat": "^2.19.1",
"hardhat-abi-exporter": "^2.10.1",
"hardhat-contract-sizer": "^2.6.1",
Expand Down Expand Up @@ -68,7 +68,7 @@
"drand": "ts-node ./scripts/crawl-random-numbers.ts",
"gas-report": "env ENABLE_GAS_REPORT=true yarn test:sol",
"analyze": "slither . --hardhat-artifacts-directory ./.artifacts --sarif slither.sarif --config-file .slither.json",
"test": "hardhat test ./test/WegaGameController.test.ts ./test/WegaRandomNumberController.test.ts ./test/WegaERC20Escrow.test.ts ./test/WegaFeeManager.test.ts"
"test": "hardhat test ./test/WegaGameController.test.ts ./test/WegaRandomizerController.test.ts ./test/WegaERC20Escrow.test.ts ./test/WegaFeeManager.test.ts"
},
"dependencies": {
"@types/yargs": "^17.0.17",
Expand Down
Loading

0 comments on commit 35d0e6d

Please sign in to comment.