Skip to content
Open
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
60 changes: 50 additions & 10 deletions pnpm-lock.yaml

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

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ overrides:
yaml@<2.8.3: '>=2.8.3'
brace-expansion@<5.0.5: '>=5.0.5'
lodash@<=4.17.23: '>=4.18.0'
follow-redirects@<=1.15.11: '>=1.16.0'

nodeOptions: '--disable-warning=ExperimentalWarning --disable-warning=DeprecationWarning'
22 changes: 15 additions & 7 deletions src/cli/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ import cli from './cli.js'

const testPrivateKey = generatePrivateKey()
const testAccount = privateKeyToAccount(testPrivateKey)
const testXdgDataHome = fs.mkdtempSync(path.join(os.tmpdir(), 'mppx-cli-xdg-'))

afterAll(() => {
fs.rmSync(testXdgDataHome, { recursive: true, force: true })
})

async function serve(argv: string[], options?: { env?: Record<string, string | undefined> }) {
let output = ''
let stderr = ''
let exitCode: number | undefined
const saved: Record<string, string | undefined> = {}
if (options?.env) {
for (const [key, value] of Object.entries(options.env)) {
saved[key] = process.env[key]
if (value === undefined) delete process.env[key]
else process.env[key] = value
}
const env = { XDG_DATA_HOME: testXdgDataHome, ...options?.env }
for (const [key, value] of Object.entries(env)) {
saved[key] = process.env[key]
if (value === undefined) delete process.env[key]
else process.env[key] = value
}
const origStdoutWrite = process.stdout.write
const origStderrWrite = process.stderr.write
Expand Down Expand Up @@ -1053,7 +1057,11 @@ describe('stripe charge', () => {
describe.skipIf(!!process.env.CI)('account', () => {
const binPath = path.resolve(import.meta.dirname, '../bin.ts')
const cwd = path.resolve(import.meta.dirname, '../..')
const accountEnv = { ...process.env, NODE_NO_WARNINGS: '1' }
const accountEnv = {
...process.env,
NODE_NO_WARNINGS: '1',
XDG_DATA_HOME: testXdgDataHome,
}
const prefix = `__mppx_test_${Date.now()}`
const createdAccounts: string[] = []

Expand Down
36 changes: 36 additions & 0 deletions src/server/Mppx.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,40 @@ describe('Mppx type tests', () => {
test('static Mppx.compose accepts configured handlers', () => {
expectTypeOf(Mppx.compose).toBeFunction()
})

test('challenge namespace has nested accessors matching methods', () => {
const mppx = Mppx.create({ methods: [alphaMethod, betaMethod], realm, secretKey })

expectTypeOf(mppx.challenge).toBeObject()
expectTypeOf(mppx.challenge.alpha).toBeObject()
expectTypeOf(mppx.challenge.alpha.charge).toBeFunction()
expectTypeOf(mppx.challenge.beta).toBeObject()
expectTypeOf(mppx.challenge.beta.charge).toBeFunction()
})

test('challenge functions return Promise<Challenge>', () => {
const mppx = Mppx.create({ methods: [alphaMethod], realm, secretKey })

const challenge = mppx.challenge.alpha.charge({
amount: '100',
currency: '0x01',
decimals: 6,
recipient: '0x02',
})

expectTypeOf(challenge).toMatchTypeOf<Promise<unknown>>()

type AwaitedChallenge = Awaited<typeof challenge>
expectTypeOf<AwaitedChallenge>().toHaveProperty('id')
expectTypeOf<AwaitedChallenge>().toHaveProperty('realm')
expectTypeOf<AwaitedChallenge>().toHaveProperty('method')
expectTypeOf<AwaitedChallenge>().toHaveProperty('intent')
expectTypeOf<AwaitedChallenge>().toHaveProperty('request')
})

test('verifyCredential exists and returns Promise<Receipt>', () => {
const mppx = Mppx.create({ methods: [alphaMethod], realm, secretKey })

expectTypeOf(mppx.verifyCredential).toBeFunction()
})
})
Loading
Loading