Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions test/src/concrete/Flow.construction.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import {Vm} from "forge-std/Test.sol";
import {EvaluableConfigV3} from "rain.interpreter.interface/interface/IInterpreterCallerV2.sol";
import {FlowTest} from "test/abstract/FlowTest.sol";
import {EmptyFlowConfig} from "src/error/ErrFlow.sol";
import {EvaluableV2} from "rain.interpreter.interface/lib/caller/LibEvaluable.sol";
import {LibLogHelper} from "test/lib/LibLogHelper.sol";

contract FlowConstructionTest is FlowTest {
using LibLogHelper for Vm.Log[];
function testFlowConstructionEmptyConfigReverts() external {
EvaluableConfigV3[] memory emptyConfig = new EvaluableConfigV3[](0);
address impl = deployFlowImplementation();
Expand Down Expand Up @@ -37,4 +40,33 @@ contract FlowConstructionTest is FlowTest {
assertEq(sender, address(I_CLONE_FACTORY), "wrong sender in Initialize event");
assertEq(keccak256(abi.encode(flowConfig)), keccak256(abi.encode(config)), "wrong compare Structs");
}

/// `flowInit` does not de-duplicate identical evaluable configs: two
/// configs that produce the same `(interpreter, store, expression)`
/// triple emit two `FlowInitialized` events and write the same
/// `registeredFlows` slot twice. The registration is idempotent so
/// the resulting clone is still functional with that evaluable.
/// forge-config: default.fuzz.runs = 100
function testFlowConstructionDuplicateEvaluablesEmitTwiceIdempotently(
address expression,
bytes memory bytecode,
uint256[] memory constants
) external {
expressionDeployerDeployExpression2MockCall(bytecode, constants, expression, bytes(hex"0007"));

EvaluableConfigV3[] memory flowConfig = new EvaluableConfigV3[](2);
flowConfig[0] = EvaluableConfigV3(DEPLOYER, bytecode, constants);
flowConfig[1] = EvaluableConfigV3(DEPLOYER, bytecode, constants);

vm.recordLogs();
I_CLONE_FACTORY.clone(deployFlowImplementation(), abi.encode(flowConfig));

Vm.Log[] memory init =
vm.getRecordedLogs().findEvents(keccak256("FlowInitialized(address,(address,address,address))"));
assertEq(init.length, 2, "duplicate configs MUST emit two FlowInitialized events");

(, EvaluableV2 memory ev0) = abi.decode(init[0].data, (address, EvaluableV2));
(, EvaluableV2 memory ev1) = abi.decode(init[1].data, (address, EvaluableV2));
assertEq(keccak256(abi.encode(ev0)), keccak256(abi.encode(ev1)), "duplicate events MUST carry identical evaluable");
}
Comment on lines +64 to +71
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Missing functional assertion after duplicate initialization.

The new test proves duplicate emits (Lines 64-70), but it does not verify the deployed clone remains callable with that evaluable. That post-condition is part of the stated objective, so please add an execution/assertion step after clone deployment using the existing flow execution helper in this test suite.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/src/concrete/Flow.construction.t.sol` around lines 64 - 71, After
asserting the two FlowInitialized logs and that ev0 and ev1 (both typed
EvaluableV2) are identical, add a functional assertion that the deployed clone
is callable with that evaluable: invoke the test-suite's existing flow execution
helper (the same helper used elsewhere in this test file) against the newly
deployed clone using ev0 and assert the call succeeds (no revert) and returns
the expected result/state change; reference the decoded ev0/ev1 values and the
FlowInitialized event from vm.getRecordedLogs() when locating where to add this
execution/assertion.

}
Loading