Skip to content

Commit a3968e1

Browse files
Seulgi Kimsgkim126
authored andcommitted
Disable the transaction with the Order
However, you can enable it by setting an environment variable `ENABLE_ORDER=true`, and they are enabled in tests
1 parent 7a601cd commit a3968e1

File tree

6 files changed

+2920
-43
lines changed

6 files changed

+2920
-43
lines changed

core/src/codechain_machine.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ use crate::transaction::{SignedTransaction, UnverifiedTransaction};
3030

3131
pub struct CodeChainMachine {
3232
params: CommonParams,
33+
is_order_disabled: bool,
3334
}
3435

3536
impl CodeChainMachine {
3637
pub fn new(params: CommonParams) -> Self {
3738
CodeChainMachine {
3839
params,
40+
is_order_disabled: is_order_disabled(),
3941
}
4042
}
4143

@@ -71,7 +73,7 @@ impl CodeChainMachine {
7173
}
7274
.into())
7375
}
74-
p.verify_basic(self.params())?;
76+
p.verify_basic(self.params(), self.is_order_disabled)?;
7577

7678
Ok(())
7779
}
@@ -260,6 +262,19 @@ impl CodeChainMachine {
260262
}
261263
}
262264

265+
fn is_order_disabled() -> bool {
266+
#[cfg(test)]
267+
const DEFAULT_ORDER_DISABLED: bool = false;
268+
#[cfg(not(test))]
269+
const DEFAULT_ORDER_DISABLED: bool = true;
270+
let var = std::env::var("ENABLE_ORDER");
271+
match var.as_ref().map(|x| x.trim()) {
272+
Ok(value) => !value.parse::<bool>().unwrap(),
273+
Err(std::env::VarError::NotPresent) => DEFAULT_ORDER_DISABLED,
274+
Err(err) => unreachable!("{:?}", err),
275+
}
276+
}
277+
263278
impl Machine for CodeChainMachine {
264279
type Header = Header;
265280
type LiveBlock = ExecutedBlock;

core/src/transaction.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl UnverifiedTransaction {
133133
}
134134

135135
/// Verify basic signature params. Does not attempt signer recovery.
136-
pub fn verify_basic(&self, params: &CommonParams) -> Result<(), SyntaxError> {
136+
pub fn verify_basic(&self, params: &CommonParams, is_order_disabled: bool) -> Result<(), SyntaxError> {
137137
if self.network_id != params.network_id {
138138
return Err(SyntaxError::InvalidNetworkId(self.network_id))
139139
}
@@ -146,6 +146,7 @@ impl UnverifiedTransaction {
146146
params.max_asset_scheme_metadata_size,
147147
params.max_transfer_metadata_size,
148148
params.max_text_content_size,
149+
is_order_disabled,
149150
)
150151
}
151152
}

test/src/e2e.long/orders.test.ts

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ describe("orders", function() {
2626
let node: CodeChain;
2727

2828
before(async function() {
29-
node = new CodeChain();
29+
node = new CodeChain({
30+
env: {
31+
ENABLE_ORDER: "true"
32+
}
33+
});
3034
await node.start();
3135
});
3236

@@ -119,7 +123,7 @@ describe("orders", function() {
119123
await node.sdk.rpc.chain.sendSignedTransaction(signed);
120124
expect.fail();
121125
} catch (e) {
122-
expect(e).is.similarTo(ERROR.INVALID_ORDER_ASSET_TYPES);
126+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
123127
}
124128
});
125129
});
@@ -711,9 +715,7 @@ describe("orders", function() {
711715
await node.sdk.rpc.chain.sendSignedTransaction(signed);
712716
expect.fail();
713717
} catch (e) {
714-
expect(e).is.similarTo(
715-
ERROR.INCONSISTENT_TRANSACTION_IN_OUT_WITH_ORDERS
716-
);
718+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
717719
}
718720
});
719721

@@ -781,7 +783,7 @@ describe("orders", function() {
781783
await node.sdk.rpc.chain.sendSignedTransaction(signed);
782784
expect.fail();
783785
} catch (e) {
784-
expect(e).is.similarTo(ERROR.INVALID_SPENT_QUANTITY);
786+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
785787
}
786788
});
787789

@@ -849,9 +851,7 @@ describe("orders", function() {
849851
await node.sdk.rpc.chain.sendSignedTransaction(signed);
850852
expect.fail();
851853
} catch (e) {
852-
expect(e).is.similarTo(
853-
ERROR.INCONSISTENT_TRANSACTION_IN_OUT_WITH_ORDERS
854-
);
854+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
855855
}
856856
});
857857

@@ -926,9 +926,7 @@ describe("orders", function() {
926926
await node.sdk.rpc.chain.sendSignedTransaction(signed);
927927
expect.fail();
928928
} catch (e) {
929-
expect(e).is.similarTo(
930-
ERROR.INVALID_ORDER_LOCK_SCRIPT_HASH
931-
);
929+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
932930
}
933931
});
934932

@@ -999,7 +997,7 @@ describe("orders", function() {
999997
await node.sdk.rpc.chain.sendSignedTransaction(signed);
1000998
expect.fail();
1001999
} catch (e) {
1002-
expect(e).is.similarTo(ERROR.INVALID_ORDER_PARAMETERS);
1000+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
10031001
}
10041002
});
10051003

@@ -1073,9 +1071,7 @@ describe("orders", function() {
10731071
await node.sdk.rpc.chain.sendSignedTransaction(signed);
10741072
expect.fail();
10751073
} catch (e) {
1076-
expect(e).is.similarTo(
1077-
ERROR.INCONSISTENT_TRANSACTION_IN_OUT_WITH_ORDERS
1078-
);
1074+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
10791075
}
10801076
});
10811077

@@ -1149,9 +1145,7 @@ describe("orders", function() {
11491145
await node.sdk.rpc.chain.sendSignedTransaction(signed);
11501146
expect.fail();
11511147
} catch (e) {
1152-
expect(e).is.similarTo(
1153-
ERROR.INCONSISTENT_TRANSACTION_IN_OUT_WITH_ORDERS
1154-
);
1148+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
11551149
}
11561150
});
11571151

@@ -1231,9 +1225,7 @@ describe("orders", function() {
12311225
await node.sdk.rpc.chain.sendSignedTransaction(signed);
12321226
expect.fail();
12331227
} catch (e) {
1234-
expect(e).is.similarTo(
1235-
ERROR.INCONSISTENT_TRANSACTION_IN_OUT_WITH_ORDERS
1236-
);
1228+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
12371229
}
12381230
});
12391231

@@ -1303,7 +1295,7 @@ describe("orders", function() {
13031295
await node.sdk.rpc.chain.sendSignedTransaction(signed);
13041296
expect.fail();
13051297
} catch (e) {
1306-
expect(e).is.similarTo(ERROR.INVALID_ORIGIN_OUTPUTS);
1298+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
13071299
}
13081300
});
13091301

@@ -1372,7 +1364,7 @@ describe("orders", function() {
13721364
await node.sdk.rpc.chain.sendSignedTransaction(signed);
13731365
expect.fail();
13741366
} catch (e) {
1375-
expect(e).is.similarTo(ERROR.INVALID_ORIGIN_OUTPUTS);
1367+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
13761368
}
13771369
});
13781370

@@ -1743,9 +1735,7 @@ describe("orders", function() {
17431735
await node.sdk.rpc.chain.sendSignedTransaction(signed);
17441736
expect.fail();
17451737
} catch (e) {
1746-
expect(e).is.similarTo(
1747-
ERROR.INVALID_ORDER_ASSET_QUANTITIES
1748-
);
1738+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
17491739
}
17501740
});
17511741

@@ -1815,9 +1805,7 @@ describe("orders", function() {
18151805
await node.sdk.rpc.chain.sendSignedTransaction(signed);
18161806
expect.fail();
18171807
} catch (e) {
1818-
expect(e).is.similarTo(
1819-
ERROR.INVALID_ORDER_ASSET_QUANTITIES
1820-
);
1808+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
18211809
}
18221810
});
18231811

@@ -1885,7 +1873,7 @@ describe("orders", function() {
18851873
await node.sdk.rpc.chain.sendSignedTransaction(signed);
18861874
expect.fail();
18871875
} catch (e) {
1888-
expect(e).is.similarTo(ERROR.ORDER_EXPIRED);
1876+
expect(e).is.similarTo(ERROR.DISABLED_TRANSACTION);
18891877
}
18901878
});
18911879

0 commit comments

Comments
 (0)