Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"format:check": "npm run format:check:js && npm run format:check:rust",
"format:check:js": "prettier --check .",
"format:check:rust": "cargo fmt --manifest-path soroban-contract/Cargo.toml --all --check",
"test": "npm run test --prefix soroban-client && cargo test --manifest-path soroban-contract/Cargo.toml --all-targets --all-features"
"test": "npm run test --prefix soroban-client && npm run test:rust-contracts",
"test:rust-contracts": "npm run test:rust-contracts:build && cargo test --manifest-path soroban-contract/Cargo.toml --workspace --exclude integration_tests --lib",
"test:rust-contracts:build": "cargo build --release --manifest-path soroban-contract/Cargo.toml --target wasm32-unknown-unknown",
"test:rust:full": "npm run test:rust-contracts:build && cargo test --manifest-path soroban-contract/Cargo.toml --workspace --all-targets --all-features"
},
"devDependencies": {
"husky": "^9.1.7",
Expand Down
345 changes: 236 additions & 109 deletions soroban-client/app/verifier/page.tsx

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions soroban-client/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import type { Config } from 'jest';
import nextJest from 'next/jest.js';
import type { Config } from "jest";
import nextJest from "next/jest.js";

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
dir: "./",
});

// Add any custom config to be passed to Jest
const config: Config = {
coverageProvider: 'v8',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
coverageProvider: "v8",
testEnvironment: "jsdom",
setupFiles: ["<rootDir>/jest.polyfills.ts"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
collectCoverage: false,
coverageDirectory: '<rootDir>/coverage',
coverageReporters: ['text-summary', 'lcov', 'json-summary'],
coverageDirectory: "<rootDir>/coverage",
coverageReporters: ["text-summary", "lcov", "json-summary"],
coverageThreshold: {
global: {
branches: 70,
Expand All @@ -24,7 +25,8 @@ const config: Config = {
},
moduleNameMapper: {
// Handle module aliases
'^@/(.*)$': '<rootDir>/$1',
"^@/(.*)$": "<rootDir>/$1",
"^next-intl$": "<rootDir>/test/mocks/next-intl.ts",
},
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
Expand Down
10 changes: 10 additions & 0 deletions soroban-client/jest.polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Runs before Jest loads test modules (via `setupFiles`).
* Stellar SDK expects Web APIs that are not always present during early module init in jsdom.
*/
import { TextDecoder, TextEncoder } from "node:util";

Object.assign(globalThis, {
TextEncoder,
TextDecoder,
});
51 changes: 51 additions & 0 deletions soroban-client/lib/soroban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,57 @@ export async function createEvent(
return await server.submitTransaction(signedTx as any);
}

export interface CheckInTicketParams {
/** Wallet signing the tx; must be event organizer or on-chain staff. */
scanner: string;
eventId: number;
tokenId: bigint;
}

export async function checkInTicket(
params: CheckInTicketParams,
signTransactionFn: SignTransactionFn
) {
if (!isEventManagerConfigured()) {
throw new Error(
"EVENT_MANAGER_CONTRACT is not configured. Set NEXT_PUBLIC_EVENT_MANAGER_CONTRACT in your env."
);
}

const server = new Server(HORIZON_URL);
const sourceAccount = await server.loadAccount(params.scanner);
const fee = await server.fetchBaseFee();

const args = [
nativeToScVal(params.scanner, { type: "address" }),
nativeToScVal(params.eventId, { type: "u32" }),
nativeToScVal(params.tokenId, { type: "u128" }),
];

const operation = Operation.invokeContractFunction({
contract: EVENT_MANAGER_CONTRACT,
function: "check_in",
args,
});

const tx = new TransactionBuilder(sourceAccount, {
fee: fee.toString(),
networkPassphrase: NETWORK_PASSPHRASE,
})
.addOperation(operation)
.setTimeout(30)
.build();

const txXdr = tx.toXDR();
const signedTxXdr = await signTransactionFn(txXdr, {
networkPassphrase: NETWORK_PASSPHRASE,
address: params.scanner,
});

const signedTx = TransactionBuilder.fromXDR(signedTxXdr, NETWORK_PASSPHRASE);
return await server.submitTransaction(signedTx as any);
}

export async function buyTickets(
params: BuyTicketsParams,
signTransactionFn: SignTransactionFn
Expand Down
42 changes: 23 additions & 19 deletions soroban-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions soroban-client/sdk/src/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,55 @@ export class EventManagerContract extends BaseContract {
return normalizePurchase(raw);
}

checkIn(caller: string, eventId: number, tokenId: bigint, options: WriteInvokeOptions) {
return this.write(
"check_in",
[
nativeToScVal(caller, { type: "address" }),
nativeToScVal(eventId, { type: "u32" }),
nativeToScVal(tokenId, { type: "u128" }),
],
options
);
}

addEventStaff(eventId: number, staff: string, options: WriteInvokeOptions) {
return this.write(
"add_event_staff",
[nativeToScVal(eventId, { type: "u32" }), nativeToScVal(staff, { type: "address" })],
options
);
}

removeEventStaff(eventId: number, staff: string, options: WriteInvokeOptions) {
return this.write(
"remove_event_staff",
[nativeToScVal(eventId, { type: "u32" }), nativeToScVal(staff, { type: "address" })],
options
);
}

async getEventStaff(eventId: number, options?: InvokeOptions): Promise<string[]> {
return this.read<string[]>(
"get_event_staff",
[nativeToScVal(eventId, { type: "u32" })],
options
);
}

async getCheckInTimestamp(
eventId: number,
tokenId: bigint,
options?: InvokeOptions
): Promise<number> {
const raw = await this.read<number>(
"get_check_in_timestamp",
[nativeToScVal(eventId, { type: "u32" }), nativeToScVal(tokenId, { type: "u128" })],
options
);
return Number(raw);
}

cancelEvent(eventId: number, options: WriteInvokeOptions) {
return this.write("cancel_event", [nativeToScVal(eventId, { type: "u32" })], options);
}
Expand Down
Loading
Loading