创建地址上链订单,需要判断该地址是否已经是地址地址,如果是,不允许创建。
This commit is contained in:
1 parent
22735b80c0
commit
e5820e36e7
7 files changed
+102
-2
No files matched your search
@@ -36,6 +36,9 @@ public class RentalBusinessTest {
|
||||
private long wallet;
|
||||
private long node;
|
||||
private boolean proofAvailable = true;
|
||||
private boolean receiverActivated;
|
||||
private boolean activationRpcFailed;
|
||||
private int activationChecks;
|
||||
private static final String ADDRESS = "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf";
|
||||
private static final String OWNER = "TR7NHqjeKQxGTCi8q8ZY4pL8otgjLj6t";
|
||||
private final ObjectMapper json = new ObjectMapper();
|
||||
@@ -228,6 +231,17 @@ public class RentalBusinessTest {
|
||||
java.lang.reflect.Field envField = RentalOnchain.class.getDeclaredField("environment");
|
||||
envField.setAccessible(true);
|
||||
envField.set(onchain, environment);
|
||||
java.lang.reflect.Field activationField = RentalOnchain.class.getDeclaredField("chain");
|
||||
activationField.setAccessible(true);
|
||||
activationField.set(onchain, new RentalChain(json) {
|
||||
@Override public com.fasterxml.jackson.databind.JsonNode call(String network, String path, Map<String, Object> body) {
|
||||
assertEquals("/wallet/getaccount", path);
|
||||
assertEquals("NILE", network);
|
||||
activationChecks++;
|
||||
if (activationRpcFailed) { throw new IllegalStateException("controlled RPC failure"); }
|
||||
return json.valueToTree(receiverActivated ? map("address", ADDRESS, "balance", 0) : map());
|
||||
}
|
||||
});
|
||||
java.lang.reflect.Field onchainField = RentalOrders.class.getDeclaredField("onchain");
|
||||
onchainField.setAccessible(true);
|
||||
onchainField.set(orders, onchain);
|
||||
@@ -501,6 +515,32 @@ public class RentalBusinessTest {
|
||||
assertEquals(0, store.rows("SELECT id FROM rent_ledger WHERE order_id=? AND event_type='SUPPLIER_FEE'", orderId).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onchainRejectsActivatedOrUnknownWithoutOrderOrFrozenFunds() {
|
||||
BigDecimal before = amount(store.get("account", payer, false), "available_amount");
|
||||
for (boolean active : new boolean[] {true, false}) {
|
||||
receiverActivated = active;
|
||||
activationRpcFailed = !active;
|
||||
try {
|
||||
tx.execute(status -> orders.create(app, 10, onchainRequest("activation-reject")));
|
||||
fail("已激活或状态未知不允许创建");
|
||||
} catch (IllegalArgumentException | IllegalStateException expected) { /* 保持余额且无新订单 */ }
|
||||
assertEquals(before, amount(store.get("account", payer, false), "available_amount"));
|
||||
assertEquals(ZERO, amount(store.get("account", payer, false), "frozen_amount"));
|
||||
assertTrue(store.rows("SELECT id FROM rent_order WHERE merchant_order_no='activation-reject'").isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onchainIdempotentRetryStillWorksAfterReceiverActivated() {
|
||||
Map<String, Object> request = onchainRequest("activation-idempotent");
|
||||
Map<String, Object> original = tx.execute(status -> orders.create(app, 10, request));
|
||||
receiverActivated = true;
|
||||
Map<String, Object> retry = tx.execute(status -> orders.create(app, 10, request));
|
||||
assertEquals(number(original, "id"), number(retry, "id"));
|
||||
assertEquals(1, activationChecks);
|
||||
}
|
||||
|
||||
private Map<String, Object> onchainRequest(String merchant) {
|
||||
return map("order_type", "ADDRESS_ONCHAIN", "network", "NILE", "merchant_order_no", merchant,
|
||||
"receiver_address", ADDRESS, "expected_amount", "0.173457");
|
||||
|
||||
Reference in new issue
Block a user