Skip to content

Commit

Permalink
Added tests for expected flow
Browse files Browse the repository at this point in the history
  • Loading branch information
luloxi committed Oct 10, 2023
1 parent e7c9437 commit a20209a
Show file tree
Hide file tree
Showing 151 changed files with 85 additions and 14 deletions.
Empty file modified .github/ISSUE_TEMPLATE/bug_report.yml
100644 → 100755
Empty file.
Empty file modified .github/ISSUE_TEMPLATE/config.yml
100644 → 100755
Empty file.
Empty file modified .github/pull_request_template.md
100644 → 100755
Empty file.
Empty file modified .github/workflows/lint.yaml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .lintstagedrc.js
100644 → 100755
Empty file.
Empty file modified .yarn/patches/usehooks-ts-npm-2.7.2-fceffe0e43.patch
100644 → 100755
Empty file.
Empty file modified .yarn/plugins/@yarnpkg/plugin-typescript.cjs
100644 → 100755
Empty file.
Empty file modified .yarnrc.yml
100644 → 100755
Empty file.
Empty file modified CONTRIBUTING.md
100644 → 100755
Empty file.
Empty file modified LICENCE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified migration/DOCUMENTATION.md
100644 → 100755
Empty file.
Empty file modified migration/concept/acceptdecline.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified migration/concept/history.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified migration/concept/ideas/Sportsbook (7).png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified migration/concept/ideas/Sportsbook (8).png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified migration/concept/landing.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified migration/concept/login.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified migration/concept/newchallenge.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified migration/concept/social.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified migration/v2-contracts/LoseNft.sol
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/NFTdata/LostNft.json
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/NFTdata/TieNft.json
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/NFTdata/WinNft.json
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/SportsChallenge.sol
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/TieNft.sol
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/WinNft.sol
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/deploy/01_deploy_lose-nft.js
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/deploy/01_deploy_tie-nft.js
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/deploy/01_deploy_win-nft copy.js
100644 → 100755
Empty file.
Empty file modified migration/v2-contracts/deploy/02_deploy_sportsbook.js
100644 → 100755
Empty file.
Empty file modified package.json
100644 → 100755
Empty file.
Empty file modified packages/hardhat/.env.example
100644 → 100755
Empty file.
Empty file modified packages/hardhat/.eslintignore
100644 → 100755
Empty file.
Empty file modified packages/hardhat/.eslintrc.json
100644 → 100755
Empty file.
Empty file modified packages/hardhat/.gitignore
100644 → 100755
Empty file.
Empty file modified packages/hardhat/.prettierrc.json
100644 → 100755
Empty file.
Empty file modified packages/hardhat/contracts/Sportsbook.sol
100644 → 100755
Empty file.
Empty file modified packages/hardhat/deploy/00_deploy_sportsbook.ts
100644 → 100755
Empty file.
Empty file modified packages/hardhat/deploy/99_generateTsAbis.ts
100644 → 100755
Empty file.
Empty file modified packages/hardhat/hardhat.config.ts
100644 → 100755
Empty file.
Empty file modified packages/hardhat/package.json
100644 → 100755
Empty file.
Empty file modified packages/hardhat/scripts/generateAccount.ts
100644 → 100755
Empty file.
Empty file modified packages/hardhat/scripts/listAccount.ts
100644 → 100755
Empty file.
97 changes: 84 additions & 13 deletions packages/hardhat/test/Sportsbook.t.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,109 @@ describe("Sportsbook", function () {
let team1: any;
let team2: any;
let referee: any;
let newReferee: any;

const BET_AMOUNT = ethers.utils.parseEther("1");

before(async () => {
[/*owner,*/ team1, team2, referee] = await ethers.getSigners();
[/*owner,*/ team1, team2, referee, newReferee] = await ethers.getSigners();
const sportsbookFactory = await ethers.getContractFactory("Sportsbook");
sportsbook = (await sportsbookFactory.deploy()) as Sportsbook;
await sportsbook.deployed();
});

describe("Basic usage", function () {
it("Creates a new challenge", async function () {
await sportsbook.createChallenge(team2.address, referee.address, { value: ethers.utils.parseEther("1") });
describe("Expected flow", function () {
const challengeId = 0;

it("0. createChallenge: Creates a new match challenge with the correct parameters", async function () {
await sportsbook.connect(team1).createChallenge(team2.address, referee.address, { value: BET_AMOUNT });
expect(await sportsbook.viewMatchCount()).to.equal(1);
const challenge = await sportsbook.viewMatchChallenge(0);
expect(challenge.team1).to.equal(team1.address);
expect(challenge.team2).to.equal(team2.address);
expect(challenge.state).to.equal(0);
expect(challenge.referee).to.equal(referee.address);
expect(challenge.bet).to.equal(BET_AMOUNT);
});

it("Allows accepting a new challenge", async function () {
const challengeId = 0;
await sportsbook.createChallenge(team2.address, referee.address, { value: ethers.utils.parseEther("1") });
it("1. acceptChallenge: Only allows team2 to accept a new match", async function () {
await expect(
sportsbook.connect(team1).acceptChallenge(challengeId, { value: ethers.utils.parseEther("1") }),
).to.be.revertedWith("You're not the challenged team!");
await sportsbook.connect(team2).acceptChallenge(challengeId, { value: ethers.utils.parseEther("1") });
expect(await sportsbook.viewMatchState(challengeId)).to.equal(1);
});

it("Allows proposing and accepting referee update", async function () {
const challengeId = 0;
await sportsbook.createChallenge(team2.address, referee.address, { value: ethers.utils.parseEther("1") });

it("1. updateReferee: Allows proposing and accepting referee update", async function () {
// Propose referee update
await sportsbook.updateReferee(challengeId, team1.address);
await sportsbook.connect(team1).updateReferee(challengeId, newReferee.address);
expect(await sportsbook.viewUpdateRefereeState(challengeId)).to.equal(1);

// Accept referee update
await sportsbook.connect(team2).answerUpdateReferee(challengeId, true);
expect(await sportsbook.viewMatchReferee(challengeId)).to.equal(team1.address);
expect(await sportsbook.viewMatchReferee(challengeId)).to.equal(newReferee.address);
});

it("2. startChallenge: Only allows the referee to start the match", async function () {
await expect(sportsbook.connect(team2).startChallenge(challengeId)).to.be.revertedWith("You're not the referee!");
await sportsbook.connect(newReferee).startChallenge(challengeId);
});
it("2. updateReferee: Doesn't allow changing referee after the match has started", async function () {
await expect(sportsbook.connect(team1).updateReferee(challengeId, newReferee.address)).to.be.revertedWith(
"Challenge has already been started!",
);
});
it("2. withdrawPrize: Doesn't allow withdrawing the prize before the match has ended", async function () {
await expect(sportsbook.connect(team1).withdrawPrize(challengeId)).to.be.revertedWith(
"Challenge has not been completed yet.",
);
});
it("3. completeChallenge: Only allows the referee to set the score of the match", async function () {
await expect(sportsbook.connect(team2).completeChallenge(challengeId, 1, 0)).to.be.revertedWith(
"You must be the referee to say who won",
);
await sportsbook.connect(newReferee).completeChallenge(challengeId, 1, 0);
});
it("3. completeChallenge: Doesn't allow changing the score after the match has ended", async function () {
await expect(sportsbook.connect(newReferee).completeChallenge(challengeId, 2, 0)).to.be.revertedWith(
"Challenge hasn't started!",
);
});
it("4. withdrawPrize: Only allows the winner to withdraw the prize", async function () {
const originalTeam1Balance = await ethers.provider.getBalance(team1.address);
await expect(sportsbook.connect(team2).withdrawPrize(challengeId)).to.be.revertedWith(
"You are not the winning team.",
);
await sportsbook.connect(team1).withdrawPrize(challengeId);
const newTeam1Balance = await ethers.provider.getBalance(team1.address);
expect(newTeam1Balance.sub(ethers.utils.parseEther("0.1"))).to.be.gt(originalTeam1Balance);
});
xit("4. withdrawPrize: Doesn't allow withdrawing the prize twice", async function () {
// For some reason this is reverting with the reason "Transfer failed" instead of the expected error message, should investigate further
await expect(sportsbook.connect(team1).withdrawPrize(challengeId)).to.be.revertedWith(
"You have already withdrawn your share.",
);
});
});
describe("Edge cases", function () {
it("withdrawPrize: Should split the prize in half in case of a tie", async function () {
const challengeId = 1;
await sportsbook.connect(team1).createChallenge(team2.address, referee.address, { value: BET_AMOUNT });
await sportsbook.connect(team2).acceptChallenge(challengeId, { value: BET_AMOUNT });
await sportsbook.connect(referee).startChallenge(challengeId);
await sportsbook.connect(referee).completeChallenge(challengeId, 1, 1);

const originalTeam1Balance = await ethers.provider.getBalance(team1.address);
const originalTeam2Balance = await ethers.provider.getBalance(team2.address);

await sportsbook.connect(team1).withdrawPrize(challengeId);
await sportsbook.connect(team2).withdrawPrize(challengeId);

const newTeam1Balance = await ethers.provider.getBalance(team1.address);
const newTeam2Balance = await ethers.provider.getBalance(team2.address);
// This check should be more accurate, but I'm lazy to calculate gas costs properly
expect(newTeam1Balance.sub(ethers.utils.parseEther("0.1"))).to.be.gt(originalTeam1Balance);
expect(newTeam2Balance.sub(ethers.utils.parseEther("0.1"))).to.be.gt(originalTeam2Balance);
});
});
});
Empty file modified packages/hardhat/tsconfig.json
100644 → 100755
Empty file.
Empty file modified packages/nextjs/.eslintignore
100644 → 100755
Empty file.
Empty file modified packages/nextjs/.eslintrc.json
100644 → 100755
Empty file.
Empty file modified packages/nextjs/.gitignore
100644 → 100755
Empty file.
Empty file modified packages/nextjs/.npmrc
100644 → 100755
Empty file.
Empty file modified packages/nextjs/.prettierrc.json
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/Footer.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/Header.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/MetaHeader.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/Spinner.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/SwitchTheme.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/blockexplorer/AddressCodeTab.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/blockexplorer/AddressLogsTab.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/blockexplorer/AddressStorageTab.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/blockexplorer/PaginationButton.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/blockexplorer/SearchBar.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/blockexplorer/TransactionHash.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/blockexplorer/TransactionsTable.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/blockexplorer/index.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Address.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Balance.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/BlockieAvatar.tsx
100644 → 100755
Empty file.
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Contract/ContractUI.tsx
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Contract/TxReceipt.tsx
100644 → 100755
Empty file.
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Contract/index.tsx
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Faucet.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/FaucetButton.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Input/AddressInput.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Input/Bytes32Input.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Input/BytesInput.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Input/EtherInput.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Input/InputBase.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Input/IntegerInput.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Input/index.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/Input/utils.ts
100644 → 100755
Empty file.
Empty file.
Empty file modified packages/nextjs/components/scaffold-eth/index.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/generated/deployedContracts.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/index.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useAccountBalance.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useAnimationConfig.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useAutoConnect.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useBurnerWallet.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useContractLogs.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useDeployedContractInfo.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useFetchBlocks.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useNativeCurrencyPrice.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useNetworkColor.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useOutsideClick.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useScaffoldContract.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useScaffoldContractRead.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useScaffoldContractWrite.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useScaffoldEventHistory.ts
100644 → 100755
Empty file.
Empty file.
Empty file modified packages/nextjs/hooks/scaffold-eth/useTransactor.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/next-env.d.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/next.config.js
100644 → 100755
Empty file.
Empty file modified packages/nextjs/package.json
100644 → 100755
Empty file.
Empty file modified packages/nextjs/pages/_app.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/pages/blockexplorer/address/[address].tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/pages/blockexplorer/index.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/pages/blockexplorer/transaction/[txHash].tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/pages/debug.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/pages/index.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/pages/sportsbook/ChallengeCard.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/pages/sportsbook/CreateChallengeBox.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/postcss.config.js
100644 → 100755
Empty file.
Empty file modified packages/nextjs/public/assets/gradient-bg.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified packages/nextjs/public/assets/switch-button-off.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified packages/nextjs/public/assets/switch-button-on.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified packages/nextjs/public/background.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified packages/nextjs/public/favicon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified packages/nextjs/public/logo.svg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified packages/nextjs/public/thumbnail.jpg
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified packages/nextjs/scaffold.config.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/services/store/store.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/services/web3/wagmi-burner/BurnerConnector.ts
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion packages/nextjs/services/web3/wagmi-burner/BurnerConnectorErrors.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const BurnerConnectorErrorList = {
/**
* A union of all the BurnerConnectorErrorList
*/
export type BurnerConnectorErrorTypes = typeof BurnerConnectorErrorList[keyof typeof BurnerConnectorErrorList];
export type BurnerConnectorErrorTypes = (typeof BurnerConnectorErrorList)[keyof typeof BurnerConnectorErrorList];

export class BurnerConnectorError extends Error {
constructor(errorType: BurnerConnectorErrorTypes, message?: string) {
Expand Down
Empty file.
Empty file.
Empty file modified packages/nextjs/services/web3/wagmiClient.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/services/web3/wagmiConnectors.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/styles/Fancy.css
100644 → 100755
Empty file.
Empty file modified packages/nextjs/styles/globals.css
100644 → 100755
Empty file.
Empty file modified packages/nextjs/tailwind.config.js
100644 → 100755
Empty file.
Empty file modified packages/nextjs/tsconfig.json
100644 → 100755
Empty file.
Empty file modified packages/nextjs/types/SportsbookTypes.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/types/abitype/abi.d.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/block.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/contract.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/contractNames.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/decodeTxData.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/fetchPriceFromUniswap.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/getLocalProvider.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/index.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/networks.ts
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/notification.tsx
100644 → 100755
Empty file.
Empty file modified packages/nextjs/utils/scaffold-eth/parseTxnValue.ts
100644 → 100755
Empty file.
Empty file modified yarn.lock
100644 → 100755
Empty file.

0 comments on commit a20209a

Please sign in to comment.