From 4d089113d2141094c321951c47853b89da20b620 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 26 Sep 2024 20:21:36 +0300 Subject: [PATCH] BigUint operations --- .../main/expression/rust-to-mx.md | 2 - mx-rust-semantics/main/glue.md | 6 + mx-rust-semantics/main/modules/biguint.md | 182 +++++++++++++++++- mx-rust-semantics/main/modules/proxy.md | 84 ++++---- mx-rust-semantics/main/modules/send.md | 40 ++-- mx-rust-semantics/main/representation.md | 14 +- rust-semantics/expression/comparisons.md | 1 + tests/mx-rust-contracts/require.3.run | 2 +- tests/mx-rust/biguint.add.run | 8 + tests/mx-rust/biguint.add64.run | 8 + tests/mx-rust/biguint.div.run | 8 + tests/mx-rust/biguint.div64.run | 8 + tests/mx-rust/biguint.eq.run | 26 +++ tests/mx-rust/biguint.ge.run | 26 +++ tests/mx-rust/biguint.gt.run | 26 +++ tests/mx-rust/biguint.le.run | 26 +++ tests/mx-rust/biguint.lt.run | 26 +++ tests/mx-rust/biguint.mul.run | 8 + tests/mx-rust/biguint.mul64.run | 8 + tests/mx-rust/biguint.ne.run | 26 +++ tests/mx-rust/biguint.rs | 73 +++++++ tests/mx-rust/biguint.sub.run | 8 + tests/mx-rust/biguint.sub64.run | 8 + tests/mx-rust/biguint.zero.run | 6 + 24 files changed, 556 insertions(+), 74 deletions(-) create mode 100644 tests/mx-rust/biguint.add.run create mode 100644 tests/mx-rust/biguint.add64.run create mode 100644 tests/mx-rust/biguint.div.run create mode 100644 tests/mx-rust/biguint.div64.run create mode 100644 tests/mx-rust/biguint.eq.run create mode 100644 tests/mx-rust/biguint.ge.run create mode 100644 tests/mx-rust/biguint.gt.run create mode 100644 tests/mx-rust/biguint.le.run create mode 100644 tests/mx-rust/biguint.lt.run create mode 100644 tests/mx-rust/biguint.mul.run create mode 100644 tests/mx-rust/biguint.mul64.run create mode 100644 tests/mx-rust/biguint.ne.run create mode 100644 tests/mx-rust/biguint.rs create mode 100644 tests/mx-rust/biguint.sub.run create mode 100644 tests/mx-rust/biguint.sub64.run create mode 100644 tests/mx-rust/biguint.zero.run diff --git a/mx-rust-semantics/main/expression/rust-to-mx.md b/mx-rust-semantics/main/expression/rust-to-mx.md index a991c21..dea7a59 100644 --- a/mx-rust-semantics/main/expression/rust-to-mx.md +++ b/mx-rust-semantics/main/expression/rust-to-mx.md @@ -30,9 +30,7 @@ module MX-RUST-EXPRESSION-RUST-TO-MX rule rustToMx(S:String => mxStringValue(S)) rule rustToMx(V:Value => mxIntValue({valueToInteger(V)}:>Int)) requires notBool isSemanticsError(valueToInteger(V)) - rule rustToMx(tuple(V:ValueList)) => rustValuesToMxListValue(V, .MxValueList) - syntax RustMxInstruction ::= rustValuesToMxListValue(ValueListOrError, MxValueList) rule rustValuesToMxListValue(.ValueList, L:MxValueList) => rustToMx(mxListValue(reverse(L, .MxValueList))) rule (.K => rustToMx(HOLE)) ~> rustValuesToMxListValue(((HOLE:Value , V:ValueList) => V), _:MxValueList) diff --git a/mx-rust-semantics/main/glue.md b/mx-rust-semantics/main/glue.md index 28f5cb7..e0b9902 100644 --- a/mx-rust-semantics/main/glue.md +++ b/mx-rust-semantics/main/glue.md @@ -64,6 +64,12 @@ module MX-RUST-GLUE rule mxIntValue(0) ~> mxRustCheckMxStatus => .K + rule (.K => rustValuesToMxListValue(Values, .MxValueList)) + ~> rustMxCallHook(_, Values:ValueList) + rule (rustToMx(mxListValue(L:MxValueList)) ~> rustMxCallHook(Hook:MxHookName, _)) + => Hook(L) + + rule L:MxValue ~> mxRustWrapInMxList => mxListValue(L) endmodule ``` diff --git a/mx-rust-semantics/main/modules/biguint.md b/mx-rust-semantics/main/modules/biguint.md index b00d020..7cb3fbd 100644 --- a/mx-rust-semantics/main/modules/biguint.md +++ b/mx-rust-semantics/main/modules/biguint.md @@ -3,6 +3,7 @@ module MX-RUST-MODULES-BIGUINT imports private COMMON-K-CELL imports private MX-COMMON-SYNTAX + imports private MX-RUST-BIGUINT-OPERATORS imports private MX-RUST-REPRESENTATION imports private RUST-EXECUTION-CONFIGURATION imports private RUST-REPRESENTATION @@ -25,8 +26,15 @@ module MX-RUST-MODULES-BIGUINT ValueId |-> V:Value ... + rule normalizedMethodCall + ( #token("BigUint", "Identifier"):Identifier + , #token("zero", "Identifier"):Identifier + , .PtrList + ) + => mxRustBigIntNew(0) + // -------------------------------------- - rule bigUintType + rule bigUintFromValueType => rustStructType ( #token("BigUint", "Identifier"):Identifier , ( mxRustStructField @@ -36,9 +44,19 @@ module MX-RUST-MODULES-BIGUINT , .MxRustStructFields ) ) + rule bigUintFromIdType + => rustStructType + ( #token("BigUint", "Identifier"):Identifier + , ( mxRustStructField + ( #token("mx_biguint_id", "Identifier"):Identifier + , i32 + ) + , .MxRustStructFields + ) + ) // -------------------------------------- rule mxToRustTyped(#token("BigUint", "Identifier"):Identifier, V:MxValue) - => mxToRustTyped(bigUintType, mxListValue(V)) + => mxToRustTyped(bigUintFromValueType, mxListValue(V)) rule (.K => MX#bigIntNew(mxIntValue(I))) ~> mxToRustTyped(MxRust#bigInt, mxIntValue(I:Int)) @@ -50,7 +68,7 @@ module MX-RUST-MODULES-BIGUINT | "mxRustCreateBigUint" rule mxRustBigIntNew(V:Int) - => mxToRustTyped(bigUintType, mxListValue(mxIntValue(V))) + => mxToRustTyped(bigUintFromValueType, mxListValue(mxIntValue(V))) rule mxRustEmptyValue(rustType(#token("BigUint", "Identifier"))) => mxRustBigIntNew(0) @@ -89,4 +107,162 @@ module MX-RUST-MODULES-BIGUINT endmodule +module MX-RUST-BIGUINT-OPERATORS + imports private COMMON-K-CELL + imports private MX-RUST-REPRESENTATION + imports private RUST-EXECUTION-CONFIGURATION + + syntax MxRustInstruction ::= rustMxBinaryBigUintOperator(MxHookName, Value, Value) + rule + + rustMxBinaryBigUintOperator + ( Hook:MxHookName + , struct + ( #token("BigUint", "Identifier"):Identifier #as BigUint:TypePath + , #token("mx_biguint_id", "Identifier"):Identifier |-> FirstId:Int + _:Map + ) + , struct + ( #token("BigUint", "Identifier"):Identifier #as BigUint:TypePath + , #token("mx_biguint_id", "Identifier"):Identifier |-> SecondId:Int + _:Map + ) + ) + => rustMxCallHook(Hook, (V1, V2, .ValueList)) + ~> mxRustWrapInMxList + ~> mxToRustTyped(bigUintFromIdType) + ~> implicitCastTo(BigUint) + ... + + + FirstId |-> V1:Value + SecondId |-> V2:Value + ... + + + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintOperator(MX#bigIntAdd, V1, V2) + + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + - ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintOperator(MX#bigIntSub, V1, V2) + + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + * ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintOperator(MX#bigIntMul, V1, V2) + + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + / ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintOperator(MX#bigIntDiv, V1, V2) + + + + rule + (ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _)) #as V1:PtrValue) + + (ptrValue(_, u64(_:MInt{64})) #as V2:PtrValue) + => V1 + bigUintFrom(V2) + + rule + (ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _)) #as V1:PtrValue) + - (ptrValue(_, u64(_:MInt{64})) #as V2:PtrValue) + => V1 - bigUintFrom(V2) + + rule + (ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _)) #as V1:PtrValue) + * (ptrValue(_, u64(_:MInt{64})) #as V2:PtrValue) + => V1 * bigUintFrom(V2) + + rule + (ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _)) #as V1:PtrValue) + / (ptrValue(_, u64(_:MInt{64})) #as V2:PtrValue) + => V1 / bigUintFrom(V2) + + syntax Expression ::= bigUintFrom(Expression) [function, total] + rule bigUintFrom(V:Expression) + => ( #token("BigUint", "Identifier"):Identifier + :: #token("from", "Identifier"):Identifier + :: .PathExprSegments + ) + ( V, .CallParamsList ) + + + syntax MxRustInstruction ::= rustMxBinaryBigUintComparisonOperator(MxHookName, Value, Value) + rule + + rustMxBinaryBigUintComparisonOperator + ( Hook:MxHookName + , struct + ( #token("BigUint", "Identifier"):Identifier + , #token("mx_biguint_id", "Identifier"):Identifier |-> FirstId:Int + _:Map + ) + , struct + ( #token("BigUint", "Identifier"):Identifier + , #token("mx_biguint_id", "Identifier"):Identifier |-> SecondId:Int + _:Map + ) + ) + => rustMxCallHook(Hook, (V1, V2, .ValueList)) + ~> mxToRustTyped(i32) + ~> implicitCastTo(i32) + ... + + + FirstId |-> V1:Value + SecondId |-> V2:Value + ... + + + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + == ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintComparisonOperator(MX#bigIntCmp, V1, V2) + ~> mxRustEqResult + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + != ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintComparisonOperator(MX#bigIntCmp, V1, V2) + ~> mxRustNeResult + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + < ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) // > + => rustMxBinaryBigUintComparisonOperator(MX#bigIntCmp, V1, V2) + ~> mxRustLtResult + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + <= ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintComparisonOperator(MX#bigIntCmp, V1, V2) + ~> mxRustLeResult + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + > ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintComparisonOperator(MX#bigIntCmp, V1, V2) + ~> mxRustGtResult + rule + ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V1:Value) + >= ptrValue(_, struct(#token("BigUint", "Identifier"):Identifier, _) #as V2:Value) + => rustMxBinaryBigUintComparisonOperator(MX#bigIntCmp, V1, V2) + ~> mxRustGeResult + + syntax MxRustInstruction ::= "mxRustEqResult" + | "mxRustNeResult" + | "mxRustGeResult" + | "mxRustGtResult" + | "mxRustLeResult" + | "mxRustLtResult" + + rule V:PtrValue ~> mxRustEqResult => V == ptrValue(null, i32(0p32)) + rule V:PtrValue ~> mxRustNeResult => V != ptrValue(null, i32(0p32)) + rule V:PtrValue ~> mxRustGeResult => V >= ptrValue(null, i32(0p32)) + rule V:PtrValue ~> mxRustGtResult => V > ptrValue(null, i32(0p32)) + rule V:PtrValue ~> mxRustLtResult => V < ptrValue(null, i32(0p32)) // > + rule V:PtrValue ~> mxRustLeResult => V <= ptrValue(null, i32(0p32)) + +endmodule + ``` diff --git a/mx-rust-semantics/main/modules/proxy.md b/mx-rust-semantics/main/modules/proxy.md index 1d639db..c809f63 100644 --- a/mx-rust-semantics/main/modules/proxy.md +++ b/mx-rust-semantics/main/modules/proxy.md @@ -89,62 +89,62 @@ module MX-RUST-MODULES-PROXY MethodName syntax RustMxInstruction ::= rustMxManagedExecuteOnDestContext - ( destination: MxOrRustValueOrInstruction // MxOrRustValue - , egldValue: MxOrRustValueOrInstruction // MxOrRustValue - , mxTransfers: MxOrRustValueOrInstruction // MxOrRustValue - , gasLimit: MxOrRustValueOrInstruction // MxOrRustValue - , function: MxOrRustValueOrInstruction // MxOrRustValue - , args: MxOrRustValueOrInstruction // MxOrRustValue + ( destination: RustToMxOrInstruction // RustToMx + , egldValue: RustToMxOrInstruction // RustToMx + , mxTransfers: RustToMxOrInstruction // RustToMx + , gasLimit: RustToMxOrInstruction // RustToMx + , function: RustToMxOrInstruction // RustToMx + , args: RustToMxOrInstruction // RustToMx ) context rustMxManagedExecuteOnDestContext - (... destination: HOLE:MxOrRustValue => rustToMx(HOLE) - , egldValue: _:MxOrRustValue - , mxTransfers: _:MxOrRustValue - , gasLimit: _:MxOrRustValue - , function: _:MxOrRustValue - , args: _:MxOrRustValue + (... destination: HOLE:RustToMx => rustToMx(HOLE) + , egldValue: _:RustToMx + , mxTransfers: _:RustToMx + , gasLimit: _:RustToMx + , function: _:RustToMx + , args: _:RustToMx ) [result(MxValue)] context rustMxManagedExecuteOnDestContext - (... destination: Destination:MxOrRustValue - , egldValue: HOLE:MxOrRustValue => rustToMx(HOLE) - , mxTransfers: _:MxOrRustValue - , gasLimit: _:MxOrRustValue - , function: _:MxOrRustValue - , args: _:MxOrRustValue + (... destination: Destination:RustToMx + , egldValue: HOLE:RustToMx => rustToMx(HOLE) + , mxTransfers: _:RustToMx + , gasLimit: _:RustToMx + , function: _:RustToMx + , args: _:RustToMx ) requires isMxValue(Destination) [result(MxValue)] context rustMxManagedExecuteOnDestContext - (... destination: Destination:MxOrRustValue - , egldValue: EgldValue:MxOrRustValue - , mxTransfers: HOLE:MxOrRustValue => rustToMx(HOLE) - , gasLimit: _:MxOrRustValue - , function: _:MxOrRustValue - , args: _:MxOrRustValue + (... destination: Destination:RustToMx + , egldValue: EgldValue:RustToMx + , mxTransfers: HOLE:RustToMx => rustToMx(HOLE) + , gasLimit: _:RustToMx + , function: _:RustToMx + , args: _:RustToMx ) requires isMxValue(Destination) andBool isMxValue(EgldValue) [result(MxValue)] context rustMxManagedExecuteOnDestContext - (... destination: Destination:MxOrRustValue - , egldValue: EgldValue:MxOrRustValue - , mxTransfers: MxTransfers:MxOrRustValue - , gasLimit: HOLE:MxOrRustValue => rustToMx(HOLE) - , function: _:MxOrRustValue - , args: _:MxOrRustValue + (... destination: Destination:RustToMx + , egldValue: EgldValue:RustToMx + , mxTransfers: MxTransfers:RustToMx + , gasLimit: HOLE:RustToMx => rustToMx(HOLE) + , function: _:RustToMx + , args: _:RustToMx ) requires isMxValue(Destination) andBool isMxValue(EgldValue) andBool isMxValue(MxTransfers) [result(MxValue)] context rustMxManagedExecuteOnDestContext - (... destination: Destination:MxOrRustValue - , egldValue: EgldValue:MxOrRustValue - , mxTransfers: MxTransfers:MxOrRustValue - , gasLimit: GasLimit:MxOrRustValue - , function: HOLE:MxOrRustValue => rustToMx(HOLE) - , args: _:MxOrRustValue + (... destination: Destination:RustToMx + , egldValue: EgldValue:RustToMx + , mxTransfers: MxTransfers:RustToMx + , gasLimit: GasLimit:RustToMx + , function: HOLE:RustToMx => rustToMx(HOLE) + , args: _:RustToMx ) requires isMxValue(Destination) andBool isMxValue(EgldValue) @@ -152,12 +152,12 @@ module MX-RUST-MODULES-PROXY andBool isMxValue(GasLimit) [result(MxValue)] context rustMxManagedExecuteOnDestContext - (... destination: Destination:MxOrRustValue - , egldValue: EgldValue:MxOrRustValue - , mxTransfers: MxTransfers:MxOrRustValue - , gasLimit: GasLimit:MxOrRustValue - , function: Function:MxOrRustValue - , args: HOLE:MxOrRustValue => rustToMx(HOLE) + (... destination: Destination:RustToMx + , egldValue: EgldValue:RustToMx + , mxTransfers: MxTransfers:RustToMx + , gasLimit: GasLimit:RustToMx + , function: Function:RustToMx + , args: HOLE:RustToMx => rustToMx(HOLE) ) requires isMxValue(Destination) andBool isMxValue(EgldValue) diff --git a/mx-rust-semantics/main/modules/send.md b/mx-rust-semantics/main/modules/send.md index 9a03a1f..579cbb2 100644 --- a/mx-rust-semantics/main/modules/send.md +++ b/mx-rust-semantics/main/modules/send.md @@ -60,40 +60,40 @@ module MX-RUST-MODULES-SEND syntax RustMxInstruction ::= rustMxDirectEsdt - ( destination: MxOrRustValueOrInstruction // MxOrRustValue - , tokenId: MxOrRustValueOrInstruction // MxOrRustValue - , nonce: MxOrRustValueOrInstruction // MxOrRustValue - , amount: MxOrRustValueOrInstruction // MxOrRustValue + ( destination: RustToMxOrInstruction // RustToMx + , tokenId: RustToMxOrInstruction // RustToMx + , nonce: RustToMxOrInstruction // RustToMx + , amount: RustToMxOrInstruction // RustToMx ) context rustMxDirectEsdt - (... destination: HOLE:MxOrRustValue => rustToMx(HOLE) - , tokenId: _:MxOrRustValue - , nonce: _:MxOrRustValue - , amount: _:MxOrRustValue + (... destination: HOLE:RustToMx => rustToMx(HOLE) + , tokenId: _:RustToMx + , nonce: _:RustToMx + , amount: _:RustToMx ) [result(MxValue)] context rustMxDirectEsdt - (... destination: Destination:MxOrRustValue - , tokenId: HOLE:MxOrRustValue => rustToMx(HOLE) - , nonce: _:MxOrRustValue - , amount: _:MxOrRustValue + (... destination: Destination:RustToMx + , tokenId: HOLE:RustToMx => rustToMx(HOLE) + , nonce: _:RustToMx + , amount: _:RustToMx ) requires isMxValue(Destination) [result(MxValue)] context rustMxDirectEsdt - (... destination: Destination:MxOrRustValue - , tokenId: TokenId:MxOrRustValue - , nonce: HOLE:MxOrRustValue => rustToMx(HOLE) - , amount: _:MxOrRustValue + (... destination: Destination:RustToMx + , tokenId: TokenId:RustToMx + , nonce: HOLE:RustToMx => rustToMx(HOLE) + , amount: _:RustToMx ) requires isMxValue(Destination) andBool isMxValue(TokenId) [result(MxValue)] context rustMxDirectEsdt - (... destination: Destination:MxOrRustValue - , tokenId: TokenId:MxOrRustValue - , nonce: Nonce:MxOrRustValue - , amount: HOLE:MxOrRustValue => rustToMx(HOLE) + (... destination: Destination:RustToMx + , tokenId: TokenId:RustToMx + , nonce: Nonce:RustToMx + , amount: HOLE:RustToMx => rustToMx(HOLE) ) requires isMxValue(Destination) andBool isMxValue(TokenId) diff --git a/mx-rust-semantics/main/representation.md b/mx-rust-semantics/main/representation.md index a70c376..cbf7110 100644 --- a/mx-rust-semantics/main/representation.md +++ b/mx-rust-semantics/main/representation.md @@ -31,15 +31,18 @@ module MX-RUST-REPRESENTATION | mxRustNewStruct(MxRustStructType, CallParamsList) [strict(2), result(ValueWithPtr)] | "mxRustCheckMxStatus" + | rustMxCallHook(MxHookName, ValueList) + | "mxRustWrapInMxList" syntax TraitType ::= "contract" | "proxy" syntax MxRustType ::= "noType" | rustType(Type) syntax MxRustTypeOrError ::= MxRustType | SemanticsError syntax Value ::= MxRustType - syntax Type ::= "bigUintType" [function, total] + syntax Type ::= "bigUintFromValueType" [function, total] + syntax Type ::= "bigUintFromIdType" [function, total] - syntax MxOrRustValueOrInstruction ::= MxOrRustValue | MxRustInstruction + syntax RustToMxOrInstruction ::= RustToMx | MxRustInstruction syntax Expression ::= concatString(Expression, Expression) [seqstrict] | toString(Expression) [strict] @@ -84,14 +87,13 @@ module MX-RUST-REPRESENTATION-CONVERSIONS syntax MxToRustOrError ::= MxToRust | SemanticsError syntax MxToRustList ::= List{MxToRustOrError, ","} - syntax MxOrRustValue ::= MxValue | Value - syntax MxOrRustValueList ::= List{MxOrRustValue, ","} - syntax MxOrRustValueListOrError ::= MxOrRustValueList | SemanticsError + syntax RustToMx ::= MxValue | Value syntax MxRustInstruction ::= mxToRustTyped(MxRustType) // TODO: Merge rustToMx and rustValueToMx - syntax MxRustInstruction ::= rustToMx(MxOrRustValue) + syntax MxRustInstruction ::= rustToMx(RustToMx) | "rustToMx" + | rustValuesToMxListValue(ValueListOrError, MxValueList) endmodule ``` diff --git a/rust-semantics/expression/comparisons.md b/rust-semantics/expression/comparisons.md index c104513..3071bb0 100644 --- a/rust-semantics/expression/comparisons.md +++ b/rust-semantics/expression/comparisons.md @@ -27,6 +27,7 @@ module RUST-EXPRESSION-STRUCT-COMPARISONS ( listToPtrList(values(FirstFields)) , listToPtrList(values(SecondFields)) ) + [owise] syntax ExpressionOrError ::= allPtrEquality(PtrListOrError, PtrListOrError) [function, total] diff --git a/tests/mx-rust-contracts/require.3.run b/tests/mx-rust-contracts/require.3.run index 226ddc1..26cee29 100644 --- a/tests/mx-rust-contracts/require.3.run +++ b/tests/mx-rust-contracts/require.3.run @@ -10,4 +10,4 @@ call 6 MX#managedExecuteOnDestContext; check_eq mxIntValue(0); push_return_value; -check_eq mxUnitValue() +check_eq mxListValue() diff --git a/tests/mx-rust/biguint.add.run b/tests/mx-rust/biguint.add.run new file mode 100644 index 0000000..1ff677c --- /dev/null +++ b/tests/mx-rust/biguint.add.run @@ -0,0 +1,8 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +push 2u64; +push 3u64; +call BigUintTest.add; +get_bigint_from_struct; +check_eq mxIntValue(5) diff --git a/tests/mx-rust/biguint.add64.run b/tests/mx-rust/biguint.add64.run new file mode 100644 index 0000000..98b2791 --- /dev/null +++ b/tests/mx-rust/biguint.add64.run @@ -0,0 +1,8 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +push 2u64; +push 3u64; +call BigUintTest.add64; +get_bigint_from_struct; +check_eq mxIntValue(5) diff --git a/tests/mx-rust/biguint.div.run b/tests/mx-rust/biguint.div.run new file mode 100644 index 0000000..4362fde --- /dev/null +++ b/tests/mx-rust/biguint.div.run @@ -0,0 +1,8 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +push 20u64; +push 3u64; +call BigUintTest.div; +get_bigint_from_struct; +check_eq mxIntValue(6) diff --git a/tests/mx-rust/biguint.div64.run b/tests/mx-rust/biguint.div64.run new file mode 100644 index 0000000..407701b --- /dev/null +++ b/tests/mx-rust/biguint.div64.run @@ -0,0 +1,8 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +push 20u64; +push 3u64; +call BigUintTest.div64; +get_bigint_from_struct; +check_eq mxIntValue(6) diff --git a/tests/mx-rust/biguint.eq.run b/tests/mx-rust/biguint.eq.run new file mode 100644 index 0000000..6d74ec7 --- /dev/null +++ b/tests/mx-rust/biguint.eq.run @@ -0,0 +1,26 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +set_named "self"; + +push_named "self"; +push 20u64; +push 30u64; +call BigUintTest.eq; +return_value; +check_eq false; + +push_named "self"; +push 30u64; +push 30u64; +call BigUintTest.eq; +return_value; +check_eq true; + +push_named "self"; +push 40u64; +push 30u64; +call BigUintTest.eq; +return_value; +check_eq false + diff --git a/tests/mx-rust/biguint.ge.run b/tests/mx-rust/biguint.ge.run new file mode 100644 index 0000000..8c591f4 --- /dev/null +++ b/tests/mx-rust/biguint.ge.run @@ -0,0 +1,26 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +set_named "self"; + +push_named "self"; +push 20u64; +push 30u64; +call BigUintTest.ge; +return_value; +check_eq false; + +push_named "self"; +push 30u64; +push 30u64; +call BigUintTest.ge; +return_value; +check_eq true; + +push_named "self"; +push 40u64; +push 30u64; +call BigUintTest.ge; +return_value; +check_eq true + diff --git a/tests/mx-rust/biguint.gt.run b/tests/mx-rust/biguint.gt.run new file mode 100644 index 0000000..d5b9536 --- /dev/null +++ b/tests/mx-rust/biguint.gt.run @@ -0,0 +1,26 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +set_named "self"; + +push_named "self"; +push 20u64; +push 30u64; +call BigUintTest.gt; +return_value; +check_eq false; + +push_named "self"; +push 30u64; +push 30u64; +call BigUintTest.gt; +return_value; +check_eq false; + +push_named "self"; +push 40u64; +push 30u64; +call BigUintTest.gt; +return_value; +check_eq true + diff --git a/tests/mx-rust/biguint.le.run b/tests/mx-rust/biguint.le.run new file mode 100644 index 0000000..9c14f53 --- /dev/null +++ b/tests/mx-rust/biguint.le.run @@ -0,0 +1,26 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +set_named "self"; + +push_named "self"; +push 20u64; +push 30u64; +call BigUintTest.le; +return_value; +check_eq true; + +push_named "self"; +push 30u64; +push 30u64; +call BigUintTest.le; +return_value; +check_eq true; + +push_named "self"; +push 40u64; +push 30u64; +call BigUintTest.le; +return_value; +check_eq false + diff --git a/tests/mx-rust/biguint.lt.run b/tests/mx-rust/biguint.lt.run new file mode 100644 index 0000000..09efe07 --- /dev/null +++ b/tests/mx-rust/biguint.lt.run @@ -0,0 +1,26 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +set_named "self"; + +push_named "self"; +push 20u64; +push 30u64; +call BigUintTest.lt; +return_value; +check_eq true; + +push_named "self"; +push 30u64; +push 30u64; +call BigUintTest.lt; +return_value; +check_eq false; + +push_named "self"; +push 40u64; +push 30u64; +call BigUintTest.lt; +return_value; +check_eq false + diff --git a/tests/mx-rust/biguint.mul.run b/tests/mx-rust/biguint.mul.run new file mode 100644 index 0000000..2153334 --- /dev/null +++ b/tests/mx-rust/biguint.mul.run @@ -0,0 +1,8 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +push 15u64; +push 3u64; +call BigUintTest.mul; +get_bigint_from_struct; +check_eq mxIntValue(45) diff --git a/tests/mx-rust/biguint.mul64.run b/tests/mx-rust/biguint.mul64.run new file mode 100644 index 0000000..db44954 --- /dev/null +++ b/tests/mx-rust/biguint.mul64.run @@ -0,0 +1,8 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +push 15u64; +push 3u64; +call BigUintTest.mul64; +get_bigint_from_struct; +check_eq mxIntValue(45) diff --git a/tests/mx-rust/biguint.ne.run b/tests/mx-rust/biguint.ne.run new file mode 100644 index 0000000..e49f403 --- /dev/null +++ b/tests/mx-rust/biguint.ne.run @@ -0,0 +1,26 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +set_named "self"; + +push_named "self"; +push 20u64; +push 30u64; +call BigUintTest.ne; +return_value; +check_eq true; + +push_named "self"; +push 30u64; +push 30u64; +call BigUintTest.ne; +return_value; +check_eq false; + +push_named "self"; +push 40u64; +push 30u64; +call BigUintTest.ne; +return_value; +check_eq true + diff --git a/tests/mx-rust/biguint.rs b/tests/mx-rust/biguint.rs new file mode 100644 index 0000000..9a36e4d --- /dev/null +++ b/tests/mx-rust/biguint.rs @@ -0,0 +1,73 @@ +#![no_std] + +#[allow(unused_imports)] +use multiversx_sc::imports::*; + +#[multiversx_sc::contract] +pub trait BigUintTest { + #[init] + fn init(&self) {} + + #[upgrade] + fn upgrade(&self) {} + + fn zero(&self) -> BigUint { + BigUint::zero() + } + + fn add(&self, a: u64, b: u64) -> BigUint { + BigUint::from(a) + BigUint::from(b) + } + + fn sub(&self, a: u64, b: u64) -> BigUint { + BigUint::from(a) - BigUint::from(b) + } + + fn mul(&self, a: u64, b: u64) -> BigUint { + BigUint::from(a) * BigUint::from(b) + } + + fn div(&self, a: u64, b: u64) -> BigUint { + BigUint::from(a) / BigUint::from(b) + } + + fn lt(&self, a: u64, b: u64) -> bool { + BigUint::from(a) < BigUint::from(b) + } + + fn le(&self, a: u64, b: u64) -> bool { + BigUint::from(a) <= BigUint::from(b) + } + + fn gt(&self, a: u64, b: u64) -> bool { + BigUint::from(a) > BigUint::from(b) + } + + fn ge(&self, a: u64, b: u64) -> bool { + BigUint::from(a) >= BigUint::from(b) + } + + fn eq(&self, a: u64, b: u64) -> bool { + BigUint::from(a) == BigUint::from(b) + } + + fn ne(&self, a: u64, b: u64) -> bool { + BigUint::from(a) != BigUint::from(b) + } + + fn add64(&self, a: u64, b: u64) -> BigUint { + BigUint::from(a) + b + } + + fn sub64(&self, a: u64, b: u64) -> BigUint { + BigUint::from(a) - b + } + + fn mul64(&self, a: u64, b: u64) -> BigUint { + BigUint::from(a) * b + } + + fn div64(&self, a: u64, b: u64) -> BigUint { + BigUint::from(a) / b + } +} diff --git a/tests/mx-rust/biguint.sub.run b/tests/mx-rust/biguint.sub.run new file mode 100644 index 0000000..6c43115 --- /dev/null +++ b/tests/mx-rust/biguint.sub.run @@ -0,0 +1,8 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +push 50u64; +push 3u64; +call BigUintTest.sub; +get_bigint_from_struct; +check_eq mxIntValue(47) diff --git a/tests/mx-rust/biguint.sub64.run b/tests/mx-rust/biguint.sub64.run new file mode 100644 index 0000000..0c619cf --- /dev/null +++ b/tests/mx-rust/biguint.sub64.run @@ -0,0 +1,8 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +push 50u64; +push 3u64; +call BigUintTest.sub64; +get_bigint_from_struct; +check_eq mxIntValue(47) diff --git a/tests/mx-rust/biguint.zero.run b/tests/mx-rust/biguint.zero.run new file mode 100644 index 0000000..9c16cd1 --- /dev/null +++ b/tests/mx-rust/biguint.zero.run @@ -0,0 +1,6 @@ +addAccount("Owner"); +setCallee("Owner"); +new BigUintTest; +call BigUintTest.zero; +get_bigint_from_struct; +check_eq mxIntValue(0)