public void TestMessageTransactionBuilder() { var builder = new MessageTransactionBuilder(); builder.NID = 2; builder.PrivateKey = PrivateKey.Random(); builder.To = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269"; builder.StepLimit = NumericsHelper.ICX2Loop("0.1"); builder.Value = NumericsHelper.ICX2Loop("1"); builder.Timestamp = 100000000000; builder.Message = "testMessage"; var tx = builder.Build(); Assert.True(Signer.Verify(tx.Signature, tx.Hash, tx.From)); var hashSource = new Dictionary <string, object>() { ["version"] = "0x3", ["nid"] = "0x2", ["from"] = Addresser.Create(builder.PrivateKey).ToString(), ["to"] = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["stepLimit"] = "0x16345785d8a0000", ["value"] = "0xde0b6b3a7640000", ["timestamp"] = "0x174876e800", ["dataType"] = "message", ["data"] = new Bytes(Encoding.UTF8.GetBytes(builder.Message)).ToString() }; var hash = Hasher.Digest(hashSource); Assert.AreEqual(tx.Hash, hash); }
public void Test_RPCInvalidRequestException() { var txBuilder = new TransactionBuilder(); txBuilder.PrivateKey = PrivateKey.Random(); txBuilder.To = "hx0000000000000000000000000000000000000000"; txBuilder.StepLimit = 100000000; txBuilder.NID = 2; txBuilder.Value = 0; var tx = txBuilder.Build(); var gendTransactin = new SendTransaction(Consts.ApiUrl.TestNet); Assert.ThrowsAsync(typeof(RPCInvalidRequestException), async() => await gendTransactin.Invoke(tx)); }
public void TestCallTransactionBuilder() { var builder = new CallTransactionBuilder(); builder.NID = 2; builder.PrivateKey = PrivateKey.Random(); builder.To = "cx54f7853dc6481b670caf69c5a27c7c8fe5be8269"; builder.StepLimit = NumericsHelper.ICX2Loop("0.10000000000"); builder.Value = NumericsHelper.ICX2Loop("1.00000"); builder.Timestamp = 100000000000; builder.Method = "transfer"; builder.Params["to"] = new ExternalAddress("hx54f7853dc6481b670caf69c5a27c7c8fe5be8269"); builder.Params["value"] = new BigInteger(10); var tx = builder.Build(); Assert.True(Signer.Verify(tx.Signature, tx.Hash, tx.From)); var hashSource = new Dictionary <string, object>() { ["version"] = "0x3", ["nid"] = "0x2", ["from"] = Addresser.Create(builder.PrivateKey).ToString(), ["to"] = "cx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["stepLimit"] = "0x16345785d8a0000", ["value"] = "0xde0b6b3a7640000", ["timestamp"] = "0x174876e800", ["dataType"] = "call", ["data"] = new Dictionary <string, object>() { ["method"] = "transfer", ["params"] = new Dictionary <string, object>() { ["to"] = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["value"] = "0xa" } } }; var hash = Hasher.Digest(hashSource); Assert.AreEqual(tx.Hash, hash); }
public void TestDelopyTransaction() { var builder = new DeployTransactionBuilder(); builder.NID = 2; builder.PrivateKey = PrivateKey.Random(); builder.To = "cx0000000000000000000000000000000000000000"; builder.StepLimit = NumericsHelper.ICX2Loop("0.1"); builder.Timestamp = 100000000000; builder.ContentType = "application/zip"; builder.Content = new Bytes("0x1212121212"); builder.Params["to"] = new ExternalAddress("hx54f7853dc6481b670caf69c5a27c7c8fe5be8269"); builder.Params["value"] = new BigInteger(10); var tx = builder.Build(); Assert.True(Signer.Verify(tx.Signature, tx.Hash, tx.From)); var hashSource = new Dictionary <string, object>() { ["version"] = "0x3", ["nid"] = "0x2", ["from"] = Addresser.Create(builder.PrivateKey).ToString(), ["to"] = "cx0000000000000000000000000000000000000000", ["stepLimit"] = "0x16345785d8a0000", ["timestamp"] = "0x174876e800", ["dataType"] = "deploy", ["data"] = new Dictionary <string, object>() { ["contentType"] = "application/zip", ["content"] = "0x1212121212", ["params"] = new Dictionary <string, object>() { ["to"] = "hx54f7853dc6481b670caf69c5a27c7c8fe5be8269", ["value"] = "0xa" } } }; var hash = Hasher.Digest(hashSource); Assert.AreEqual(tx.Hash, hash); }
public void Test_KeyStore() { Random random = new Random(); byte[] passwordBytes = new byte[random.Next() % 256]; random.NextBytes(passwordBytes); string password = Convert.ToBase64String(passwordBytes); PrivateKey privateKey = PrivateKey.Random(); ExternalAddress address = Addresser.Create(privateKey); KeyStore keyStore = KeyStore.Create(privateKey, address); string fileName = keyStore.Store(password); keyStore = KeyStore.Load(password, fileName); File.Delete(fileName); Assert.AreEqual(privateKey, keyStore.PrivateKey); Assert.AreEqual(address, keyStore.Address); }
public async Task Test_Call() { var getScoreApi = new GetScoreApi(Consts.ApiUrl.TestNet); var scoreApi = await getScoreApi.Invoke("cx0000000000000000000000000000000000000001"); Console.WriteLine(JsonConvert.SerializeObject(scoreApi, Formatting.Indented)); var privateKey = PrivateKey.Random(); var address = Addresser.Create(privateKey); var call = new Call(Consts.ApiUrl.TestNet); var result = await call.Invoke( address, "cx0000000000000000000000000000000000000001", "isDeployer", ("address", address) ); // 0x0 Console.WriteLine(result); var call0 = new Call <bool>(Consts.ApiUrl.TestNet); var result0 = await call0.Invoke( address, "cx0000000000000000000000000000000000000001", "isDeployer", ("address", address) ); // false Console.WriteLine(result0); var call1 = new Call <IsDeployerRequestParam, bool>(Consts.ApiUrl.TestNet); var result1 = await call1.Invoke( address, "cx0000000000000000000000000000000000000001", "isDeployer", new IsDeployerRequestParam() { Address = address } ); // false Console.WriteLine(result1); var call2 = new Call <BigInteger>(Consts.ApiUrl.TestNet); var result2 = await call2.Invoke( address, "cx0000000000000000000000000000000000000001", "getStepPrice" ); Console.WriteLine(result2); var call3 = new Call <GetRevisionResponseParam>(Consts.ApiUrl.TestNet); var result3 = await call3.Invoke( address, "cx0000000000000000000000000000000000000001", "getRevision" ); Console.WriteLine(result3.Code); Console.WriteLine(result3.Name); var call4 = new Call <Dictionary <string, BigInteger> >(Consts.ApiUrl.TestNet); var result4 = await call4.Invoke( address, "cx0000000000000000000000000000000000000001", "getStepCosts" ); Console.WriteLine(JsonConvert.SerializeObject(result4)); }
public static Wallet Create() { var privateKey = PrivateKey.Random(); return(Create(privateKey)); }