From 80048208d1b12452167972652c5a15f6dc726673 Mon Sep 17 00:00:00 2001 From: CalDescent Date: Thu, 15 Dec 2022 12:14:42 +0000 Subject: [PATCH] Moved some test sponsorship utility methods to AccountUtils, so they can be used in other test classes too. --- .../test/SelfSponsorshipAlgoV1Tests.java | 205 +++++++----------- .../org/qortal/test/common/AccountUtils.java | 57 ++++- 2 files changed, 131 insertions(+), 131 deletions(-) diff --git a/src/test/java/org/qortal/test/SelfSponsorshipAlgoV1Tests.java b/src/test/java/org/qortal/test/SelfSponsorshipAlgoV1Tests.java index 91628dd3..397a1bbe 100644 --- a/src/test/java/org/qortal/test/SelfSponsorshipAlgoV1Tests.java +++ b/src/test/java/org/qortal/test/SelfSponsorshipAlgoV1Tests.java @@ -50,8 +50,8 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob"); // Bob self sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Mint blocks @@ -73,7 +73,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -139,18 +139,18 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount dilbertAccount = Common.getTestAccount(repository, "dilbert"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Chloe sponsors 10 accounts - List chloeSponsees = generateSponsorshipRewardShares(repository, chloeAccount, 10); - List chloeSponseesOnlineAccounts = toRewardShares(repository, chloeAccount, chloeSponsees); + List chloeSponsees = AccountUtils.generateSponsorshipRewardShares(repository, chloeAccount, 10); + List chloeSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, chloeAccount, chloeSponsees); onlineAccounts.addAll(chloeSponseesOnlineAccounts); // Dilbert sponsors 5 accounts - List dilbertSponsees = generateSponsorshipRewardShares(repository, dilbertAccount, 5); - List dilbertSponseesOnlineAccounts = toRewardShares(repository, dilbertAccount, dilbertSponsees); + List dilbertSponsees = AccountUtils.generateSponsorshipRewardShares(repository, dilbertAccount, 5); + List dilbertSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, dilbertAccount, dilbertSponsees); onlineAccounts.addAll(dilbertSponseesOnlineAccounts); // Mint blocks @@ -172,7 +172,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -270,20 +270,20 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount dilbertAccount = Common.getTestAccount(repository, "dilbert"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccountsAliceSigner.addAll(bobSponseesOnlineAccounts); onlineAccountsBobSigner.addAll(bobSponseesOnlineAccounts); // Chloe sponsors 10 accounts - List chloeSponsees = generateSponsorshipRewardShares(repository, chloeAccount, 10); - List chloeSponseesOnlineAccounts = toRewardShares(repository, chloeAccount, chloeSponsees); + List chloeSponsees = AccountUtils.generateSponsorshipRewardShares(repository, chloeAccount, 10); + List chloeSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, chloeAccount, chloeSponsees); onlineAccountsAliceSigner.addAll(chloeSponseesOnlineAccounts); onlineAccountsBobSigner.addAll(chloeSponseesOnlineAccounts); // Dilbert sponsors 5 accounts - List dilbertSponsees = generateSponsorshipRewardShares(repository, dilbertAccount, 5); - List dilbertSponseesOnlineAccounts = toRewardShares(repository, dilbertAccount, dilbertSponsees); + List dilbertSponsees = AccountUtils.generateSponsorshipRewardShares(repository, dilbertAccount, 5); + List dilbertSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, dilbertAccount, dilbertSponsees); onlineAccountsAliceSigner.addAll(dilbertSponseesOnlineAccounts); onlineAccountsBobSigner.addAll(dilbertSponseesOnlineAccounts); @@ -306,7 +306,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccountsAliceSigner.addAll(bobSponseeSelfShares); onlineAccountsBobSigner.addAll(bobSponseeSelfShares); @@ -382,14 +382,14 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob"); // Alice sponsors 10 accounts - List aliceSponsees = generateSponsorshipRewardShares(repository, aliceAccount, 10); - List aliceSponseesOnlineAccounts = toRewardShares(repository, aliceAccount, aliceSponsees); + List aliceSponsees = AccountUtils.generateSponsorshipRewardShares(repository, aliceAccount, 10); + List aliceSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, aliceAccount, aliceSponsees); onlineAccountsAliceSigner.addAll(aliceSponseesOnlineAccounts); onlineAccountsBobSigner.addAll(aliceSponseesOnlineAccounts); // Bob sponsors 9 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 9); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 9); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccountsAliceSigner.addAll(bobSponseesOnlineAccounts); onlineAccountsBobSigner.addAll(bobSponseesOnlineAccounts); @@ -412,7 +412,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, aliceSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List aliceSponseeSelfShares = generateSelfShares(repository, aliceSponsees); + List aliceSponseeSelfShares = AccountUtils.generateSelfShares(repository, aliceSponsees); onlineAccountsAliceSigner.addAll(aliceSponseeSelfShares); onlineAccountsBobSigner.addAll(aliceSponseeSelfShares); @@ -483,18 +483,18 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount dilbertAccount = Common.getTestAccount(repository, "dilbert"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Chloe sponsors 10 accounts - List chloeSponsees = generateSponsorshipRewardShares(repository, chloeAccount, 10); - List chloeSponseesOnlineAccounts = toRewardShares(repository, chloeAccount, chloeSponsees); + List chloeSponsees = AccountUtils.generateSponsorshipRewardShares(repository, chloeAccount, 10); + List chloeSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, chloeAccount, chloeSponsees); onlineAccounts.addAll(chloeSponseesOnlineAccounts); // Dilbert sponsors 5 accounts - List dilbertSponsees = generateSponsorshipRewardShares(repository, dilbertAccount, 5); - List dilbertSponseesOnlineAccounts = toRewardShares(repository, dilbertAccount, dilbertSponsees); + List dilbertSponsees = AccountUtils.generateSponsorshipRewardShares(repository, dilbertAccount, 5); + List dilbertSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, dilbertAccount, dilbertSponsees); onlineAccounts.addAll(dilbertSponseesOnlineAccounts); // Mint blocks @@ -516,7 +516,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -597,14 +597,14 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob"); // Alice sponsors 10 accounts - List aliceSponsees = generateSponsorshipRewardShares(repository, aliceAccount, 10); - List aliceSponseesOnlineAccounts = toRewardShares(repository, aliceAccount, aliceSponsees); + List aliceSponsees = AccountUtils.generateSponsorshipRewardShares(repository, aliceAccount, 10); + List aliceSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, aliceAccount, aliceSponsees); onlineAccounts.addAll(aliceSponseesOnlineAccounts); onlineAccounts.addAll(aliceSponseesOnlineAccounts); // Bob sponsors 9 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 9); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 9); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); onlineAccounts.addAll(bobSponseesOnlineAccounts); @@ -627,7 +627,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, aliceSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List aliceSponseeSelfShares = generateSelfShares(repository, aliceSponsees); + List aliceSponseeSelfShares = AccountUtils.generateSelfShares(repository, aliceSponsees); onlineAccounts.addAll(aliceSponseeSelfShares); // Mint blocks (Bob is the signer) @@ -706,13 +706,13 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount chloeAccount = Common.getTestAccount(repository, "chloe"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Chloe sponsors 10 accounts - List chloeSponsees = generateSponsorshipRewardShares(repository, chloeAccount, 10); - List chloeSponseesOnlineAccounts = toRewardShares(repository, chloeAccount, chloeSponsees); + List chloeSponsees = AccountUtils.generateSponsorshipRewardShares(repository, chloeAccount, 10); + List chloeSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, chloeAccount, chloeSponsees); onlineAccounts.addAll(chloeSponseesOnlineAccounts); // Mint blocks @@ -728,7 +728,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { block = BlockMinter.mintTestingBlock(repository, onlineAccounts.toArray(new PrivateKeyAccount[0])); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -744,22 +744,22 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertEquals(19, (int) block.getBlockData().getHeight()); // Bob creates a valid reward share transaction - assertEquals(Transaction.ValidationResult.OK, createRandomRewardShare(repository, bobAccount)); + assertEquals(Transaction.ValidationResult.OK, AccountUtils.createRandomRewardShare(repository, bobAccount)); // Mint a block, so the algo runs block = BlockMinter.mintTestingBlock(repository, onlineAccounts.toArray(new PrivateKeyAccount[0])); // Bob can no longer create a reward share transaction - assertEquals(Transaction.ValidationResult.ACCOUNT_CANNOT_REWARD_SHARE, createRandomRewardShare(repository, bobAccount)); + assertEquals(Transaction.ValidationResult.ACCOUNT_CANNOT_REWARD_SHARE, AccountUtils.createRandomRewardShare(repository, bobAccount)); // ... but Chloe still can - assertEquals(Transaction.ValidationResult.OK, createRandomRewardShare(repository, chloeAccount)); + assertEquals(Transaction.ValidationResult.OK, AccountUtils.createRandomRewardShare(repository, chloeAccount)); // Orphan last block BlockUtils.orphanLastBlock(repository); // Bob creates another valid reward share transaction - assertEquals(Transaction.ValidationResult.OK, createRandomRewardShare(repository, bobAccount)); + assertEquals(Transaction.ValidationResult.OK, AccountUtils.createRandomRewardShare(repository, bobAccount)); // Run orphan check - this can't be in afterTest() because some tests access the live db Common.orphanCheck(); @@ -780,13 +780,13 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob"); // Alice sponsors 10 accounts - List aliceSponsees = generateSponsorshipRewardShares(repository, aliceAccount, 10); - List aliceSponseesOnlineAccounts = toRewardShares(repository, aliceAccount, aliceSponsees); + List aliceSponsees = AccountUtils.generateSponsorshipRewardShares(repository, aliceAccount, 10); + List aliceSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, aliceAccount, aliceSponsees); onlineAccounts.addAll(aliceSponseesOnlineAccounts); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Mint blocks @@ -802,7 +802,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { block = BlockMinter.mintTestingBlock(repository, onlineAccounts.toArray(new PrivateKeyAccount[0])); // Generate self shares so the sponsees can start minting - List aliceSponseeSelfShares = generateSelfShares(repository, aliceSponsees); + List aliceSponseeSelfShares = AccountUtils.generateSelfShares(repository, aliceSponsees); onlineAccounts.addAll(aliceSponseeSelfShares); // Mint blocks @@ -818,7 +818,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertEquals(19, (int) block.getBlockData().getHeight()); // Alice creates a valid reward share transaction - assertEquals(Transaction.ValidationResult.OK, createRandomRewardShare(repository, aliceAccount)); + assertEquals(Transaction.ValidationResult.OK, AccountUtils.createRandomRewardShare(repository, aliceAccount)); // Mint a block, so the algo runs block = BlockMinter.mintTestingBlock(repository, onlineAccounts.toArray(new PrivateKeyAccount[0])); @@ -830,16 +830,16 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertEquals(0, (int) new Account(repository, aliceAccount.getAddress()).getLevel()); // Alice can no longer create a reward share transaction - assertEquals(Transaction.ValidationResult.ACCOUNT_CANNOT_REWARD_SHARE, createRandomRewardShare(repository, aliceAccount)); + assertEquals(Transaction.ValidationResult.ACCOUNT_CANNOT_REWARD_SHARE, AccountUtils.createRandomRewardShare(repository, aliceAccount)); // ... but Bob still can - assertEquals(Transaction.ValidationResult.OK, createRandomRewardShare(repository, bobAccount)); + assertEquals(Transaction.ValidationResult.OK, AccountUtils.createRandomRewardShare(repository, bobAccount)); // Orphan last block BlockUtils.orphanLastBlock(repository); // Alice creates another valid reward share transaction - assertEquals(Transaction.ValidationResult.OK, createRandomRewardShare(repository, aliceAccount)); + assertEquals(Transaction.ValidationResult.OK, AccountUtils.createRandomRewardShare(repository, aliceAccount)); // Run orphan check - this can't be in afterTest() because some tests access the live db Common.orphanCheck(); @@ -867,8 +867,8 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount dilbertAccount = Common.getTestAccount(repository, "dilbert"); // Dilbert sponsors 10 accounts - List dilbertSponsees = generateSponsorshipRewardShares(repository, dilbertAccount, 10); - List dilbertSponseesOnlineAccounts = toRewardShares(repository, dilbertAccount, dilbertSponsees); + List dilbertSponsees = AccountUtils.generateSponsorshipRewardShares(repository, dilbertAccount, 10); + List dilbertSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, dilbertAccount, dilbertSponsees); onlineAccounts.addAll(dilbertSponseesOnlineAccounts); // Mint blocks @@ -921,8 +921,8 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount dilbertAccount = Common.getTestAccount(repository, "dilbert"); // Dilbert sponsors 10 accounts - List dilbertSponsees = generateSponsorshipRewardShares(repository, dilbertAccount, 10); - List dilbertSponseesOnlineAccounts = toRewardShares(repository, dilbertAccount, dilbertSponsees); + List dilbertSponsees = AccountUtils.generateSponsorshipRewardShares(repository, dilbertAccount, 10); + List dilbertSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, dilbertAccount, dilbertSponsees); onlineAccounts.addAll(dilbertSponseesOnlineAccounts); // Mint blocks @@ -935,7 +935,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { block = BlockMinter.mintTestingBlock(repository, onlineAccounts.toArray(new PrivateKeyAccount[0])); // Generate self shares so the sponsees can start minting - List dilbertSponseeSelfShares = generateSelfShares(repository, dilbertSponsees); + List dilbertSponseeSelfShares = AccountUtils.generateSelfShares(repository, dilbertSponsees); onlineAccounts.addAll(dilbertSponseeSelfShares); // Mint blocks @@ -985,8 +985,8 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount dilbertAccount = Common.getTestAccount(repository, "dilbert"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Chloe sponsors THE SAME 10 accounts @@ -996,12 +996,12 @@ public class SelfSponsorshipAlgoV1Tests extends Common { TransactionUtils.signAndImportValid(repository, transactionData, chloeAccount); } List chloeSponsees = new ArrayList<>(bobSponsees); - List chloeSponseesOnlineAccounts = toRewardShares(repository, chloeAccount, chloeSponsees); + List chloeSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, chloeAccount, chloeSponsees); onlineAccounts.addAll(chloeSponseesOnlineAccounts); // Dilbert sponsors 5 accounts - List dilbertSponsees = generateSponsorshipRewardShares(repository, dilbertAccount, 5); - List dilbertSponseesOnlineAccounts = toRewardShares(repository, dilbertAccount, dilbertSponsees); + List dilbertSponsees = AccountUtils.generateSponsorshipRewardShares(repository, dilbertAccount, 5); + List dilbertSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, dilbertAccount, dilbertSponsees); onlineAccounts.addAll(dilbertSponseesOnlineAccounts); // Mint blocks @@ -1023,7 +1023,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -1108,8 +1108,8 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Mint blocks @@ -1128,7 +1128,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -1220,8 +1220,8 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Mint blocks @@ -1240,7 +1240,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -1316,8 +1316,8 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Mint blocks @@ -1336,7 +1336,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -1392,8 +1392,8 @@ public class SelfSponsorshipAlgoV1Tests extends Common { PrivateKeyAccount bobAccount = Common.getTestAccount(repository, "bob"); // Bob sponsors 10 accounts - List bobSponsees = generateSponsorshipRewardShares(repository, bobAccount, 10); - List bobSponseesOnlineAccounts = toRewardShares(repository, bobAccount, bobSponsees); + List bobSponsees = AccountUtils.generateSponsorshipRewardShares(repository, bobAccount, 10); + List bobSponseesOnlineAccounts = AccountUtils.toRewardShares(repository, bobAccount, bobSponsees); onlineAccounts.addAll(bobSponseesOnlineAccounts); // Mint blocks @@ -1412,7 +1412,7 @@ public class SelfSponsorshipAlgoV1Tests extends Common { assertTrue(new Account(repository, bobSponsee.getAddress()).getLevel() > 0); // Generate self shares so the sponsees can start minting - List bobSponseeSelfShares = generateSelfShares(repository, bobSponsees); + List bobSponseeSelfShares = AccountUtils.generateSelfShares(repository, bobSponsees); onlineAccounts.addAll(bobSponseeSelfShares); // Mint blocks @@ -1543,61 +1543,6 @@ public class SelfSponsorshipAlgoV1Tests extends Common { return new TransferPrivsTransaction(repository, transactionData); } - private static List generateSponsorshipRewardShares(Repository repository, PrivateKeyAccount sponsorAccount, int accountsCount) throws DataException { - final int sharePercent = 0; - Random random = new Random(); - - List sponsees = new ArrayList<>(); - for (int i = 0; i < accountsCount; i++) { - - // Generate random sponsee account - byte[] randomPrivateKey = new byte[32]; - random.nextBytes(randomPrivateKey); - PrivateKeyAccount sponseeAccount = new PrivateKeyAccount(repository, randomPrivateKey); - sponsees.add(sponseeAccount); - - // Create reward-share - TransactionData transactionData = AccountUtils.createRewardShare(repository, sponsorAccount, sponseeAccount, sharePercent, fee); - TransactionUtils.signAndImportValid(repository, transactionData, sponsorAccount); - } - - return sponsees; - } - - private static Transaction.ValidationResult createRandomRewardShare(Repository repository, PrivateKeyAccount account) throws DataException { - // Bob attempts to create a reward share transaction - byte[] randomPrivateKey = new byte[32]; - new Random().nextBytes(randomPrivateKey); - PrivateKeyAccount sponseeAccount = new PrivateKeyAccount(repository, randomPrivateKey); - TransactionData transactionData = AccountUtils.createRewardShare(repository, account, sponseeAccount, 0, fee); - return TransactionUtils.signAndImport(repository, transactionData, account); - } - - private static List generateSelfShares(Repository repository, List accounts) throws DataException { - final int sharePercent = 0; - - for (PrivateKeyAccount account : accounts) { - // Create reward-share - TransactionData transactionData = AccountUtils.createRewardShare(repository, account, account, sharePercent, 0L); - TransactionUtils.signAndImportValid(repository, transactionData, account); - } - - return toRewardShares(repository, null, accounts); - } - - private static List toRewardShares(Repository repository, PrivateKeyAccount parentAccount, List accounts) { - List rewardShares = new ArrayList<>(); - - for (PrivateKeyAccount account : accounts) { - PrivateKeyAccount sponsor = (parentAccount != null) ? parentAccount : account; - byte[] rewardSharePrivateKey = sponsor.getRewardSharePrivateKey(account.getPublicKey()); - PrivateKeyAccount rewardShareAccount = new PrivateKeyAccount(repository, rewardSharePrivateKey); - rewardShares.add(rewardShareAccount); - } - - return rewardShares; - } - private boolean areAllAccountsPresentInBlock(List accounts, Block block) throws DataException { for (PrivateKeyAccount bobSponsee : accounts) { boolean foundOnlineAccountInBlock = false; diff --git a/src/test/java/org/qortal/test/common/AccountUtils.java b/src/test/java/org/qortal/test/common/AccountUtils.java index c31cd85e..bdfd124b 100644 --- a/src/test/java/org/qortal/test/common/AccountUtils.java +++ b/src/test/java/org/qortal/test/common/AccountUtils.java @@ -8,7 +8,6 @@ import java.util.*; import com.google.common.primitives.Longs; import org.qortal.account.PrivateKeyAccount; -import org.qortal.block.BlockChain; import org.qortal.crypto.Crypto; import org.qortal.crypto.Qortal25519Extras; import org.qortal.data.network.OnlineAccountData; @@ -19,6 +18,7 @@ import org.qortal.data.transaction.TransactionData; import org.qortal.group.Group; import org.qortal.repository.DataException; import org.qortal.repository.Repository; +import org.qortal.transaction.Transaction; import org.qortal.transform.Transformer; import org.qortal.utils.Amounts; @@ -86,6 +86,61 @@ public class AccountUtils { return rewardSharePrivateKey; } + public static List generateSponsorshipRewardShares(Repository repository, PrivateKeyAccount sponsorAccount, int accountsCount) throws DataException { + final int sharePercent = 0; + Random random = new Random(); + + List sponsees = new ArrayList<>(); + for (int i = 0; i < accountsCount; i++) { + + // Generate random sponsee account + byte[] randomPrivateKey = new byte[32]; + random.nextBytes(randomPrivateKey); + PrivateKeyAccount sponseeAccount = new PrivateKeyAccount(repository, randomPrivateKey); + sponsees.add(sponseeAccount); + + // Create reward-share + TransactionData transactionData = AccountUtils.createRewardShare(repository, sponsorAccount, sponseeAccount, sharePercent, fee); + TransactionUtils.signAndImportValid(repository, transactionData, sponsorAccount); + } + + return sponsees; + } + + public static Transaction.ValidationResult createRandomRewardShare(Repository repository, PrivateKeyAccount account) throws DataException { + // Bob attempts to create a reward share transaction + byte[] randomPrivateKey = new byte[32]; + new Random().nextBytes(randomPrivateKey); + PrivateKeyAccount sponseeAccount = new PrivateKeyAccount(repository, randomPrivateKey); + TransactionData transactionData = createRewardShare(repository, account, sponseeAccount, 0, fee); + return TransactionUtils.signAndImport(repository, transactionData, account); + } + + public static List generateSelfShares(Repository repository, List accounts) throws DataException { + final int sharePercent = 0; + + for (PrivateKeyAccount account : accounts) { + // Create reward-share + TransactionData transactionData = createRewardShare(repository, account, account, sharePercent, 0L); + TransactionUtils.signAndImportValid(repository, transactionData, account); + } + + return toRewardShares(repository, null, accounts); + } + + public static List toRewardShares(Repository repository, PrivateKeyAccount parentAccount, List accounts) { + List rewardShares = new ArrayList<>(); + + for (PrivateKeyAccount account : accounts) { + PrivateKeyAccount sponsor = (parentAccount != null) ? parentAccount : account; + byte[] rewardSharePrivateKey = sponsor.getRewardSharePrivateKey(account.getPublicKey()); + PrivateKeyAccount rewardShareAccount = new PrivateKeyAccount(repository, rewardSharePrivateKey); + rewardShares.add(rewardShareAccount); + } + + return rewardShares; + } + public static Map> getBalances(Repository repository, long... assetIds) throws DataException { Map> balances = new HashMap<>();