public async Task SecretLockTransactionTest() { var signer = KeyPair.CreateFromPrivateKey(Config.PrivateKeyMain); var secretHash = new byte[64]; var digest = new Sha3Digest(512); digest.BlockUpdate("5D8BEBBE80D7EA3B0088E59308D8671099781429".FromHex(), 0, "5D8BEBBE80D7EA3B0088E59308D8671099781429".FromHex().Length); digest.DoFinal(secretHash, 0); var transaction = SecretLockTransaction.Create( NetworkType.Types.MIJIN_TEST, 3, Deadline.CreateHours(2), 0, new Mosaic(new MosaicId("nem:xem"), 10000000), 10000, HashType.Types.SHA3_512, secretHash.ToHexLower(), Address.CreateFromPublicKey("5D8BEBBE80D7EA3B0088E59308D8671099781429B449A0BBCA6D950A709BA068", NetworkType.Types.MIJIN_TEST) ) .SignWith(signer); listener.ConfirmedTransactionsGiven(Address.CreateFromPublicKey(transaction.Signer, NetworkType.Types.MIJIN_TEST)) .Subscribe( e => { Assert.Fail("Success"); }); await new TransactionHttp(host).Announce(transaction); var status = await listener.TransactionStatus(Address.CreateFromPublicKey(signer.PublicKeyString, NetworkType.Types.MIJIN_TEST)).Where(e => e.Hash == transaction.Hash).Take(1); Assert.AreEqual("Failure_Lock_Hash_Exists", status.Status); }
public async Task Should_Announce_Secret_Hash() { var bob = await Fixture.GenerateAccountWithCurrency(10000); /* var priv_bob = await Fixture.GenerateAccountWithCurrency(10000); * * var priv_alice = await Fixture.GenerateAccountWithCurrency(10000);*/ var alice = await Fixture.GenerateAccountWithCurrency(10000); Log.WriteLine($"Bob Account Address: {bob.Address.Plain} \r\n Private Key: {bob.PrivateKey} \r\n Public Key {bob.PublicKey}"); Log.WriteLine($"Alice Account Address: {alice.Address.Plain} \r\n Private Key: {alice.PrivateKey} \r\n Public Key {alice.PublicKey}"); //var secret = "8ee6bb9dc6dbf61db3b2c01086976ffac34b0820c1a4c8aeff92f59c33cb49fa"; byte[] Seed = new byte[40]; // Random random = new Random(); // random.NextBytes(Seed); var secret_ = CryptoUtils.Sha3_256(Seed); var secret = BitConverter.ToString(secret_); secret = secret.Replace("-", "").ToLowerInvariant(); var csprng = new RNGCryptoServiceProvider(); csprng.GetNonZeroBytes(Seed); var proof = BitConverter.ToString(Seed); //var proof = string.Join("", Seed.Select(b => b.ToString("X"))); proof = proof.Replace("-", ""); /* Random rdm = new Random(); * string proof = string.Empty; * int num; * * for (int i = 0; i < 4; i++) * { * num = rdm.Next(0, int.MaxValue); * proof += num.ToString("X4"); * }*/ //proof = Hex.EncodeHexString(Seed); //proof = proof.Replace("-", ""); //Random random = new Random(); //string proof = random.NextBytes(secretSeed); var nonce = MosaicNonce.CreateRandom(); var mosaic_id = MosaicId.CreateFromNonce(nonce, Fixture.GenerationHash); var secretLockTransaction = SecretLockTransaction.Create(Deadline.Create(), // NetworkCurrencyMosaic.CreateRelative(10), new Mosaic(mosaic_id, 10), (ulong)100, HashType.SHA3_256, secret, bob.Address, NetworkType.TEST_NET); /* var aggregateTransaction = AggregateTransaction.CreateComplete( * Deadline.Create(), * new List<Transaction> * { * secretLockTransaction.ToAggregate(Fixture.SeedAccount.PublicAccount) * }, * Fixture.NetworkType);*/ var signedTransaction = alice.Sign(secretLockTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(signedTransaction); Log.WriteLine($"Going to announce transaction {signedTransaction.Hash}"); Log.WriteLine($"Proof {proof}"); Log.WriteLine($"Secret {secret}"); Log.WriteLine($"proof length {proof.DecodeHexString().Length}"); await Fixture.SiriusClient.TransactionHttp.Announce(signedTransaction); //Log.WriteLine($"Going to announce Secret Lock Transaction {signedTransaction.Hash}"); var secretProofTransaction = SecretProofTransaction.Create( Deadline.Create(), HashType.SHA3_256, Recipient.From(bob.Address), secret, secret, Fixture.NetworkType ); var secretProofsignedTransaction = bob.Sign(secretProofTransaction, Fixture.GenerationHash); Fixture.WatchForFailure(secretProofsignedTransaction); Thread.Sleep(8000); // Log.WriteLine($"Going to announce Secret Lock Transaction {signedTransaction.Hash}"); // var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(3000)); // var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(alice.Address).Take(1).Timeout(TimeSpan.FromSeconds(3000)); await Fixture.SiriusClient.TransactionHttp.Announce(secretProofsignedTransaction); Thread.Sleep(8000); Log.WriteLine($"Going to announce Secret Proof Transaction {secretProofsignedTransaction.Hash}"); //var tx = Fixture.SiriusWebSocketClient.Listener.ConfirmedTransactionsGiven(alice.Address).Take(1).Timeout(TimeSpan.FromSeconds(3000)); //var secretLocksignedTransaction = account.Sign(secretLockTransaction, Fixture.GenerationHash); // await Fixture.SiriusClient.TransactionHttp.Announce(secretLocksignedTransaction); // var result = await tx; // Log.WriteLine($"Request confirmed with transaction {result.TransactionInfo.Hash}"); }