Skip to content

Commit

Permalink
Introduce forks
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Sep 19, 2024
1 parent 767222e commit b140bd1
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 23 deletions.
8 changes: 6 additions & 2 deletions chainstate/test-suite/src/tests/chainstate_storage_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use common::{
output_value::OutputValue,
tokens::{make_token_id, NftIssuance, TokenAuxiliaryData, TokenIssuanceV0},
ChainstateUpgrade, ChangeTokenMetadataUriActivated, DataDepositFeeVersion, Destination,
HtlcActivated, NetUpgrades, OrdersActivated, OutPointSourceId, RewardDistributionVersion,
TokenIssuanceVersion, TokensFeeVersion, Transaction, TxInput, TxOutput, UtxoOutPoint,
FrozenTokensValidationVersion, HtlcActivated, NetUpgrades, OrdersActivated,
OutPointSourceId, RewardDistributionVersion, TokenIssuanceVersion, TokensFeeVersion,
Transaction, TxInput, TxOutput, UtxoOutPoint,
},
primitives::{Amount, Id, Idable},
};
Expand Down Expand Up @@ -121,6 +122,7 @@ fn store_fungible_token_v0(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -203,6 +205,7 @@ fn store_nft_v0(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -516,6 +519,7 @@ fn store_aux_data_from_issue_nft(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
6 changes: 5 additions & 1 deletion chainstate/test-suite/src/tests/fungible_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use chainstate::{
};
use chainstate_test_framework::{get_output_value, TestFramework, TransactionBuilder};
use common::chain::tokens::{Metadata, NftIssuanceV0, TokenIssuanceV0, TokenTransfer};
use common::chain::{RewardDistributionVersion, UtxoOutPoint};
use common::chain::{FrozenTokensValidationVersion, RewardDistributionVersion, UtxoOutPoint};
use common::primitives::{id, BlockHeight, Id};
use common::{
chain::{
Expand Down Expand Up @@ -59,6 +59,7 @@ fn make_test_framework_with_v0(rng: &mut (impl Rng + CryptoRng)) -> TestFramewor
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -966,6 +967,7 @@ fn no_v0_issuance_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -1032,6 +1034,7 @@ fn no_v0_transfer_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand All @@ -1044,6 +1047,7 @@ fn no_v0_transfer_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
2 changes: 2 additions & 0 deletions chainstate/test-suite/src/tests/fungible_tokens_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6072,6 +6072,7 @@ fn test_change_metadata_uri_activation(#[case] seed: Seed) {
common::chain::TokensFeeVersion::V1,
common::chain::DataDepositFeeVersion::V1,
common::chain::ChangeTokenMetadataUriActivated::No,
common::chain::FrozenTokensValidationVersion::V1,
common::chain::HtlcActivated::Yes,
common::chain::OrdersActivated::Yes,
),
Expand All @@ -6084,6 +6085,7 @@ fn test_change_metadata_uri_activation(#[case] seed: Seed) {
common::chain::TokensFeeVersion::V1,
common::chain::DataDepositFeeVersion::V1,
common::chain::ChangeTokenMetadataUriActivated::Yes,
common::chain::FrozenTokensValidationVersion::V1,
common::chain::HtlcActivated::Yes,
common::chain::OrdersActivated::Yes,
),
Expand Down
10 changes: 7 additions & 3 deletions chainstate/test-suite/src/tests/htlc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ use common::{
timelock::OutputTimeLock,
tokens::{make_token_id, TokenData, TokenIssuance, TokenTransfer},
AccountCommand, AccountNonce, ChainConfig, ChainstateUpgrade,
ChangeTokenMetadataUriActivated, DataDepositFeeVersion, Destination, HtlcActivated,
OrdersActivated, RewardDistributionVersion, TokenIssuanceVersion, TokensFeeVersion,
TxInput, TxOutput,
ChangeTokenMetadataUriActivated, DataDepositFeeVersion, Destination,
FrozenTokensValidationVersion, HtlcActivated, OrdersActivated, RewardDistributionVersion,
TokenIssuanceVersion, TokensFeeVersion, TxInput, TxOutput,
},
primitives::{Amount, Idable},
};
Expand Down Expand Up @@ -590,6 +590,7 @@ fn fork_activation(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::No,
OrdersActivated::No,
),
Expand All @@ -602,6 +603,7 @@ fn fork_activation(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::No,
),
Expand Down Expand Up @@ -693,6 +695,7 @@ fn spend_tokens(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand All @@ -705,6 +708,7 @@ fn spend_tokens(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
3 changes: 2 additions & 1 deletion chainstate/test-suite/src/tests/nft_burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use common::chain::{
HtlcActivated, OrdersActivated, RewardDistributionVersion, TokenIssuanceVersion,
TokensFeeVersion, TxInput, TxOutput,
};
use common::chain::{OutPointSourceId, UtxoOutPoint};
use common::chain::{FrozenTokensValidationVersion, OutPointSourceId, UtxoOutPoint};
use common::primitives::{Amount, BlockHeight, CoinOrTokenId, Idable};
use randomness::Rng;
use rstest::rstest;
Expand Down Expand Up @@ -218,6 +218,7 @@ fn no_v0_issuance_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
6 changes: 4 additions & 2 deletions chainstate/test-suite/src/tests/nft_issuance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use common::chain::{
signature::inputsig::InputWitness,
tokens::{is_rfc3986_valid_symbol, make_token_id, Metadata, NftIssuance, NftIssuanceV0},
Block, ChainstateUpgrade, ChangeTokenMetadataUriActivated, DataDepositFeeVersion, Destination,
HtlcActivated, OrdersActivated, OutPointSourceId, RewardDistributionVersion,
TokenIssuanceVersion, TokensFeeVersion, TxInput, TxOutput,
FrozenTokensValidationVersion, HtlcActivated, OrdersActivated, OutPointSourceId,
RewardDistributionVersion, TokenIssuanceVersion, TokensFeeVersion, TxInput, TxOutput,
};
use common::primitives::{BlockHeight, Idable};
use randomness::{CryptoRng, Rng};
Expand Down Expand Up @@ -1654,6 +1654,7 @@ fn no_v0_issuance_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -1720,6 +1721,7 @@ fn only_ascii_alphanumeric_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
6 changes: 4 additions & 2 deletions chainstate/test-suite/src/tests/nft_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ use common::{
signature::inputsig::InputWitness,
tokens::{make_token_id, NftIssuance, TokenId},
ChainstateUpgrade, ChangeTokenMetadataUriActivated, DataDepositFeeVersion, Destination,
HtlcActivated, NetUpgrades, OrdersActivated, OutPointSourceId, RewardDistributionVersion,
TokenIssuanceVersion, TokensFeeVersion, TxInput, TxOutput,
FrozenTokensValidationVersion, HtlcActivated, NetUpgrades, OrdersActivated,
OutPointSourceId, RewardDistributionVersion, TokenIssuanceVersion, TokensFeeVersion,
TxInput, TxOutput,
},
primitives::{Amount, BlockHeight, CoinOrTokenId},
};
Expand Down Expand Up @@ -372,6 +373,7 @@ fn ensure_nft_cannot_be_printed_from_tokens_op(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
2 changes: 2 additions & 0 deletions chainstate/test-suite/src/tests/orders_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,7 @@ fn test_activation(#[case] seed: Seed) {
common::chain::TokensFeeVersion::V1,
common::chain::DataDepositFeeVersion::V1,
common::chain::ChangeTokenMetadataUriActivated::Yes,
common::chain::FrozenTokensValidationVersion::V1,
common::chain::HtlcActivated::No,
common::chain::OrdersActivated::No,
),
Expand All @@ -1519,6 +1520,7 @@ fn test_activation(#[case] seed: Seed) {
common::chain::TokensFeeVersion::V1,
common::chain::DataDepositFeeVersion::V1,
common::chain::ChangeTokenMetadataUriActivated::Yes,
common::chain::FrozenTokensValidationVersion::V1,
common::chain::HtlcActivated::No,
common::chain::OrdersActivated::Yes,
),
Expand Down
5 changes: 3 additions & 2 deletions chainstate/test-suite/src/tests/tx_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ use common::{
TokenTotalSupply,
},
ChainConfig, ChainstateUpgrade, ChangeTokenMetadataUriActivated, DataDepositFeeVersion,
Destination, HtlcActivated, NetUpgrades, OrdersActivated, TokenIssuanceVersion,
TokensFeeVersion, TxInput, TxOutput, UtxoOutPoint,
Destination, FrozenTokensValidationVersion, HtlcActivated, NetUpgrades, OrdersActivated,
TokenIssuanceVersion, TokensFeeVersion, TxInput, TxOutput, UtxoOutPoint,
},
primitives::{Amount, Fee, Idable},
};
Expand Down Expand Up @@ -579,6 +579,7 @@ fn issue_fungible_token_v0(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
19 changes: 16 additions & 3 deletions chainstate/tx-verifier/src/transaction_verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ use common::{
signed_transaction::SignedTransaction,
tokens::make_token_id,
AccountCommand, AccountNonce, AccountSpending, AccountType, Block, ChainConfig,
DelegationId, GenBlock, Transaction, TxInput, TxOutput, UtxoOutPoint,
DelegationId, FrozenTokensValidationVersion, GenBlock, Transaction, TxInput, TxOutput,
UtxoOutPoint,
},
primitives::{id::WithId, Amount, BlockHeight, Fee, Id, Idable},
};
Expand Down Expand Up @@ -542,7 +543,7 @@ where
tx_source: &TransactionSourceForConnect,
tx: &Transaction,
) -> Result<(), ConnectTransactionError> {
self.check_operations_with_frozen_tokens(tx)?;
self.check_operations_with_frozen_tokens(tx, tx_source.expected_block_height())?;

let input_undos = tx
.inputs()
Expand Down Expand Up @@ -685,6 +686,7 @@ where
fn check_operations_with_frozen_tokens(
&self,
tx: &Transaction,
block_height: BlockHeight,
) -> Result<(), ConnectTransactionError> {
let check_not_frozen = |token_id| {
// TODO: when NFTs are stored in accounting None should become an error
Expand Down Expand Up @@ -735,7 +737,18 @@ where
.ok_or(ConnectTransactionError::MissingOutputOrSpent(
utxo_outpoint.clone(),
))?;
check_tx_output(utxo.output())

match self
.chain_config
.as_ref()
.chainstate_upgrades()
.version_at_height(block_height)
.1
.frozen_tokens_validation_version()
{
FrozenTokensValidationVersion::V0 => Ok(()),
FrozenTokensValidationVersion::V1 => check_tx_output(utxo.output()),
}
}
TxInput::Account(account_outpoint) => match account_outpoint.account() {
AccountSpending::DelegationBalance(_, _) => Ok(()),
Expand Down
Loading

0 comments on commit b140bd1

Please sign in to comment.