Skip to content

Commit

Permalink
Migrate Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dev2-nomo committed Nov 11, 2024
1 parent ce5fa8c commit 797f0c1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
16 changes: 13 additions & 3 deletions lib/src/crypto/evm/entities/contract/contract_function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ sealed class ContractFunction implements ExternalContractFunctionMixin {
}) {
final opening = textSignature.indexOf("(");
final closing = textSignature.lastIndexOf(")");

if (opening == -1 || closing == -1) {
throw Exception("Invalid text signature: $textSignature");
}

final name = textSignature.substring(0, opening);
final params_s = extractParams(
textSignature.substring(opening + 1, closing),
Expand Down Expand Up @@ -147,7 +152,7 @@ sealed class ContractFunction implements ExternalContractFunctionMixin {
if (functionMap != null) {
final localResult = decodeRaw(data: data, functionMap: functionMap);

if (localResult is! UnknownContractFunction ||
if (localResult is! UnknownContractFunction &&
localResult is! NotDecodableContractFunction) {
return localResult;
}
Expand Down Expand Up @@ -181,8 +186,13 @@ sealed class ContractFunction implements ExternalContractFunctionMixin {

if (text_signarure == null) return UnknownContractFunction(data: data);

final function =
ContractFunction.fromTextSignature(textSignature: text_signarure);
final ExternalContractFunction function;
try {
function =
ContractFunction.fromTextSignature(textSignature: text_signarure);
} catch (e) {
return UnknownContractFunction(data: data);
}

return ContractFunction.decode(
data: data,
Expand Down
4 changes: 2 additions & 2 deletions test/ci/parsing/fetch_function_signature_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void main() {
contractFunction = await ContractFunction.decodeRawWithFetch(
data: dataString.hexToBytesWithPrefix,
functionMap: {
"0x3f8fc233": "cancelTrades((bytes32,uint256,uint256)[])",
"3f8fc233": "cancelTrades((bytes32,uint256,uint256)[])",
},
);

Expand Down Expand Up @@ -424,7 +424,7 @@ void main() {
final contractFunction = await ContractFunction.decodeRawWithFetch(
data: dataString.hexToBytesWithPrefix,
functionMap: {
"0x2289b18c": "g(uint256[][],string[])",
"2289b18c": "g(uint256[][],string[])",
},
);

Expand Down
7 changes: 6 additions & 1 deletion test/ci/parsing/reverse-hash-computation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import 'package:test/test.dart';
import 'package:walletkit_dart/walletkit_dart.dart';

void main() {
const functionMap = {"asd": "asd"};
const functionMap = {
"40c10f19": "mint(address,uint256)",
"6ba4c138": "claim(uint256[])",
"d63a47d6":
"mint(address _to,uint256 _amount,bytes[] _amounts,bool _collect,address[] _addresses,int256 _intParam)",
};
test('extract functionSignature mint from the transaction', () {
const String unsignedTxFromNomo = // from nomo.signEvmTransaction
"0xf86982074b8504a817c80083029810946d3be2fca848393ee83b2a1d65b312889cacf5e680b84440c10f1900000000000000000000000005870f1507d820212e921e1f39f14660336231d10000000000000000000000000000000000000000000000000000000000f34344";
Expand Down

0 comments on commit 797f0c1

Please sign in to comment.