Skip to content

Commit

Permalink
added receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-tran committed Aug 18, 2019
1 parent 89954d9 commit 3cf2cc2
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 25 deletions.
213 changes: 201 additions & 12 deletions src/ProximaX.Sirius.Chain.Sdk.Tests/E2E/E2EMultiSigAccountTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace ProximaX.Sirius.Chain.Sdk.Tests.E2E
{
//[Collection("E2ETestFixtureCollection")]
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
public class E2EMultiSigAccountTests: IClassFixture<E2ETestFixture>
public class E2EMultiSigAccountTests : IClassFixture<E2ETestFixture>
{
private readonly E2ETestFixture _fixture;

Expand All @@ -28,6 +28,7 @@ public class E2EMultiSigAccountTests: IClassFixture<E2ETestFixture>
private Account cosignatory1;
private Account cosignatory2;
private Account cosignatory3;
private Account cosignatory4;
private Account account;
private NetworkType networkType;
private string networkGenerationHash;
Expand All @@ -40,8 +41,9 @@ public E2EMultiSigAccountTests(E2ETestFixture fixture, ITestOutputHelper output)
cosignatory1 = _fixture.Cosignatory1;
cosignatory2 = _fixture.Cosignatory2;
cosignatory3 = _fixture.Cosignatory3;
cosignatory4 = _fixture.Cosignatory4;
networkType = _fixture.Client.NetworkHttp.GetNetworkType().Wait();
networkGenerationHash = _fixture.Client.BlockHttp.GetGenerationHash().Wait();
networkGenerationHash = _fixture.Client.BlockHttp.GetGenerationHash().Wait();
//Initialise().Wait();
// multiMultisigAccount = Account.GenerateNewAccount(_fixture.Client.NetworkHttp.GetNetworkType().Wait());
//Account.GenerateNewAccount(_fixture.Client.NetworkHttp.GetNetworkType().Wait());
Expand All @@ -50,7 +52,7 @@ public E2EMultiSigAccountTests(E2ETestFixture fixture, ITestOutputHelper output)
// cosig3 = Account.GenerateNewAccount(_fixture.Client.NetworkHttp.GetNetworkType().Wait());
}



/*
[Fact, Priority(0)]
Expand Down Expand Up @@ -250,7 +252,7 @@ public async Task Should_Transfer_From_MultiSig1_Of_2_Aggregate()
public async Task Should_Convert_Account_To_1to2_MultiSig()
{
// Get current network type


// Create an account to be converted to multisig with some money
// var account = await _fixture.GenerateAccountAndSendSomeMoney(100);
Expand Down Expand Up @@ -292,7 +294,7 @@ public async Task Should_Convert_Account_To_1to2_MultiSig()
},
networkType);



// Sign the aggregate transaction using the private key of the multisig account
var signedTransaction = account.Sign(aggregateTransaction, networkGenerationHash);
Expand Down Expand Up @@ -353,7 +355,7 @@ public async Task Should_Convert_Account_To_1to2_MultiSig()

//var aggBondedTx = await aggBondedConfirmed;


//if(aggBondedTx.IsConfirmed())
// {
// Cosign the aggregate transaction with cosignatory1
Expand Down Expand Up @@ -441,15 +443,61 @@ public async Task Should_Convert_Account_To_1to2_MultiSig()
}

[Fact, Priority(1)]
public async Task Should_Send_Money_From_Multsi_From_1To2_Cosignatory()
{
var recipient = Account.GenerateNewAccount(networkType);

_output.WriteLine($"MultiSig account {account}");
_output.WriteLine($"Recipient account {recipient}");
_output.WriteLine($"Cosignatory1 account {cosignatory1}");
var transferTransaction = TransferTransaction.Create(
Deadline.Create(),
recipient.Address,
new List<Mosaic> { NetworkCurrencyMosaic.CreateAbsolute(10) },
PlainMessage.Create("sending 10 prx.xpx"),
networkType);

var aggregateTransaction = AggregateTransaction.CreateComplete(
Deadline.Create(),
new List<Transaction> {
transferTransaction.ToAggregate(account.PublicAccount)
},
networkType);

var signedTransaction = cosignatory1.Sign(aggregateTransaction, networkGenerationHash);

var cosignatory1ConfirmedTx = _fixture.WebSocket.Listener
.ConfirmedTransactionsGiven(cosignatory1.Address).Take(1)
.Timeout(TimeSpan.FromSeconds(2000));

await _fixture.Client.TransactionHttp.Announce(signedTransaction);

var result = await cosignatory1ConfirmedTx;

Thread.Sleep(2000);

if(result.IsConfirmed())
{
var recipientAccountInfo = await _fixture.Client.AccountHttp.GetAccountInfo(recipient.Address);
_output.WriteLine($"Recipient info {recipientAccountInfo}");


recipientAccountInfo.Mosaics.Should().HaveCount(1);
recipientAccountInfo.Mosaics[0].Amount.Should().Be(10);
}

}

[Fact, Priority(2)]
public async Task Should_Convert_Account_To_2to2_MultiSig()
{
//account = Account.CreateFromPrivateKey("6681DC3BBEEEDF213160A27DDCA551B7AC8DC3BB79B8BDC059DD2CEA7B2E9C42", networkType);
//cosignatory1 = Account.CreateFromPrivateKey("3B2B0AE238CF78E65E0F0B7110F7B4E73B8C56AB0282F98D22A39BB67D127609", networkType);
//account = Account.CreateFromPrivateKey("6681DC3BBEEEDF213160A27DDCA551B7AC8DC3BB79B8BDC059DD2CEA7B2E9C42", networkType);
//cosignatory1 = Account.CreateFromPrivateKey("3B2B0AE238CF78E65E0F0B7110F7B4E73B8C56AB0282F98D22A39BB67D127609", networkType);

_output.WriteLine($"MultiSig account {account}");
_output.WriteLine($"Cosignatory1 account {cosignatory1}");


// Define a modify multisig account transaction to increase the minAprovalDelta in one unit
var modifyMultisigAccountTransaction = ModifyMultisigAccountTransaction.Create(
Deadline.Create(),
Expand All @@ -476,9 +524,9 @@ public async Task Should_Convert_Account_To_2to2_MultiSig()
var cosignatory1ConfirmedTx = _fixture.WebSocket.Listener
.ConfirmedTransactionsGiven(cosignatory1.Address).Take(1)
.Timeout(TimeSpan.FromSeconds(2000));

_output.WriteLine($"Going to announce aggregate completed transaction {signedTransaction.Hash}");

// Announce the hash lock transaction
await _fixture.Client.TransactionHttp.Announce(signedTransaction);

Expand All @@ -493,8 +541,149 @@ public async Task Should_Convert_Account_To_2to2_MultiSig()
multiSigAcc.MinApproval.Should().Be(2);
multiSigAcc.MinRemoval.Should().Be(1);
multiSigAcc.Cosignatories.Should().HaveCount(2);



}

[Fact, Priority(3)]
public async Task Should_Add_Cosignatory()
{

//account = Account.CreateFromPrivateKey("EC2A2026948C28BAA8CDF061D7768397E0080E8E7913DE2ABF3066D2D4DCA0A6", networkType);
//cosignatory1 = Account.CreateFromPrivateKey("39E80B97D7528E59997AA11DD499B42EFEE2E85BE372179CE88E622541F5DEDB", networkType);
//cosignatory2 = Account.CreateFromPrivateKey("38296AE980C69D24D018D119C40A00D3894713F3A2F7BB27E495671D3D8C2E6D", networkType);
// cosignatory3 = Account.CreateFromPrivateKey("748EFC97BBB2EC5A304DAD9B712B6540A8AD6A3EC2C60BDB03D20F6DB34513AD", networkType);

Thread.Sleep(4000);
_output.WriteLine($"MultiSig account {account}");
_output.WriteLine($"Cosignatory1 account {cosignatory1}");
_output.WriteLine($"Cosignatory3 account {cosignatory3}");

var multisigCosignatoryModification = new MultisigCosignatoryModification(MultisigCosignatoryModificationType.ADD, cosignatory3.PublicAccount);

// Define a modify multisig account transaction to increase the minAprovalDelta in one unit
var modifyMultisigAccountTransaction = ModifyMultisigAccountTransaction.Create(
Deadline.Create(),
0,
0,
new List<MultisigCosignatoryModification>
{
multisigCosignatoryModification
},
networkType);

// Wrap the modify multisig account transaction in an aggregate transaction,
// attaching the multisig public key as the signer
var aggregateTransaction = AggregateTransaction.CreateBonded(
Deadline.Create(),
new List<Transaction>
{
modifyMultisigAccountTransaction.ToAggregate(account.PublicAccount)
},
networkType
);

var signedTransaction = cosignatory1.Sign(aggregateTransaction, networkGenerationHash);

// Before sending an aggregate bonded transaction,
// the future multisig account needs to lock at least 10 cat.currency.
// This transaction is required to prevent network spamming and ensure that
// the inner transactions are cosigned
var hashLockTransaction = HashLockTransaction.Create(
Deadline.Create(),
NetworkCurrencyMosaic.CreateRelative(10),
(ulong)700,
signedTransaction,
networkType);


var hashLockTransactionSigned = cosignatory1.Sign(hashLockTransaction, networkGenerationHash);

/*var hashLocktx = _fixture.WebSocket.Listener
.ConfirmedTransactionsGiven(cosignatory1.Address).Take(1)
.Timeout(TimeSpan.FromSeconds(500));*/

_fixture.WatchForFailure(hashLockTransactionSigned);

_output.WriteLine($"Going to announce hash lock transaction {hashLockTransactionSigned.Hash}");

// Announce the hash lock transaction
await _fixture.Client.TransactionHttp.Announce(hashLockTransactionSigned);

Thread.Sleep(8000);

// Wait for the hash lock transaction to be confirmed
//var hashLockConfirmed = await hashLocktx;

// if (hashLockConfirmed.TransactionInfo.Hash == hashLockTransactionSigned.Hash)
// {

_fixture.WatchForFailure(signedTransaction);

_output.WriteLine($"Going to announce aggregate bonded transaction {signedTransaction.Hash}");

// Announce the AnnounceAggregateBonded transaction
await _fixture.Client.TransactionHttp.AnnounceAggregateBonded(signedTransaction);

// sleep for await
Thread.Sleep(8000);

/*var cosignatory3Cosigned = _fixture.WebSocket.Listener
.CosignatureAdded(cosignatory3.Address).Take(1)
.Timeout(TimeSpan.FromSeconds(2000));*/
Thread.Sleep(2000);
var cosignatory3AggTxs = await _fixture.Client.AccountHttp.AggregateBondedTransactions(cosignatory3.PublicAccount);
foreach (AggregateTransaction tx in cosignatory3AggTxs)
{
if (!tx.IsSignedByAccount(cosignatory3.PublicAccount))
{
var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, cosignatory3);

_fixture.WatchForFailure(cosignatureSignedTransaction);

await _fixture.Client.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

Thread.Sleep(2000);
//var resultTx = await cosignatory1Cosigned;

//_output.WriteLine($"Completed Cosign 1 {resultTx}");

}
}

/*var cosignatory2Cosigned = _fixture.WebSocket.Listener
.CosignatureAdded(cosignatory2.Address).Take(1)
.Timeout(TimeSpan.FromSeconds(2000));*/
Thread.Sleep(2000);
var cosignatory2AggTxs = await _fixture.Client.AccountHttp.AggregateBondedTransactions(cosignatory2.PublicAccount);
foreach (AggregateTransaction tx in cosignatory2AggTxs)
{
if (!tx.IsSignedByAccount(cosignatory2.PublicAccount))
{
var cosignatureSignedTransaction = CosignAggregateBondedTransaction(tx, cosignatory2);

_fixture.WatchForFailure(cosignatureSignedTransaction);

await _fixture.Client.TransactionHttp.AnnounceAggregateBondedCosignatureAsync(cosignatureSignedTransaction);

Thread.Sleep(2000);
//var resultTx = await cosignatory1Cosigned;

//_output.WriteLine($"Completed Cosign 1 {resultTx}");

}
}

Thread.Sleep(10000);
// verify the account is multisig
var multiSigAcc = await _fixture.Client.AccountHttp.GetMultisigAccountInfo(account.Address);
_output.WriteLine($"Multisig account {multiSigAcc}");

multiSigAcc.IsMultisig.Should().BeTrue();
multiSigAcc.Cosignatories.Should().HaveCount(3);

_output.WriteLine($"Completed");
// }
}

private CosignatureSignedTransaction CosignAggregateBondedTransaction(AggregateTransaction transaction, Account account)
Expand Down
5 changes: 4 additions & 1 deletion src/ProximaX.Sirius.Chain.Sdk.Tests/E2E/E2ETestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class E2ETestFixture : IDisposable

public Account Cosignatory3 { get; set; }

public Account Cosignatory4 { get; set; }

public E2ETestFixture()
{
InitializeFixture().Wait();
Expand All @@ -51,9 +53,10 @@ private async Task InitializeFixture()
SeedAccount = await GetSeedAccount();
MultiSigAccount = await GenerateAccountAndSendSomeMoney(100);
var networkType = await Client.NetworkHttp.GetNetworkType();
Cosignatory1 = Account.GenerateNewAccount(networkType);
Cosignatory1 = await GenerateAccountAndSendSomeMoney(100);
Cosignatory2 = Account.GenerateNewAccount(networkType);
Cosignatory3 = Account.GenerateNewAccount(networkType);
Cosignatory4 = Account.GenerateNewAccount(networkType);
//set default timeout
DefaultTimeout = TimeSpan.FromSeconds(100);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,22 @@ public async Task Should_Return_The_Generation_Hash()
generationHash.Should().BeEquivalentTo("7C175E628183275364959BEA811897111C5AFCA014DD991FC0D87AD7C16BB41F");
}
}


[Fact]
public async Task Should_Return_The_Receipt_From_Block()
{
using (var httpTest = new HttpTest())
{
var fakeJson =
TestHelper.LoadJsonFileToObject(@"Testdata\\Block\\GetReceiptFromBlock.json");

httpTest.RespondWithJson(fakeJson);

var receipts = await _blockchainHttp.GetBlockReceipts(2830);
receipts.MosaicResolutionStatements.Should().HaveCountGreaterThan(0);
receipts.TransactionStatement.Should().HaveCountGreaterThan(0);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"transactionStatements": [
{
"height": [
13186,
2830,
0
],
"source": {
Expand All @@ -19,13 +19,48 @@
231112638
],
"amount": [
0,
100,
0
]
},
{
"version": 1,
"type": 20803,
"mosaicId": [
481110499,
231112638
],
"amount": [
100,
0
]
}
]
}
],
"addressResolutionStatements": [],
"mosaicResolutionStatements": []
"mosaicResolutionStatements": [
{
"height": [
2830,
0
],
"unresolved": [
2855265186,
2553603033
],
"resolutionEntries": [
{
"source": {
"primaryId": 1,
"secondaryId": 0
},
"resolved": [
3796365617,
55345548
]
}
]
}
]
}
Loading

0 comments on commit 3cf2cc2

Please sign in to comment.