|
1 | 1 | package eu.bittrade.libs.steemj.apis.network.broadcast; |
2 | 2 |
|
3 | 3 | import static org.hamcrest.MatcherAssert.assertThat; |
4 | | -import static org.hamcrest.Matchers.equalTo; |
| 4 | +import static org.hamcrest.Matchers.greaterThan; |
| 5 | +import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
| 6 | +import static org.hamcrest.Matchers.isEmptyOrNullString; |
| 7 | +import static org.hamcrest.Matchers.not; |
| 8 | +import static org.junit.Assert.assertFalse; |
5 | 9 |
|
6 | 10 | import java.util.ArrayList; |
| 11 | +import java.util.Arrays; |
7 | 12 |
|
8 | 13 | import org.junit.BeforeClass; |
9 | 14 | import org.junit.Test; |
10 | 15 | import org.junit.experimental.categories.Category; |
11 | 16 |
|
12 | 17 | import eu.bittrade.libs.steemj.BaseTransactionBroadcastIT; |
| 18 | +import eu.bittrade.libs.steemj.BaseTransactionalIT; |
13 | 19 | import eu.bittrade.libs.steemj.IntegrationTest; |
| 20 | +import eu.bittrade.libs.steemj.apis.follow.enums.FollowType; |
| 21 | +import eu.bittrade.libs.steemj.apis.follow.models.operations.FollowOperation; |
| 22 | +import eu.bittrade.libs.steemj.apis.network.broadcast.model.BroadcastTransactionSynchronousReturn; |
14 | 23 | import eu.bittrade.libs.steemj.base.models.AccountName; |
15 | | -import eu.bittrade.libs.steemj.base.models.Asset; |
16 | | -import eu.bittrade.libs.steemj.base.models.Permlink; |
| 24 | +import eu.bittrade.libs.steemj.base.models.DynamicGlobalProperty; |
17 | 25 | import eu.bittrade.libs.steemj.base.models.SignedTransaction; |
18 | | -import eu.bittrade.libs.steemj.base.models.TimePointSec; |
19 | | -import eu.bittrade.libs.steemj.base.models.operations.CommentOptionsOperation; |
| 26 | +import eu.bittrade.libs.steemj.base.models.operations.CustomJsonOperation; |
20 | 27 | import eu.bittrade.libs.steemj.base.models.operations.Operation; |
21 | 28 | import eu.bittrade.libs.steemj.communication.CommunicationHandler; |
22 | | -import eu.bittrade.libs.steemj.enums.AssetSymbolType; |
23 | 29 | import eu.bittrade.libs.steemj.exceptions.SteemCommunicationException; |
24 | 30 | import eu.bittrade.libs.steemj.exceptions.SteemInvalidTransactionException; |
25 | 31 | import eu.bittrade.libs.steemj.exceptions.SteemResponseException; |
@@ -49,38 +55,100 @@ public static void init() throws SteemCommunicationException { |
49 | 55 |
|
50 | 56 | /** |
51 | 57 | * Test the |
52 | | - * {@link eu.bittrade.libs.steemj.apis.network.broadcast.NetworkBroadcastApi#broadcastTransactionWithCallback(CommunicationHandler, eu.bittrade.libs.steemj.base.models.SignedTransaction)} |
| 58 | + * {@link eu.bittrade.libs.steemj.apis.network.broadcast.NetworkBroadcastApi#broadcastTransactionSynchronous(CommunicationHandler, eu.bittrade.libs.steemj.base.models.SignedTransaction)} |
53 | 59 | * method. |
54 | 60 | * |
55 | 61 | * @throws SteemCommunicationException |
56 | 62 | * If a communication error occurs. |
57 | 63 | * @throws SteemResponseException |
58 | 64 | * If the response is an error. |
59 | 65 | * @throws SteemInvalidTransactionException |
| 66 | + * If the transaction is not valid. |
60 | 67 | */ |
61 | 68 | @Category({ IntegrationTest.class }) |
62 | 69 | @Test |
63 | | - public void testBroadcastTransactionWithCallback() |
| 70 | + public void testBroadcastTransactionSynchronous() |
64 | 71 | throws SteemCommunicationException, SteemResponseException, SteemInvalidTransactionException { |
65 | | - AccountName author = new AccountName("dez1337"); |
66 | | - Permlink permlink = new Permlink("steemj-v0-2-4-has-been-released-update-9"); |
67 | | - boolean allowVotes = true; |
68 | | - boolean allowCurationRewards = true; |
69 | | - short percentSteemDollars = (short) 10000; |
70 | | - Asset maxAcceptedPayout = new Asset(1000000000, AssetSymbolType.SBD); |
| 72 | + ArrayList<AccountName> requiredPostingAuths = new ArrayList<>(); |
| 73 | + requiredPostingAuths.add(BaseTransactionalIT.DEZ_ACCOUNT_NAME); |
71 | 74 |
|
72 | | - CommentOptionsOperation commentOptionsOperation = new CommentOptionsOperation(author, permlink, |
73 | | - maxAcceptedPayout, percentSteemDollars, allowVotes, allowCurationRewards, null); |
| 75 | + String id = "follow"; |
| 76 | + String json = (new FollowOperation(BaseTransactionalIT.DEZ_ACCOUNT_NAME, |
| 77 | + BaseTransactionalIT.STEEMJ_ACCOUNT_NAME, Arrays.asList(FollowType.BLOG))).toJson(); |
| 78 | + |
| 79 | + CustomJsonOperation customJsonOperation = new CustomJsonOperation(null, requiredPostingAuths, id, json); |
74 | 80 |
|
75 | 81 | ArrayList<Operation> operations = new ArrayList<>(); |
76 | | - operations.add(commentOptionsOperation); |
| 82 | + operations.add(customJsonOperation); |
| 83 | + |
| 84 | + DynamicGlobalProperty globalProperties = steemJ.getDynamicGlobalProperties(); |
| 85 | + |
| 86 | + signedTransaction = new SignedTransaction(globalProperties.getHeadBlockId(), operations, null); |
| 87 | + |
| 88 | + signedTransaction.sign(); |
| 89 | + |
| 90 | + BroadcastTransactionSynchronousReturn result = NetworkBroadcastApi |
| 91 | + .broadcastTransactionSynchronous(COMMUNICATION_HANDLER, signedTransaction); |
| 92 | + |
| 93 | + assertThat(result.getBlockNum(), greaterThan(0)); |
| 94 | + assertThat(result.getTrxNum(), greaterThanOrEqualTo(0)); |
| 95 | + assertThat(result.getId().toString(), not(isEmptyOrNullString())); |
| 96 | + assertFalse(result.isExpired()); |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Test the |
| 101 | + * {@link eu.bittrade.libs.steemj.apis.network.broadcast.NetworkBroadcastApi#broadcastTransaction(CommunicationHandler, eu.bittrade.libs.steemj.base.models.SignedTransaction)} |
| 102 | + * method. |
| 103 | + * |
| 104 | + * @throws SteemCommunicationException |
| 105 | + * If a communication error occurs. |
| 106 | + * @throws SteemResponseException |
| 107 | + * If the response is an error. |
| 108 | + * @throws SteemInvalidTransactionException |
| 109 | + * If the transaction is not valid. |
| 110 | + */ |
| 111 | + @Category({ IntegrationTest.class }) |
| 112 | + @Test |
| 113 | + public void testBroadcastTransaction() |
| 114 | + throws SteemCommunicationException, SteemResponseException, SteemInvalidTransactionException { |
| 115 | + ArrayList<AccountName> requiredPostingAuths = new ArrayList<>(); |
| 116 | + requiredPostingAuths.add(BaseTransactionalIT.STEEMJ_ACCOUNT_NAME); |
77 | 117 |
|
78 | | - signedTransaction = new SignedTransaction(REF_BLOCK_NUM, REF_BLOCK_PREFIX, new TimePointSec(EXPIRATION_DATE), |
79 | | - operations, null); |
| 118 | + String id = "follow"; |
| 119 | + String json = (new FollowOperation(BaseTransactionalIT.STEEMJ_ACCOUNT_NAME, |
| 120 | + BaseTransactionalIT.DEZ_ACCOUNT_NAME, Arrays.asList(FollowType.BLOG))).toJson(); |
80 | 121 |
|
81 | | - NetworkBroadcastApi.broadcastTransactionSynchronous(COMMUNICATION_HANDLER, signedTransaction); |
82 | | - NetworkBroadcastApi.broadcastTransactionWithCallback(COMMUNICATION_HANDLER, signedTransaction); |
| 122 | + CustomJsonOperation customJsonOperation = new CustomJsonOperation(null, requiredPostingAuths, id, json); |
83 | 123 |
|
84 | | - assertThat(1, equalTo(2)); |
| 124 | + ArrayList<Operation> operations = new ArrayList<>(); |
| 125 | + operations.add(customJsonOperation); |
| 126 | + |
| 127 | + DynamicGlobalProperty globalProperties = steemJ.getDynamicGlobalProperties(); |
| 128 | + |
| 129 | + signedTransaction = new SignedTransaction(globalProperties.getHeadBlockId(), operations, null); |
| 130 | + |
| 131 | + signedTransaction.sign(); |
| 132 | + |
| 133 | + NetworkBroadcastApi.broadcastTransaction(COMMUNICATION_HANDLER, signedTransaction); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * Test the |
| 138 | + * {@link eu.bittrade.libs.steemj.apis.network.broadcast.NetworkBroadcastApi#broadcastBlock(CommunicationHandler, eu.bittrade.libs.steemj.base.models.SignedBlock)} |
| 139 | + * method. |
| 140 | + * |
| 141 | + * @throws SteemCommunicationException |
| 142 | + * If a communication error occurs. |
| 143 | + * @throws SteemResponseException |
| 144 | + * If the response is an error. |
| 145 | + * @throws SteemInvalidTransactionException |
| 146 | + * If the transaction is not valid. |
| 147 | + */ |
| 148 | + @Category({ IntegrationTest.class }) |
| 149 | + @Test |
| 150 | + public void testBroadcastBlock() |
| 151 | + throws SteemCommunicationException, SteemResponseException, SteemInvalidTransactionException { |
| 152 | + // TODO: Implement. |
85 | 153 | } |
86 | 154 | } |
0 commit comments