Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JCSanPedro committed Jun 30, 2024
1 parent 4f9ddac commit bf00ab0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
6 changes: 2 additions & 4 deletions contracts/payments/Ticketing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@ contract Ticketing is ITicketing, Initializable, Ownable2StepUpgradeable, ERC165
error TicketAlreadyRedeemed();
error RedeemerCommitMismatch();
error InvalidSignature();
error TokenCannotBeZeroAddress();
error TicketNotCreatedInTheEpoch();
error TokenAddressCannotBeNil();
error TicketCannotBeFromFutureBlock();
error TicketSenderCannotBeZeroAddress();
error TicketReceiverCannotBeZeroAddress();
error TicketRedeemerCannotBeZeroAddress();
error RedeemerMustHaveJoinedEpoch(uint256 cycle);

function initialize(
IERC20 token,
Expand All @@ -152,7 +150,7 @@ contract Ticketing is ITicketing, Initializable, Ownable2StepUpgradeable, ERC165
uint256 _ticketDuration
) external initializer {
if (address(token) == address(0)) {
revert TokenCannotBeZeroAddress();
revert TokenAddressCannotBeNil();
}

Ownable2StepUpgradeable.__Ownable2Step_init();
Expand Down
3 changes: 1 addition & 2 deletions test/paymets/deposits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { deployContracts, getBlockNumber, MAX, MAX_SYLO } from '../utils';
import { Signer } from 'ethers';
import { expect, assert } from 'chai';
import { Deposits } from '../../typechain-types';
import { increase } from '@nomicfoundation/hardhat-network-helpers/dist/src/helpers/time';

describe.only('Deposits', () => {
describe('Deposits', () => {
let accounts: Signer[];
let contracts: SyloContracts;
let deposits: Deposits;
Expand Down
89 changes: 87 additions & 2 deletions test/paymets/ticketing.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ethers } from 'hardhat';
import { SyloContracts } from '../../common/contracts';
import { deployContracts } from '../utils';
import { Signer } from 'ethers';
import { ContractTransactionResponse, Signer } from 'ethers';
import { expect, assert } from 'chai';
import { Deposits, Ticketing } from '../../typechain-types';

describe('Ticketing', () => {
describe.only('Ticketing', () => {
let accounts: Signer[];
let contracts: SyloContracts;
let deposits: Deposits;
Expand All @@ -16,5 +16,90 @@ describe('Ticketing', () => {
contracts = await deployContracts();
deposits = contracts.deposits;
ticketing = contracts.ticketing;

await deposits.approveTicketing(ticketing.getAddress());
});

it('cannot initialize deposits with invalid arguments', async () => {
const factory = await ethers.getContractFactory('Ticketing');
const ticketing = await factory.deploy();

await expect(
ticketing.initialize(
ethers.ZeroAddress,
ethers.ZeroAddress,
ethers.ZeroAddress,
ethers.ZeroAddress,
ethers.ZeroAddress,
ethers.ZeroAddress,
100n,
1n,
1n,
1n,
1n,
1n,
),
).to.be.revertedWithCustomError(deposits, 'TokenAddressCannotBeNil');
});

it('can set ticketing parameters', async () => {
const updateParam = async <P>(
setter: (p: P) => Promise<ContractTransactionResponse>,
getter: () => Promise<P>,
value: P,
event: string,
) => {
await expect(setter(value)).to.emit(ticketing, event);
await expect(await getter()).to.equal(value);

// confirm setter can only called by owner
// const nonOwnerCall = ticketing.connect(accounts[1]).
};

await updateParam(
ticketing.setFaceValue,
ticketing.faceValue,
111n,
'FaceValueUpdated',
);

await updateParam(
ticketing.setMultiReceiverFaceValue,
ticketing.multiReceiverFaceValue,
222n,
'MultiReceiverFaceValueUpdated',
);

await updateParam(
ticketing.setBaseLiveWinProb,
ticketing.baseLiveWinProb,
333n,
'BaseLiveWinProbUpdated',
);

await updateParam(
ticketing.setExpiredWinProb,
ticketing.expiredWinProb,
444n,
'ExpiredWinProbUpdated',
);

await updateParam(
ticketing.setDecayRate,
ticketing.decayRate,
555n,
'DecayRateUpdated',
);

await updateParam(
ticketing.setTicketDuration,
ticketing.ticketDuration,
666n,
'TicketDurationUpdated',
);
});

it('cannot set invalid ticketing parameters', async () => {});

it('cannot set ticketing parameters as non-owner', async () => {});
});

0 comments on commit bf00ab0

Please sign in to comment.