Skip to content

Commit

Permalink
checkpoint: into main from release/2.3.0 @ 65ef0f4 (#17835)
Browse files Browse the repository at this point in the history
Source hash: 65ef0f4
Remaining commits: 0
  • Loading branch information
pmaslana committed Apr 8, 2024
2 parents 72b9756 + 040f753 commit 02a7e8b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chia/_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def db_version(request) -> int:
return request.param


SOFTFORK_HEIGHTS = [1000000, 5496000, 5496100]
SOFTFORK_HEIGHTS = [1000000, 5496000, 5496100, 5650000]


@pytest.fixture(scope="function", params=SOFTFORK_HEIGHTS)
Expand Down
31 changes: 31 additions & 0 deletions chia/_tests/core/full_node/test_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,34 @@ async def test_parent_messages(self, bt: BlockTools, consensus_mode: ConsensusMo
)
)
await check_conditions(bt, conditions)

@pytest.mark.anyio
@pytest.mark.parametrize(
"conds, expected",
[
('(66 0x3f "foobar" {coin}) (67 0x3f "foobar" {coin})', None),
('(66 0x3f "foobar" {coin}) (67 0x3f "foo" {coin})', Err.MESSAGE_NOT_SENT_OR_RECEIVED),
('(66 0x39 "foo" {coin})', Err.COIN_AMOUNT_EXCEEDS_MAXIMUM),
('(67 0x0f "foo" {coin})', Err.COIN_AMOUNT_EXCEEDS_MAXIMUM),
('(66 0x3f "foo" {coin}) (67 0x27 "foo" {coin})', Err.MESSAGE_NOT_SENT_OR_RECEIVED),
('(66 0x27 "foo" {coin}) (67 0x3f "foo" {coin})', Err.MESSAGE_NOT_SENT_OR_RECEIVED),
('(66 0 "foo") (67 0 "foo")', None),
('(66 0 "foobar") (67 0 "foo")', Err.MESSAGE_NOT_SENT_OR_RECEIVED),
('(66 0x09 "foo" 1750000000000) (67 0x09 "foo" 1750000000000)', None),
('(66 -1 "foo")', Err.INVALID_MESSAGE_MODE),
('(67 -1 "foo")', Err.INVALID_MESSAGE_MODE),
('(66 0x40 "foo")', Err.INVALID_MESSAGE_MODE),
('(67 0x40 "foo")', Err.INVALID_MESSAGE_MODE),
],
)
async def test_message_conditions(
self, bt: BlockTools, consensus_mode: ConsensusMode, conds: str, expected: Optional[Err]
) -> None:
blocks = await initial_blocks(bt)
coin = blocks[-2].get_included_reward_coins()[0]
conditions = Program.to(assemble("(" + conds.format(coin="0x" + coin.name().hex()) + ")"))
# before the softfork has activated, it's all allowed
if consensus_mode.value < ConsensusMode.SOFT_FORK_4.value:
expected = None

await check_conditions(bt, conditions, expected_err=expected)
22 changes: 22 additions & 0 deletions chia/_tests/core/mempool/test_mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,28 @@ def test_softfork_condition(

assert npc_result.error == expect_error

@pytest.mark.parametrize("mempool", [True, False])
@pytest.mark.parametrize(
"condition, expect_error",
[
('(66 0 "foo") (67 0 "bar")', Err.MESSAGE_NOT_SENT_OR_RECEIVED.value),
('(66 0 "foo") (67 0 "foo")', None),
],
)
def test_message_condition(
self, mempool: bool, condition: str, expect_error: Optional[int], softfork_height: uint32
):
npc_result = generator_condition_tester(condition, mempool_mode=mempool, height=softfork_height)
print(npc_result)

# the message conditions are only activated with soft fork 4, so
# before then there are no errors.
# In mempool mode, the message conditions activated immediately.
if softfork_height < test_constants.SOFT_FORK4_HEIGHT and not mempool:
expect_error = None

assert npc_result.error == expect_error


# the tests below are malicious generator programs

Expand Down
6 changes: 4 additions & 2 deletions chia/util/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ class Err(Enum):
# raised if a spend issues too many assert spend, assert puzzle,
# assert announcement or create announcement
TOO_MANY_ANNOUNCEMENTS = 144
# the message mode in SEND_MESSAGE or RECEIVE_MESSAGE condition is not valid
INVALID_MESSAGE_MODE = 145
# the specified coin ID is not valid
INVALID_COIN_ID = 145
INVALID_COIN_ID = 146
# message not sent/received
MESSAGE_NOT_SENT_OR_RECEIVED = 146
MESSAGE_NOT_SENT_OR_RECEIVED = 147


class ValidationError(Exception):
Expand Down

0 comments on commit 02a7e8b

Please sign in to comment.