mirror of
https://github.com/0xShay/ticketchain.git
synced 2026-03-09 20:51:23 +00:00
3
.gitignore
vendored
3
.gitignore
vendored
@@ -34,3 +34,6 @@ yarn-error.log*
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
||||
artifacts
|
||||
typechain-types
|
||||
cache
|
||||
@@ -192,4 +192,4 @@ contract EventManager {
|
||||
transferTicketForce(_ticketId, _to);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
14
hardhat.config.ts
Normal file
14
hardhat.config.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { HardhatUserConfig } from 'hardhat/config';
|
||||
import '@nomiclabs/hardhat-waffle';
|
||||
import '@nomiclabs/hardhat-ethers';
|
||||
|
||||
const config: HardhatUserConfig = {
|
||||
solidity: '0.8.17',
|
||||
networks: {
|
||||
hardhat: {
|
||||
chainId: 1337,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
9825
package-lock.json
generated
9825
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
12
package.json
12
package.json
@@ -7,6 +7,8 @@
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"test": "npx hardhat --tsconfig tsconfig.hardhat.json test",
|
||||
"compile": "hardhat compile",
|
||||
"prepare": "husky"
|
||||
},
|
||||
"dependencies": {
|
||||
@@ -31,12 +33,22 @@
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@flarenetwork/flare-periphery-contracts": "^0.1.16",
|
||||
"@nomicfoundation/hardhat-toolbox": "^2.0.2",
|
||||
"@nomiclabs/hardhat-ethers": "^2.2.3",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.0",
|
||||
"@typechain/hardhat": "^6.1.6",
|
||||
"@types/mocha": "^10.0.9",
|
||||
"@types/ethereum-protocol": "^1.0.5",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"chai": "^4.2.0",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "14.2.13",
|
||||
"ethereum-waffle": "^4.0.10",
|
||||
"ethers": "^5.7.2",
|
||||
"hardhat": "^2.22.15",
|
||||
"husky": "^9.1.6",
|
||||
"lint-staged": "^15.2.10",
|
||||
"postcss": "^8",
|
||||
|
||||
1
remappings.txt
Normal file
1
remappings.txt
Normal file
@@ -0,0 +1 @@
|
||||
@flarenetwork/flare-periphery-contracts/=node_modules/@flarenetwork/flare-periphery-contracts/
|
||||
143
test/EventManager.test.ts
Normal file
143
test/EventManager.test.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import { expect } from 'chai';
|
||||
import { ethers } from 'hardhat';
|
||||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
|
||||
import { EventManager } from '../typechain-types/EventManager';
|
||||
|
||||
describe('EventManager', function () {
|
||||
let eventManager: EventManager;
|
||||
let owner: SignerWithAddress;
|
||||
let addr1: SignerWithAddress;
|
||||
let addr2: SignerWithAddress;
|
||||
|
||||
const EVENT_NAME = 'Test Event';
|
||||
const EVENT_DESCRIPTION = 'This is a test event';
|
||||
const EVENT_CAPACITY = 100;
|
||||
const EVENT_TICKET_PRICE = 1000; // 10 USD in cents
|
||||
const EVENT_DATE = Math.floor(Date.now() / 1000) + 86400; // 1 day from now
|
||||
const EVENT_IMAGES = ['image1.jpg', 'image2.jpg'];
|
||||
|
||||
beforeEach(async function () {
|
||||
[owner, addr1, addr2] = await ethers.getSigners();
|
||||
|
||||
const EventManager = await ethers.getContractFactory('EventManager');
|
||||
eventManager = await EventManager.deploy();
|
||||
await eventManager.deployed();
|
||||
});
|
||||
|
||||
async function createTestEvent() {
|
||||
await eventManager.createEvent(
|
||||
EVENT_NAME,
|
||||
EVENT_DESCRIPTION,
|
||||
EVENT_CAPACITY,
|
||||
EVENT_TICKET_PRICE,
|
||||
EVENT_DATE,
|
||||
EVENT_IMAGES
|
||||
);
|
||||
}
|
||||
|
||||
// describe("Event Creation", function () {
|
||||
// it("Should create an event with correct details", async function () {
|
||||
// await createTestEvent();
|
||||
|
||||
// const event = await eventManager.events(0);
|
||||
// expect(event.name).to.equal(EVENT_NAME);
|
||||
// expect(event.description).to.equal(EVENT_DESCRIPTION);
|
||||
// expect(event.capacity).to.equal(EVENT_CAPACITY);
|
||||
// expect(event.ticketPrice).to.equal(EVENT_TICKET_PRICE);
|
||||
// expect(event.eventDate).to.equal(EVENT_DATE);
|
||||
// expect(event.eventHost).to.equal(owner.address);
|
||||
// });
|
||||
|
||||
// it("Should emit EventCreated event", async function () {
|
||||
// await expect(await createTestEvent())
|
||||
// .to.emit(eventManager, "EventCreated")
|
||||
// .withArgs(0, EVENT_NAME, EVENT_DATE);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('Ticket Purchase', function () {
|
||||
beforeEach(async function () {
|
||||
await createTestEvent();
|
||||
});
|
||||
|
||||
it('Should allow buying a ticket', async function () {
|
||||
const ticketPriceFlare = await eventManager.getEventPriceFlare(0);
|
||||
await expect(
|
||||
eventManager.connect(addr1).buyTicket(0, { value: ticketPriceFlare })
|
||||
)
|
||||
.to.emit(eventManager, 'TicketPurchased')
|
||||
.withArgs(0, 0, addr1.address, ticketPriceFlare);
|
||||
|
||||
const ticket = await eventManager.tickets(0);
|
||||
expect(ticket.holder).to.equal(addr1.address);
|
||||
expect(ticket.eventId).to.equal(0);
|
||||
});
|
||||
|
||||
it('Should fail if insufficient funds are provided', async function () {
|
||||
const ticketPriceFlare = await eventManager.getEventPriceFlare(0);
|
||||
await expect(
|
||||
eventManager
|
||||
.connect(addr1)
|
||||
.buyTicket(0, { value: ticketPriceFlare.sub(1) })
|
||||
).to.be.revertedWith('Insufficient value provided');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ticket Transfer', function () {
|
||||
beforeEach(async function () {
|
||||
await createTestEvent();
|
||||
const ticketPriceFlare = await eventManager.getEventPriceFlare(0);
|
||||
await eventManager
|
||||
.connect(addr1)
|
||||
.buyTicket(0, { value: ticketPriceFlare });
|
||||
});
|
||||
|
||||
it('Should allow transferring a ticket', async function () {
|
||||
await expect(eventManager.connect(addr1).transferTicket(0, addr2.address))
|
||||
.to.emit(eventManager, 'TicketTransferred')
|
||||
.withArgs(0, addr1.address, addr2.address);
|
||||
|
||||
const ticket = await eventManager.tickets(0);
|
||||
expect(ticket.holder).to.equal(addr2.address);
|
||||
});
|
||||
|
||||
it('Should fail if non-owner tries to transfer', async function () {
|
||||
await expect(
|
||||
eventManager.connect(addr2).transferTicket(0, addr2.address)
|
||||
).to.be.revertedWith('You do not own this ticket');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Ticket Approval and Transfer', function () {
|
||||
beforeEach(async function () {
|
||||
await createTestEvent();
|
||||
const ticketPriceFlare = await eventManager.getEventPriceFlare(0);
|
||||
await eventManager
|
||||
.connect(addr1)
|
||||
.buyTicket(0, { value: ticketPriceFlare });
|
||||
});
|
||||
|
||||
it('Should allow approving and transferring a ticket', async function () {
|
||||
await expect(
|
||||
eventManager.connect(addr1).approveTicket(0, addr2.address, true)
|
||||
)
|
||||
.to.emit(eventManager, 'TicketTransferApproved')
|
||||
.withArgs(0, addr1.address, addr2.address);
|
||||
|
||||
await expect(
|
||||
eventManager.connect(addr2).transferTicketFrom(0, addr2.address)
|
||||
)
|
||||
.to.emit(eventManager, 'TicketTransferred')
|
||||
.withArgs(0, addr1.address, addr2.address);
|
||||
|
||||
const ticket = await eventManager.tickets(0);
|
||||
expect(ticket.holder).to.equal(addr2.address);
|
||||
});
|
||||
|
||||
it('Should fail if transferring without approval', async function () {
|
||||
await expect(
|
||||
eventManager.connect(addr2).transferTicketFrom(0, addr2.address)
|
||||
).to.be.revertedWith('You are not allowed to transfer this ticket');
|
||||
});
|
||||
});
|
||||
});
|
||||
13
tsconfig.hardhat.json
Normal file
13
tsconfig.hardhat.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "commonjs",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "./",
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": ["./scripts", "./test", "./typechain-types"],
|
||||
"files": ["./hardhat.config.ts"]
|
||||
}
|
||||
@@ -22,5 +22,5 @@
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
"exclude": ["node_modules", "test", "scripts", "hardhat.config.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user