Skip to content

Improve testing workflow #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
582a191
move contracts, compact to packages, add compact-std, add testing
andrew-fleming Jul 13, 2025
84f77fe
remove duplicate method
andrew-fleming Jul 13, 2025
bd2642b
fix comments
andrew-fleming Jul 13, 2025
bbf0f33
remove newline between imports
andrew-fleming Jul 13, 2025
3707320
improve spacing in tests
andrew-fleming Jul 13, 2025
6432d04
normalize deps
andrew-fleming Jul 13, 2025
bfb64d5
add line
andrew-fleming Jul 13, 2025
d96a31c
remove json
andrew-fleming Jul 13, 2025
0c38801
move archive/, fix conflicts
andrew-fleming Jul 14, 2025
3d3d376
Apply suggestions from code review
andrew-fleming Jul 19, 2025
d50c069
remove 'current' from state getters
andrew-fleming Jul 19, 2025
6bd2e04
Apply suggestions from code review
andrew-fleming Jul 19, 2025
fa86d82
Merge branch 'try-testing-package' of https://github.com/OpenZeppelin…
andrew-fleming Jul 19, 2025
dbf005a
fix fmt
andrew-fleming Jul 20, 2025
c73468b
add missing type
andrew-fleming Jul 20, 2025
97f4c7a
export extract types
andrew-fleming Jul 20, 2025
f8198ce
use extract types
andrew-fleming Jul 20, 2025
266a060
move contracts back to root
andrew-fleming Jul 21, 2025
572ed25
move types to types file, tidy up
andrew-fleming Jul 21, 2025
abe5fc8
improve ContextlessCircuits doc comments
andrew-fleming Jul 21, 2025
05be29d
Merge branch 'main' into try-testing-package
andrew-fleming Jul 21, 2025
4d1987e
update yarn.lock
andrew-fleming Jul 21, 2025
fa7f52d
fix import paths
andrew-fleming Jul 21, 2025
1902e6d
fix conflicts
andrew-fleming Jul 23, 2025
11fa102
Merge branch 'main' into try-testing-package
andrew-fleming Jul 23, 2025
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
26 changes: 0 additions & 26 deletions contracts/utils/src/test/types/test.ts

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"private": true,
"packageManager": "[email protected]",
"workspaces": [
"compact/",
"contracts/*/",
"docs/"
"docs/",
"packages/*",
"packages/contracts/*"
],
"scripts": {
"docs": "npx turbo run docs --filter=docs",
Expand Down
31 changes: 31 additions & 0 deletions packages/compact-std/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "@openzeppelin-compact/compact-std",
"private": true,
"version": "0.0.1",
"description": "",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"compact": "compact-compiler",
"build": "compact-builder && tsc",
"test": "vitest run",
"types": "tsc -p tsconfig.json --noEmit",
"clean": "git clean -fXd"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "22.14.0",
"fast-check": "^3.15.0",
"typescript": "^5.8.3",
"vitest": "^3.1.4"
},
"dependencies": {
"@midnight-ntwrk/compact-runtime": "^0.8.1",
"@midnight-ntwrk/midnight-js-network-id": "^2.0.1",
"@midnight-ntwrk/zswap": "^4.0.0",
"@openzeppelin-compact/compact": "workspace:^"
}
}
20 changes: 20 additions & 0 deletions packages/compact-std/src/Index.compact
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma language_version >= 0.14.0;

import CompactStandardLibrary;

/**
* @description Standard structs from CompactStandardLibrary for use in contracts and TypeScript.
*/
export {
Maybe, // Encapsulates an optionally present value
Either, // Disjoint union of two types
CurvePoint, // Point on the proof system's embedded curve
MerkleTreeDigest, // Root hash of a Merkle tree
MerkleTreePathEntry,// Entry in a Merkle tree path
MerkleTreePath, // Path in a Merkle tree leading to a leaf
ContractAddress, // Address of a contract
CoinInfo, // Description of a newly created coin
QualifiedCoinInfo, // Description of an existing coin in the ledger
ZswapCoinPublicKey, // Public key for coin outputs
SendResult // Result of send/send_immediate operations
};
129 changes: 129 additions & 0 deletions packages/compact-std/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import { describe, expectTypeOf, it } from 'vitest';
import type {
CoinInfo,
ContractAddress,
CurvePoint,
Either,
Maybe,
MerkleTreeDigest,
MerkleTreePath,
MerkleTreePathEntry,
QualifiedCoinInfo,
SendResult,
ZswapCoinPublicKey,
} from './index';

describe('@midnight-dapps/compact-std', () => {
it('should export Maybe type correctly', () => {
const maybeNumber: Maybe<number> = { is_some: true, value: 42 };
expectTypeOf(maybeNumber).toEqualTypeOf<{
is_some: boolean;
value: number;
}>();
});

it('should export Either type correctly', () => {
const eitherStringNumber: Either<string, number> = {
is_left: true,
left: 'test',
right: 0,
};
expectTypeOf(eitherStringNumber).toEqualTypeOf<{
is_left: boolean;
left: string;
right: number;
}>();
});

it('should export CurvePoint type correctly', () => {
const curvePoint: CurvePoint = { x: BigInt(1), y: BigInt(2) };
expectTypeOf(curvePoint).toEqualTypeOf<{ x: bigint; y: bigint }>();
});

it('should export MerkleTreeDigest type correctly', () => {
const digest: MerkleTreeDigest = { field: BigInt(123) };
expectTypeOf(digest).toEqualTypeOf<{ field: bigint }>();
});

it('should export MerkleTreePathEntry type correctly', () => {
const entry: MerkleTreePathEntry = {
sibling: { field: BigInt(456) },
goes_left: false,
};
expectTypeOf(entry).toEqualTypeOf<{
sibling: { field: bigint };
goes_left: boolean;
}>();
});

it('should export MerkleTreePath type correctly', () => {
const path: MerkleTreePath<Uint8Array> = {
leaf: new Uint8Array([1, 2, 3]),
path: [{ sibling: { field: BigInt(789) }, goes_left: true }],
};
expectTypeOf(path).toEqualTypeOf<{
leaf: Uint8Array;
path: { sibling: { field: bigint }; goes_left: boolean }[];
}>();
});

it('should export ContractAddress type correctly', () => {
const address: ContractAddress = { bytes: new Uint8Array(32) };
expectTypeOf(address).toEqualTypeOf<{ bytes: Uint8Array }>();
});

it('should export CoinInfo type correctly', () => {
const coin: CoinInfo = {
nonce: new Uint8Array(32),
color: new Uint8Array(32),
value: BigInt(100),
};
expectTypeOf(coin).toEqualTypeOf<{
nonce: Uint8Array;
color: Uint8Array;
value: bigint;
}>();
});

it('should export QualifiedCoinInfo type correctly', () => {
const qualifiedCoin: QualifiedCoinInfo = {
nonce: new Uint8Array(32),
color: new Uint8Array(32),
value: BigInt(200),
mt_index: BigInt(1),
};
expectTypeOf(qualifiedCoin).toEqualTypeOf<{
nonce: Uint8Array;
color: Uint8Array;
value: bigint;
mt_index: bigint;
}>();
});

it('should export ZswapCoinPublicKey type correctly', () => {
const pubKey: ZswapCoinPublicKey = { bytes: new Uint8Array(32) };
expectTypeOf(pubKey).toEqualTypeOf<{ bytes: Uint8Array }>();
});

it('should export SendResult type correctly', () => {
const result: SendResult = {
change: {
is_some: false,
value: {
nonce: new Uint8Array(32),
color: new Uint8Array(32),
value: BigInt(0),
},
},
sent: {
nonce: new Uint8Array(32),
color: new Uint8Array(32),
value: BigInt(50),
},
};
expectTypeOf(result).toEqualTypeOf<{
change: Maybe<CoinInfo>;
sent: CoinInfo;
}>();
});
});
18 changes: 18 additions & 0 deletions packages/compact-std/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* @module @midnight-dapps/compact-stdlib
* @description Re-exports custom structs from CompactStandardLibrary for use in TypeScript code.
* Excludes standard runtime types from @midnight-ntwrk/compact-runtime.
*/
export type {
Maybe,
Either,
CurvePoint,
MerkleTreeDigest,
MerkleTreePathEntry,
MerkleTreePath,
ContractAddress,
CoinInfo,
QualifiedCoinInfo,
ZswapCoinPublicKey,
SendResult,
} from './artifacts/Index/contract/index.cjs';
7 changes: 7 additions & 0 deletions packages/compact-std/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"exclude": [
"src/test/**/*.ts"
],
"compilerOptions": {}
}
16 changes: 16 additions & 0 deletions packages/compact-std/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"outDir": "dist",
"rootDir": "src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node",
"declaration": true,
"sourceMap": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "src/artifacts"]
}
10 changes: 10 additions & 0 deletions packages/compact-std/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
environment: 'node',
globals: true,
include: ['**/*.test.ts'],
hookTimeout: 100000,
},
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pragma language_version >= 0.15.0;
*/
module ShieldedToken { // DO NOT USE IN PRODUCTION!
import CompactStandardLibrary;
import "../../node_modules/@openzeppelin-compact/utils/src/Utils" prefix Utils_;
import "../../../node_modules/@openzeppelin-compact/utils/src/Utils" prefix Utils_;

// Public state
export ledger _counter: Counter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pragma language_version >= 0.15.0;
*/
module FungibleToken {
import CompactStandardLibrary;
import "../../node_modules/@openzeppelin-compact/utils/src/Initializable" prefix Initializable_;
import "../../node_modules/@openzeppelin-compact/utils/src/Utils" prefix Utils_;
import "../../../node_modules/@openzeppelin-compact/utils/src/Initializable" prefix Initializable_;
import "../../../node_modules/@openzeppelin-compact/utils/src/Utils" prefix Utils_;

/**
* @description Mapping from account addresses to their token balances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ pragma language_version >= 0.15.0;
*/
module MultiToken {
import CompactStandardLibrary;
import "../../node_modules/@openzeppelin-compact/utils/src/Utils" prefix Utils_;
import "../../node_modules/@openzeppelin-compact/utils/src/Initializable" prefix Initializable_;
import "../../../node_modules/@openzeppelin-compact/utils/src/Utils" prefix Utils_;
import "../../../node_modules/@openzeppelin-compact/utils/src/Initializable" prefix Initializable_;

/**
* @description Mapping from token ID to account balances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"@openzeppelin-compact/compact": "workspace:^"
},
"devDependencies": {
"@openzeppelin-compact/compact-std": "workspace:^",
"@openzeppelin-compact/testing": "workspace:^",
"@types/node": "22.14.0",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pragma language_version >= 0.15.0;

module NonFungibleToken {
import CompactStandardLibrary;
import "../../node_modules/@openzeppelin-compact/utils/src/Utils" prefix Utils_;
import "../../node_modules/@openzeppelin-compact/utils/src/Initializable" prefix Initializable_;
import "../../../node_modules/@openzeppelin-compact/utils/src/Utils" prefix Utils_;
import "../../../node_modules/@openzeppelin-compact/utils/src/Initializable" prefix Initializable_;

/// Public state
export sealed ledger _name: Opaque<"string">;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
pragma language_version >= 0.15.0;

import CompactStandardLibrary;

import "../../NonFungibleToken" prefix NonFungibleToken_;

export { ZswapCoinPublicKey, ContractAddress, Either, Maybe };

/**
* @description `init` is a param for testing.
* If `init` is true, initialize the contract with `_name` and `_symbol`.
Expand Down
Loading
Loading