Skip to content

Commit

Permalink
Update MethodTests.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
TeknoPT committed Sep 22, 2023
1 parent 90ce27f commit 3d10a29
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Library/tests/Contracts/MethodTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using NUnit.Framework;
using Phantasma.Core.Cryptography;
using Phantasma.Core.Domain;
Expand Down Expand Up @@ -135,4 +136,51 @@ public fetch(val:number) : number

Assert.IsTrue(result == 11);
}

[Test]
public void TestContractLengthViaParamNameWithNumber()
{
var sourceCode =
@"
contract test {
import Call;
private countLetters(x1:string) : number
{
if ( x1.length() == 0 ) {
return 0;
}
return x1.length();
}
public fetch(val:string) : number
{
return this.countLetters(val);
}
}";

var parser = new TombLangCompiler();
var contract = parser.Process(sourceCode).First();

var storage = new Dictionary<byte[], byte[]>(new ByteArrayComparer());

TestVM vm;

var keys = PhantasmaKeys.Generate();

// call fetch
var fetch = contract.abi.FindMethod("fetch");
Assert.IsNotNull(fetch);

vm = new TestVM(contract, storage, fetch);
vm.Stack.Push(VMObject.FromObject("helloworld"));
var state = vm.Execute();
Assert.IsTrue(state == ExecutionState.Halt);
var result = vm.Stack.Pop().AsNumber();
BigInteger expected = "helloworld".Length;


Assert.AreEqual(expected, result);
}
}

0 comments on commit 3d10a29

Please sign in to comment.