Skip to content
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

test: add wideRatio test #550

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
83 changes: 82 additions & 1 deletion tests/contracts/artifacts/MathTest.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,86 @@ uintFromHex:
pushbytes 0x00000000000000000000000000000000000000000000000000000000000000ff
retsub

// wideRatioTest()uint64
*abi_route_wideRatioTest:
// The ABI return prefix
byte 0x151f7c75

// execute wideRatioTest()uint64
callsub wideRatioTest
itob
concat
log
int 1
return

// wideRatioTest(): uint64
wideRatioTest:
proto 0 1

// tests/contracts/math.algo.ts:230
// return wideRatio([Uint<64>('18446744073709551615'), 2, 3, 4, 5], [2, 3, 4, 5]);
int 18446744073709551615
pushint 2
mulw
pushint 3
uncover 2
dig 1
*
cover 2
mulw
cover 2
+
swap
pushint 4
uncover 2
dig 1
*
cover 2
mulw
cover 2
+
swap
pushint 5
uncover 2
dig 1
*
cover 2
mulw
cover 2
+
swap
pushint 2
pushint 3
mulw
pushint 4
uncover 2
dig 1
*
cover 2
mulw
cover 2
+
swap
pushint 5
uncover 2
dig 1
*
cover 2
mulw
cover 2
+
swap
divmodw
pop
pop
swap
!

// wideRatio failed
assert
retsub

*abi_route_createApplication:
int 1
return
Expand Down Expand Up @@ -2093,8 +2173,9 @@ uintFromHex:
pushbytes 0x274d7705 // method "unsafeVariables()uint64"
pushbytes 0x92465d08 // method "foobar(uint128)uint128"
pushbytes 0xf01facce // method "uintFromHex()uint256"
pushbytes 0x5ac8a0a0 // method "wideRatioTest()uint64"
txna ApplicationArgs 0
match *abi_route_u64plus *abi_route_u64minus *abi_route_u64mul *abi_route_u64div *abi_route_u256plus *abi_route_u256minus *abi_route_u256mul *abi_route_u256div *abi_route_u64Return256 *abi_route_maxU64 *abi_route_exponent *abi_route_variableTypeHint *abi_route_uint8plus *abi_route_uint8exp *abi_route_plusEquals *abi_route_plusEqualsFromGlobal *abi_route_boxTest *abi_route_unsafeMethodArgs *abi_route_uint256ComparisonType *abi_route_squareRoot256 *abi_route_squareRoot64 *abi_route_addressToBigInt *abi_route_u8Tou64 *abi_route_funcName *abi_route_bigintPlus *abi_route_bitwiseOr *abi_route_bitwiseAnd *abi_route_bitwiseXor *abi_route_bitwiseOrU256 *abi_route_bitwiseAndU256 *abi_route_bitwiseXorU256 *abi_route_bitwiseNot *abi_route_bitwiseNotU256 *abi_route_mulw *abi_route_addw *abi_route_expw *abi_route_divw *abi_route_divmodw *abi_route_unsafeVariables *abi_route_foobar *abi_route_uintFromHex
match *abi_route_u64plus *abi_route_u64minus *abi_route_u64mul *abi_route_u64div *abi_route_u256plus *abi_route_u256minus *abi_route_u256mul *abi_route_u256div *abi_route_u64Return256 *abi_route_maxU64 *abi_route_exponent *abi_route_variableTypeHint *abi_route_uint8plus *abi_route_uint8exp *abi_route_plusEquals *abi_route_plusEqualsFromGlobal *abi_route_boxTest *abi_route_unsafeMethodArgs *abi_route_uint256ComparisonType *abi_route_squareRoot256 *abi_route_squareRoot64 *abi_route_addressToBigInt *abi_route_u8Tou64 *abi_route_funcName *abi_route_bigintPlus *abi_route_bitwiseOr *abi_route_bitwiseAnd *abi_route_bitwiseXor *abi_route_bitwiseOrU256 *abi_route_bitwiseAndU256 *abi_route_bitwiseXorU256 *abi_route_bitwiseNot *abi_route_bitwiseNotU256 *abi_route_mulw *abi_route_addw *abi_route_expw *abi_route_divw *abi_route_divmodw *abi_route_unsafeVariables *abi_route_foobar *abi_route_uintFromHex *abi_route_wideRatioTest

// this contract does not implement the given ABI method for call NoOp
err
14 changes: 13 additions & 1 deletion tests/contracts/artifacts/MathTest.arc32.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tests/contracts/artifacts/MathTest.arc4.json
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,13 @@
"type": "uint256"
}
},
{
"name": "wideRatioTest",
"args": [],
"returns": {
"type": "uint64"
}
},
{
"name": "createApplication",
"args": [],
Expand Down
27 changes: 23 additions & 4 deletions tests/contracts/artifacts/MathTest.arc56_draft.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/contracts/math.algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,8 @@ class MathTest extends Contract {
uintFromHex(): uint256 {
return Uint<256>('0xFF');
}

wideRatioTest(): uint64 {
return wideRatio([Uint<64>('18446744073709551615'), 2, 3, 4, 5], [2, 3, 4, 5]);
}
}
5 changes: 5 additions & 0 deletions tests/math.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ describe('Math', function () {
method: 'unsafeVariables',
});
});

test('wideRatioTest', async function () {
const { appClient } = await compileAndCreate(await sender, PATH, ARTIFACTS_DIR, NAME);
expect(await runMethod({ appClient, method: 'wideRatioTest' })).toBe(18446744073709551615n);
});
});

describe('Compile Errors', function () {
Expand Down
Loading