Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Apr 17, 2024
1 parent fea3b0d commit 2ef977e
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 180 deletions.
3 changes: 1 addition & 2 deletions examples/bitcoinjs-lib/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as dns from 'node:dns';
dns.setDefaultResultOrder('ipv4first');

import { getTests as getBitcoinTests } from 'azle/examples/bitcore-lib/test/tests';
import { Test } from 'azle/test';

import { getBitcoinTests } from '../../bitcore-lib/test/bitcoin';

export function getTests(canisterId: string): Test[] {
const origin = `http://${canisterId}.localhost:8000`;
return [
Expand Down
175 changes: 0 additions & 175 deletions examples/bitcore-lib/test/bitcoin.ts

This file was deleted.

171 changes: 168 additions & 3 deletions examples/bitcore-lib/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,172 @@
import { Test } from 'azle/test';

import { getBitcoinTests } from './bitcoin';

export function getTests(canisterId: string): Test[] {
return getBitcoinTests(canisterId);
const origin = `http://${canisterId}.localhost:8000`;

return [
{
name: '/get-address',
test: async () => {
try {
const response = await fetch(`${origin}/get-address`);
const responseText = await response.text();

return {
Ok:
responseText ===
'1PmamxRspvjCV7vDqMpzvKf92epy1utZVj'
};
} catch (error: any) {
return {
Err: error
};
}
}
},
{
name: '/get-public-key',
test: async () => {
try {
const response = await fetch(`${origin}/get-public-key`);
const publicKey = await response.text();

return {
Ok:
publicKey ===
'03fad62848f1a6cde4c4d9453dadea714cbd59f1282087853de8b0c6072bec27e7'
};
} catch (error: any) {
return {
Err: error
};
}
}
},
{
name: '/get-private-key',
test: async () => {
try {
const response = await fetch(`${origin}/get-private-key`);
const responseText = await response.text();

return {
Ok:
responseText ===
'b221d9dbb083a7f33428d7c2a3c3198ae925614d70210e28716ccaa7cd4ddb79'
};
} catch (error: any) {
return {
Err: error
};
}
}
},
{
name: '/get-private-key-wif',
test: async () => {
try {
const response = await fetch(
`${origin}/get-private-key-wif`
);
const responseText = await response.text();

return {
Ok:
responseText ===
'L3BybjkmnMdXE6iNEaeZTjVMTHA4TvpYbQozc264Lto9yVDis2nv'
};
} catch (error: any) {
return {
Err: error
};
}
}
},
{
name: '/create-transaction',
test: async () => {
try {
const response = await fetch(
`${origin}/create-transaction`,
{ method: 'POST' }
);
const transaction = await response.text();

return {
Ok:
transaction ===
'02000000018689302ea03ef5dd56fb7940a867f9240fa811eddeb0fa4c87ad9ff3728f5e110000000000ffffffff01983a0000000000001976a914ad618cf4333b3b248f9744e8e81db2964d0ae39788ac00000000'
};
} catch (error: any) {
return {
Err: error
};
}
}
},
{
name: '/sign-bitcoin-message',
test: async () => {
try {
const response = await fetch(
`${origin}/sign-bitcoin-message`,
{ method: 'POST' }
);
const responseText = await response.text();

return {
Ok: responseText.length === 88
};
} catch (error: any) {
return {
Err: error
};
}
}
},
{
name: '/verify-bitcoin-message',
test: async () => {
try {
const response = await fetch(
`${origin}/verify-bitcoin-message`,
{
method: 'POST'
}
);
const responseText = await response.json();

return {
Ok: responseText === true
};
} catch (error: any) {
return {
Err: error
};
}
}
},
{
name: '/fail-to-verify-bitcoin-message',
test: async () => {
try {
const response = await fetch(
`${origin}/fail-to-verify-bitcoin-message`,
{
method: 'POST'
}
);
const responseText = await response.json();

return {
Ok: responseText === false
};
} catch (error: any) {
return {
Err: error
};
}
}
}
];
}

0 comments on commit 2ef977e

Please sign in to comment.