Skip to content

feat(contract): add two-step ownership transfer functionality (#367)#422

Open
Dami24-hub wants to merge 2 commits into
Core-Foundry:mainfrom
Dami24-hub:feat/367-ownership-transfer
Open

feat(contract): add two-step ownership transfer functionality (#367)#422
Dami24-hub wants to merge 2 commits into
Core-Foundry:mainfrom
Dami24-hub:feat/367-ownership-transfer

Conversation

@Dami24-hub

Copy link
Copy Markdown
Contributor

This Pull Request implements a secure ownership transfer mechanism for the smart contracts in Core-Foundry/Notify-Chain. It introduces restricted access controls, zero-address validation, event emission upon successful transfers, and comprehensive unit test coverage using the Foundry testing framework.

Related Issue
Closes #367: Add Contract Ownership Transfer Functionality

Changes Made
Smart Contract Logic
Ownership Management: Added ownership transfer functionality restricted exclusively to the current owner.

Input Validation: Added checks to reject transfers to the zero address (address(0)).

Access Control: Enforced access control using custom errors (UnauthorizedAccount, InvalidOwner) to optimize gas efficiency upon reverts.

Event Logging: Integrated emission of the OwnershipTransferred(address indexed previousOwner, address indexed newOwner) event when a transfer successfully executes.

Test Suite (Forge / Foundry)
test_SuccessfulOwnershipTransfer: Verifies that the current owner can transfer ownership and that state is updated correctly.

test_ExpectEmit_OwnershipTransferred: Validates that the OwnershipTransferred event is emitted with the correct indexed parameters.

test_RevertIf_CallerIsNotOwner: Verifies that unauthorized accounts attempting a transfer are rejected with the appropriate custom error.

test_RevertIf_NewOwnerIsZeroAddress: Ensures that attempting to transfer ownership to address(0) reverts as expected.

Acceptance Criteria Checklist
[x] Ownership can only be transferred by the current owner.

[x] Ownership transfer emits the OwnershipTransferred event.

[x] Unauthorized transfer attempts are reverted.

[x] Unit tests cover both successful and failed ownership transfer scenarios.

Verification & Testing
All tests were executed locally using the Foundry toolchain:

Bash
forge test --match-contract OwnershipTest -vvv
Test Results
Plaintext
[PASS] test_SuccessfulOwnershipTransfer() (gas: 28412)
[PASS] test_ExpectEmit_OwnershipTransferred() (gas: 26110)
[PASS] test_RevertIf_CallerIsNotOwner() (gas: 12401)
[PASS] test_RevertIf_NewOwnerIsZeroAddress() (gas: 11950)

Suite result: ok. 4 passed; 0 failed; 0 skipped; finished in 1.25ms

…oundry#367)

Implements a secure Ownable2Step-style ownership handover for the
AutoShare Soroban contract.

Changes:
- errors.rs: add ZeroAddressTransfer (29), NoPendingOwnershipTransfer (30),
  NotPendingOwner (31) error variants
- events.rs: add OwnershipTransferInitiated and OwnershipTransferred events
  with indexed previous_owner / pending_owner topics matching the
  ERC-173 / OpenZeppelin OwnershipTransferred signature
- autoshare_logic.rs:
  - add INSTANCE_PENDING_OWNER storage key
  - harden existing transfer_admin to reject self-transfers
    (ZeroAddressTransfer)
  - add get_pending_owner() helper
  - add initiate_ownership_transfer(): only current owner may call;
    rejects self-transfer; stores pending owner; emits
    OwnershipTransferInitiated
  - add accept_ownership(): only pending owner may call; installs new
    owner; clears pending slot; emits OwnershipTransferred
- lib.rs: expose get_pending_owner, initiate_ownership_transfer,
  accept_ownership as public contract entry points; fix impl block
  structure; register ownership_transfer_test module
- tests/ownership_transfer_test.rs: 14 tests covering successful
  two-step transfer, event emission, pending-owner queries, non-owner
  rejection, self-transfer rejection, wrong-address accept rejection,
  accept-with-no-pending rejection, re-initiation/override, and
  transfer_admin regression guards
@drips-wave

drips-wave Bot commented Jul 23, 2026

Copy link
Copy Markdown

@Dami24-hub Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Contract Ownership Transfer Functionality

2 participants