static void Main(string[] args) { MySmartContract contract = new MySmartContract() { ContractId = new Guid().ToString(), ContractName = "TestContract" }; Console.WriteLine(string.Format(" ContractAddr: {0};\n ContractId: {1};\n ContractName: {2}", contract.ContractAddress, contract.ContractId, contract.ContractName)); Console.WriteLine("-----------------------------"); contract.InitializeDelegates(); //NOTE: GAS CONTROLS DURATION OF EXECUTION IN THIS DEMO // "Gas" is measured in CPU Cycles... int gas = 5000; //multiplied internally by 1,000,000 cycles //YardStick is passed into DurationLimiter, representing the maximum duration allowed until all tasks are cancelled. int yardStick = 1000000000; //in cycles CancellationTokenSource tokenSource = new CancellationTokenSource(); var taskDelegates = Task.Run(() => contract.Execute(gas)); taskDelegates.ContinueWith((cancelThis) => { tokenSource.Cancel(); }); contract.ExecuteAndMonitor(Task.Run(async() => await contract.DurationLimiter(tokenSource, yardStick)), gas, tokenSource).Wait(); Console.Read(); }
public static MySmartContract.Student create(Int32 id, string name, Int32 balance) { BigInteger sid = (BigInteger)id; BigInteger sbalance = (BigInteger)balance; MySmartContract.Student stu = (MySmartContract.Student)MySmartContract.Main("create", sid, "liu", sbalance); return(stu); }
public void TestDelete() { MySmartContract.Student stu = TestHelper.create(1, "liu", 100); bool delete = (bool)MySmartContract.Main("delete", "liu"); Assert.AreEqual(true, delete); // 0 balance BigInteger balance = (BigInteger)MySmartContract.Main("balance", "liu"); Assert.AreEqual(0, balance); }
public void TestBalance() { // remove all records bool delete = (bool)MySmartContract.Main("delete", "liu"); Assert.AreEqual(true, delete); // 0 balance BigInteger balance = (BigInteger)MySmartContract.Main("balance", "liu"); Assert.AreEqual(0, balance); // create account MySmartContract.Student stu = TestHelper.create(1, "liu", 100); Assert.AreEqual(100, stu.balance); BigInteger balance2 = (BigInteger)MySmartContract.Main("balance", "liu"); Assert.AreEqual(100, balance2); }