Skip to content

Commit

Permalink
Merge pull request #1918 from demergent-labs/test_stabilization
Browse files Browse the repository at this point in the history
update stable_b_tree_map prop tests to handle new stable_b_tree_map b…
  • Loading branch information
lastmjs authored Aug 19, 2024
2 parents c7b4649 + d632747 commit 1965eef
Show file tree
Hide file tree
Showing 15 changed files with 172 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ jobs:
ETHEREUM_URL: ${{ secrets.ETHEREUM_URL }}
AZLE_IDENTITY_STORAGE_MODE: 'plaintext'
AZLE_END_TO_END_TEST_LINK_AZLE: ${{ matrix.azle_source == 'repo' }}
AZLE_QUICK_TEST: ${{ matrix.azle_source == 'repo'}}
AZLE_TEST_RUN_ON_RELEASE: ${{ contains(github.head_ref, 'release--') }}
strategy:
fail-fast: false # We want to see which example tests succeed and which ones fail, we don't want one example test to cancel the rest
matrix:
Expand Down
33 changes: 22 additions & 11 deletions examples/basic_bitcoin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,28 @@ app.get('/get-p2pkh-address', async (req, res) => {
/// Sends the given amount of bitcoin from this canister to the given address.
/// Returns the transaction ID.
app.post('/send', async (req, res) => {
const { destinationAddress, amountInSatoshi } = req.body;

const txId = await bitcoinWallet.send(
NETWORK,
DERIVATION_PATH,
KEY_NAME,
destinationAddress,
BigInt(jsonParse(JSON.stringify(amountInSatoshi)))
);

res.send(txId);
try {
const { destinationAddress, amountInSatoshi } = req.body;

const txId = await bitcoinWallet.send(
NETWORK,
DERIVATION_PATH,
KEY_NAME,
destinationAddress,
BigInt(jsonParse(JSON.stringify(amountInSatoshi)))
);

res.send(txId);
} catch (error: any) {
res.status(500).json({
success: false,
error: {
code: error.code || 'UNKNOWN_ERROR',
message: error.message,
details: error.info || null
}
});
}
});

app.listen();
Expand Down
33 changes: 22 additions & 11 deletions examples/bitcoin_psbt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,28 @@ app.get('/get-p2wpkh-address', async (req, res) => {
/// Sends the given amount of bitcoin from this canister to the given address.
/// Returns the transaction ID.
app.post('/send', async (req, res) => {
const { destinationAddress, amountInSatoshi } = req.body;

const txId = await bitcoinWallet.send(
NETWORK,
DERIVATION_PATH,
KEY_NAME,
destinationAddress,
BigInt(jsonParse(JSON.stringify(amountInSatoshi)))
);

res.send(txId);
try {
const { destinationAddress, amountInSatoshi } = req.body;

const txId = await bitcoinWallet.send(
NETWORK,
DERIVATION_PATH,
KEY_NAME,
destinationAddress,
BigInt(jsonParse(JSON.stringify(amountInSatoshi)))
);

res.send(txId);
} catch (error: any) {
res.status(500).json({
success: false,
error: {
code: error.code || 'UNKNOWN_ERROR',
message: error.message,
details: error.info || null
}
});
}
});

app.listen();
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function ContainsKeyTestArb(
}

function generateBody(stableBTreeMapName: string): string {
return `
return /*TS*/ `
return ${stableBTreeMapName}.containsKey(param0);
`;
}
Expand Down
12 changes: 9 additions & 3 deletions property_tests/tests/stable_b_tree_map/test/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export function GetTestArb(
].join(', ');

const returnCandidTypeObject = `Opt(${stableBTreeMap.valueSample.src.candidTypeObject})`;
const body = generateBody(stableBTreeMap.name);
const valueTypeIsNull =
stableBTreeMap.valueSample.src.candidTypeAnnotation === 'Null';
const body = generateBody(stableBTreeMap.name, valueTypeIsNull);

const tests = generateTests(
functionName,
Expand All @@ -43,10 +45,14 @@ export function GetTestArb(
});
}

function generateBody(stableBTreeMapName: string): string {
function generateBody(
stableBTreeMapName: string,
valueTypeIsNull: boolean
): string {
return /*TS*/ `
const result = ${stableBTreeMapName}.get(param0);
if (result === null) {
const containsKey = ${stableBTreeMapName}.containsKey(param0); // For situations where the stored value is literally null
if (result === null ${valueTypeIsNull ? '&& !containsKey' : ''}) {
return None
} else {
return Some(result)
Expand Down
12 changes: 9 additions & 3 deletions property_tests/tests/stable_b_tree_map/test/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export function RemoveTestArb(
].join(', ');

const returnCandidTypeObject = `Opt(${stableBTreeMap.valueSample.src.candidTypeObject})`;
const body = generateBody(stableBTreeMap.name);
const valueTypeIsNull =
stableBTreeMap.valueSample.src.candidTypeAnnotation === 'Null';
const body = generateBody(stableBTreeMap.name, valueTypeIsNull);

const tests = generateTests(
functionName,
Expand All @@ -43,10 +45,14 @@ export function RemoveTestArb(
});
}

function generateBody(stableBTreeMapName: string): string {
function generateBody(
stableBTreeMapName: string,
valueTypeIsNull: boolean
): string {
return /*TS*/ `
const containsKey = ${stableBTreeMapName}.containsKey(param0); // For situations where the stored value is literally null
const result = ${stableBTreeMapName}.remove(param0);
if (result === null) {
if (result === null ${valueTypeIsNull ? '&& !containsKey' : ''}) {
return None
} else {
return Some(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
Expand Down
2 changes: 1 addition & 1 deletion tests/end_to_end/candid_rpc/class_syntax/new/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "new_end_to_end_test_functional_syntax",
"scripts": {
"test": "if [ \"$AZLE_QUICK_TEST\" != \"true\" ]; then tsx test/test.ts; else echo 'Skipping pretests'; fi"
"test": "if [ \"$AZLE_TEST_RUN_ON_RELEASE\" == \"true\" ]; then tsx test/test.ts; else echo 'Skipping pretests'; fi"
},
"devDependencies": {
"@dfinity/agent": "^0.19.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "new_end_to_end_test_functional_syntax",
"scripts": {
"test": "if [ \"$AZLE_QUICK_TEST\" != \"true\" ]; then tsx test/test.ts; else echo 'Skipping pretests'; fi"
"test": "if [ \"$AZLE_TEST_RUN_ON_RELEASE\" == \"true\" ]; then tsx test/test.ts; else echo 'Skipping pretests'; fi"
},
"devDependencies": {
"@dfinity/agent": "^0.19.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testTimeout: 100_000_000,
transform: {
'^.+\\.ts$': ['ts-jest', { isolatedModules: true }],
'^.+\\.js$': 'ts-jest'
Expand Down
47 changes: 29 additions & 18 deletions tests/end_to_end/http_server/ethers_base/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,35 @@ app.post(
app.post(
'/transfer-from-canister',
async (req: Request<any, any, { to: string; value: string }>, res) => {
const wallet = new ThresholdWallet(
{
derivationPath: [ic.id().toUint8Array()]
},
ethers.getDefaultProvider('https://sepolia.base.org')
);

const to = req.body.to;
const value = ethers.parseEther(req.body.value);
const gasLimit = 21_000n;

const tx = await wallet.sendTransaction({
to,
value,
gasLimit
});

res.send(`transaction sent with hash: ${tx.hash}`);
try {
const wallet = new ThresholdWallet(
{
derivationPath: [ic.id().toUint8Array()]
},
ethers.getDefaultProvider('https://sepolia.base.org')
);

const to = req.body.to;
const value = ethers.parseEther(req.body.value);
const gasLimit = 21_000n;

const tx = await wallet.sendTransaction({
to,
value,
gasLimit
});

res.send(`transaction sent with hash: ${tx.hash}`);
} catch (error: any) {
res.status(500).json({
success: false,
error: {
code: error.code || 'UNKNOWN_ERROR',
message: error.message,
details: error.info || null
}
});
}
}
);

Expand Down
2 changes: 1 addition & 1 deletion tests/end_to_end/http_server/fetch_ic/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function getTests(canisterName: string): Test {

mainPage = pages[1];
},
10_000
15_000
);

wait('for identity to be set', 5_000);
Expand Down
116 changes: 65 additions & 51 deletions tests/end_to_end/http_server/ic_evm_rpc/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,60 +83,74 @@ app.post(
app.post(
'/transfer-from-canister',
async (req: Request<any, any, { to: string; value: string }>, res) => {
if (canisterAddress.value === null) {
canisterAddress.value = ethers.computeAddress(
ethers.hexlify(await ecdsaPublicKey([ic.id().toUint8Array()]))
try {
if (canisterAddress.value === null) {
canisterAddress.value = ethers.computeAddress(
ethers.hexlify(
await ecdsaPublicKey([ic.id().toUint8Array()])
)
);
}

const to = req.body.to;
const value = ethers.parseEther(req.body.value);
const maxPriorityFeePerGas = await ethMaxPriorityFeePerGas();
const baseFeePerGas = BigInt(
(await ethFeeHistory()).Consistent?.Ok[0].baseFeePerGas[0]
);
const maxFeePerGas = baseFeePerGas * 2n + maxPriorityFeePerGas;
const gasLimit = 21_000n;
const nonce = await ethGetTransactionCount(canisterAddress.value);

let tx = ethers.Transaction.from({
to,
value,
maxPriorityFeePerGas,
maxFeePerGas,
gasLimit,
nonce,
chainId
});

const unsignedSerializedTx = tx.unsignedSerialized;
const unsignedSerializedTxHash =
ethers.keccak256(unsignedSerializedTx);

const signedSerializedTxHash = await signWithEcdsa(
[ic.id().toUint8Array()],
ethers.getBytes(unsignedSerializedTxHash)
);
}

const to = req.body.to;
const value = ethers.parseEther(req.body.value);
const maxPriorityFeePerGas = await ethMaxPriorityFeePerGas();
const baseFeePerGas = BigInt(
(await ethFeeHistory()).Consistent?.Ok[0].baseFeePerGas[0]
);
const maxFeePerGas = baseFeePerGas * 2n + maxPriorityFeePerGas;
const gasLimit = 21_000n;
const nonce = await ethGetTransactionCount(canisterAddress.value);

let tx = ethers.Transaction.from({
to,
value,
maxPriorityFeePerGas,
maxFeePerGas,
gasLimit,
nonce,
chainId
});

const unsignedSerializedTx = tx.unsignedSerialized;
const unsignedSerializedTxHash = ethers.keccak256(unsignedSerializedTx);

const signedSerializedTxHash = await signWithEcdsa(
[ic.id().toUint8Array()],
ethers.getBytes(unsignedSerializedTxHash)
);

const { r, s, v } = calculateRsvForTEcdsa(
canisterAddress.value,
unsignedSerializedTxHash,
signedSerializedTxHash
);

tx.signature = {
r,
s,
v
};

const rawTransaction = tx.serialized;

const result = await ethSendRawTransaction(rawTransaction);
const { r, s, v } = calculateRsvForTEcdsa(
canisterAddress.value,
unsignedSerializedTxHash,
signedSerializedTxHash
);

if (result.Consistent?.Ok?.Ok.length === 1) {
res.send('transaction sent');
} else {
res.status(500).send('transaction failed');
tx.signature = {
r,
s,
v
};

const rawTransaction = tx.serialized;

const result = await ethSendRawTransaction(rawTransaction);

if (result.Consistent?.Ok?.Ok.length === 1) {
res.send('transaction sent');
} else {
res.status(500).send('transaction failed');
}
} catch (error: any) {
res.status(500).json({
success: false,
error: {
code: error.code || 'UNKNOWN_ERROR',
message: error.message,
details: error.info || null
}
});
}
}
);
Expand Down
7 changes: 4 additions & 3 deletions tests/end_to_end/http_server/large_files/test/auto_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ const autoGenAutoUploadSmallFileInfos: [number, Unit][] = [
];

const autoGenAutoUploadFileInfos: [number, Unit][] =
process.env.AZLE_QUICK_TEST === 'true'
? autoGenAutoUploadSmallFileInfos
: [...autoGenAutoUploadSmallFileInfos, [250, 'MiB'], [1, 'GiB']];
process.env.AZLE_TEST_RUN_ON_RELEASE === 'true' ||
process.env.AZLE_TEST_RUN_ON_LOCAL === 'true'
? [...autoGenAutoUploadSmallFileInfos, [250, 'MiB'], [1, 'GiB']]
: autoGenAutoUploadSmallFileInfos;

const permanentFiles: string[] = [
'photos/people/george-washington.tif',
Expand Down
Loading

0 comments on commit 1965eef

Please sign in to comment.