Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example tests #18

Merged
merged 33 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
09a25eb
chore: testing
tHeMaskedMan981 Jan 13, 2025
f1e7066
fix: counter test
ameeshaagrawal Jan 13, 2025
db27e9c
fix: deployer app gateway
ameeshaagrawal Jan 13, 2025
6764bbd
fix: renames and natspecs
ameeshaagrawal Jan 13, 2025
e686560
chore: test e2e
tHeMaskedMan981 Jan 13, 2025
8a2cbfd
Merge pull request #19 from SocketDotTech/test/e2e
tHeMaskedMan981 Jan 13, 2025
a71041d
Merge branch 'feat/cronGateway' into example-tests
ameeshaagrawal Jan 13, 2025
0fbb2be
fix: dynamic auction end delay
ameeshaagrawal Jan 13, 2025
15e2efc
fix: super token
ameeshaagrawal Jan 13, 2025
0aeea83
fix: refactor
ameeshaagrawal Jan 13, 2025
97e99fd
fix: super token lockable scripts
ameeshaagrawal Jan 13, 2025
f871e70
fix: use env for addr
ameeshaagrawal Jan 13, 2025
8677cd9
chore : couter tested
tHeMaskedMan981 Jan 13, 2025
853b1f4
Merge branch 'example-tests' of https://github.com/SocketDotTech/sock…
tHeMaskedMan981 Jan 13, 2025
7c8f4fe
fix: owner from env
ameeshaagrawal Jan 13, 2025
23040e8
test: fee deposit and distribute
ameeshaagrawal Jan 13, 2025
b7c11b7
fix: fees withdraw
ameeshaagrawal Jan 13, 2025
46d3446
fix: add asserts
ameeshaagrawal Jan 13, 2025
20c9611
Merge branch 'example-tests' of https://github.com/SocketDotTech/sock…
tHeMaskedMan981 Jan 14, 2025
f11d64f
fix: inbox tests
ameeshaagrawal Jan 14, 2025
84620f1
chore: bridge tested
tHeMaskedMan981 Jan 14, 2025
7775214
Merge branch 'example-tests' into feat/cronGateway
tHeMaskedMan981 Jan 14, 2025
7857999
Add SuperToken natspec and TODO explanations missing
rookmate Jan 16, 2025
81c440d
feat: added parallel test
tHeMaskedMan981 Jan 17, 2025
51298db
Merge branch 'example-tests' into feat/cronGateway
ameeshaagrawal Jan 17, 2025
f01b778
fix: batch promise resolved check
ameeshaagrawal Jan 17, 2025
4f0cfa1
fix: return on callback revert
ameeshaagrawal Jan 17, 2025
e999dcf
fix: tests
ameeshaagrawal Jan 17, 2025
b42188b
Merge pull request #20 from SocketDotTech/feat/cronGateway
ameeshaagrawal Jan 17, 2025
be820cf
Add contextual information
rookmate Jan 17, 2025
13f9f8c
fix: sequential read from gateway
ameeshaagrawal Jan 17, 2025
8606c4a
fix: scripts and new deployments
ameeshaagrawal Jan 17, 2025
5f485af
fix: build
ameeshaagrawal Jan 17, 2025
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
7 changes: 3 additions & 4 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ BASE_SEPOLIA_RPC="https://rpc.ankr.com/base_sepolia"
SEPOLIA_RPC="https://rpc.ankr.com/eth_sepolia"

# addresses

ADDRESS_RESOLVER=
AUCTION_MANAGER=
OWNER=

# app addresses

COUNTER_DEPLOYER=
COUNTER_APP_GATEWAY=
DEPLOYER=
APP_GATEWAY=
9 changes: 6 additions & 3 deletions contracts/AsyncPromise.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract AsyncPromise is AddressResolverUtil, IPromise {
/// @notice Marks the promise as resolved and executes the callback if set.
/// @param returnData The data returned from the async payload execution.
/// @dev Only callable by the watcher precompile.
function markResolved(bytes memory returnData) external override onlyWatcherPrecompile {
function markResolved(bytes memory returnData) external override onlyWatcherPrecompile returns (bool success) {
if (resolved) revert PromiseAlreadyResolved();
resolved = true;
state = AsyncPromiseState.RESOLVED;
Expand All @@ -64,8 +64,11 @@ contract AsyncPromise is AddressResolverUtil, IPromise {
abi.encode(callbackData, returnData)
);

(bool success, ) = localInvoker.call(combinedCalldata);
require(success, "Relaying async call failed");
(success, ) = localInvoker.call(combinedCalldata);
if (!success) {
resolved = false;
state = AsyncPromiseState.WAITING_FOR_CALLBACK_EXECUTION;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ contract Forwarder is IForwarder {

// Determine if the call is a read or write operation.
bool isReadCall = IAppGateway(msg.sender).isReadCall();
bool isCallSequential = IAppGateway(msg.sender).isCallSequential();

// Queue the call in the auction house.
IDeliveryHelper(deliveryHelper).queue(
// todo
true,
isCallSequential,
chainSlug,
onChainAddress,
latestAsyncPromise,
Expand Down
16 changes: 16 additions & 0 deletions contracts/apps/counter-inbox/CounterInbox.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

import "../../utils/Ownable.sol";
import "../../base/PlugBase.sol";

contract CounterInbox is Ownable(msg.sender), PlugBase(msg.sender) {
function increaseOnGateway(uint256 value) external returns (bytes32) {
return _callAppGateway(abi.encode(value), bytes32(0));
}

function connectSocket(address appGateway_, address socket_, address switchboard_) external {
_claimOwner(socket_);
_connectSocket(appGateway_, socket_, switchboard_);
}
}
29 changes: 29 additions & 0 deletions contracts/apps/counter-inbox/CounterInboxAppGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

import "../../base/AppGatewayBase.sol";

contract CounterInboxAppGateway is AppGatewayBase {
uint256 public counter;

constructor(
address _addressResolver,
address auctionManager_,
address counterInbox_,
uint32 chainSlug_,
FeesData memory feesData_
) AppGatewayBase(_addressResolver, auctionManager_) {
watcherPrecompile().setIsValidInboxCaller(chainSlug_, address(counterInbox_), true);
_setFeesData(feesData_);
}

function callFromInbox(
uint32,
address,
bytes calldata payload_,
bytes32
) external override onlyWatcherPrecompile {
uint256 value = abi.decode(payload_, (uint256));
counter += value;
}
}
9 changes: 9 additions & 0 deletions contracts/apps/counter/CounterAppGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ contract CounterAppGateway is AppGatewayBase {
function setFees(FeesData memory feesData_) public {
feesData = feesData_;
}

function withdrawFeeTokens(
uint32 chainSlug_,
address token_,
uint256 amount_,
address receiver_
) external {
_withdrawFeeTokens(chainSlug_, token_, amount_, receiver_);
}
}
39 changes: 39 additions & 0 deletions contracts/apps/parallel-counter/ParallelCounterAppGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

import "../../base/AppGatewayBase.sol";
import "../counter/Counter.sol";

contract ParallelCounterAppGateway is AppGatewayBase {
constructor(
address _addressResolver,
address deployerContract_,
address auctionManager_,
FeesData memory feesData_
) AppGatewayBase(_addressResolver, auctionManager_) {
addressResolver.setContractsToGateways(deployerContract_);
_setFeesData(feesData_);
_setIsCallSequential(false);
}

function incrementCounters(address[] memory instances) public async {
// the increase function is called on given list of instances
// this
for (uint256 i = 0; i < instances.length; i++) {
Counter(instances[i]).increase();
}
}

function setFees(FeesData memory feesData_) public {
feesData = feesData_;
}

function withdrawFeeTokens(
uint32 chainSlug_,
address token_,
uint256 amount_,
address receiver_
) external {
_withdrawFeeTokens(chainSlug_, token_, amount_, receiver_);
}
}
43 changes: 43 additions & 0 deletions contracts/apps/parallel-counter/ParallelCounterDeployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;

import "../counter/Counter.sol";
import "../../base/AppDeployerBase.sol";
import "../../utils/Ownable.sol";

contract ParallelCounterDeployer is AppDeployerBase, Ownable {
bytes32 public counter1 = _createContractId("counter1");
bytes32 public counter2 = _createContractId("counter2");

constructor(
address addressResolver_,
address auctionManager_,
bytes32 sbType_,
FeesData memory feesData_
) AppDeployerBase(addressResolver_, auctionManager_, sbType_) Ownable(msg.sender) {
creationCodeWithArgs[counter1] = abi.encodePacked(type(Counter).creationCode);
creationCodeWithArgs[counter2] = abi.encodePacked(type(Counter).creationCode);
_setFeesData(feesData_);
_setIsCallSequential(false);
}

function deployContracts(uint32 chainSlug) external async {
_deploy(counter1, chainSlug);
_deploy(counter2, chainSlug);
}

function deployMultiChainContracts(uint32[] memory chainSlugs) external async {
for (uint32 i = 0; i < chainSlugs.length; i++) {
_deploy(counter1, chainSlugs[i]);
_deploy(counter2, chainSlugs[i]);
}
}

function initialize(uint32) public pure override {
return;
}

function setFees(FeesData memory feesData_) public {
feesData = feesData_;
}
}
5 changes: 5 additions & 0 deletions contracts/apps/payload-delivery/FeesPlug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract FeesPlug is PlugBase, Ownable {

require(balanceOf[appGateway][feeToken] >= fee, "FeesPlug: Insufficient Balance for Fees");
balanceOf[appGateway][feeToken] -= fee;

_transferTokens(feeToken, fee, transmitter);
return bytes("");
}
Expand Down Expand Up @@ -79,4 +80,8 @@ contract FeesPlug is PlugBase, Ownable {
) external onlyOwner {
_connectSocket(appGateway_, socket_, switchboard_);
}

fallback() external payable {}

receive() external payable {}
}
17 changes: 13 additions & 4 deletions contracts/apps/payload-delivery/app-gateway/AuctionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,33 @@ contract AuctionManager is AddressResolverUtil, Ownable, IAuctionManager {
mapping(bytes32 => bool) public override auctionClosed;
mapping(bytes32 => bool) public override auctionStarted;

uint256 public constant auctionEndDelaySeconds = 0;
uint256 public auctionEndDelaySeconds;

error InvalidTransmitter();

/// @notice Constructor for AuctionManager
/// @param addressResolver_ The address of the address resolver
/// @param signatureVerifier_ The address of the signature verifier
constructor(
uint32 vmChainSlug_,
uint256 auctionEndDelaySeconds_,
address addressResolver_,
SignatureVerifier signatureVerifier_,
address owner_
) AddressResolverUtil(addressResolver_) Ownable(owner_) {
vmChainSlug = vmChainSlug_;
signatureVerifier__ = signatureVerifier_;
auctionEndDelaySeconds = auctionEndDelaySeconds_;
}

event AuctionStarted(bytes32 asyncId_);
event AuctionEnded(bytes32 asyncId_, Bid winningBid);
event AuctionStarted(bytes32 asyncId);
event AuctionEnded(bytes32 asyncId, Bid winningBid);
event BidPlaced(bytes32 asyncId, Bid bid);

function setAuctionEndDelaySeconds(uint256 auctionEndDelaySeconds_) external onlyOwner {
auctionEndDelaySeconds = auctionEndDelaySeconds_;
}

function startAuction(bytes32 asyncId_) external onlyDeliveryHelper returns (uint256) {
require(!auctionClosed[asyncId_], "Auction closed");
require(!auctionStarted[asyncId_], "Auction already started");
Expand Down Expand Up @@ -81,8 +89,9 @@ contract AuctionManager is AddressResolverUtil, Ownable, IAuctionManager {
function endAuction(bytes32 asyncId_) external onlyDeliveryHelper {
auctionClosed[asyncId_] = true;
Bid memory winningBid = winningBids[asyncId_];
emit AuctionEnded(asyncId_, winningBid);
if (winningBid.transmitter == address(0)) revert InvalidTransmitter();

emit AuctionEnded(asyncId_, winningBid);
IDeliveryHelper(addressResolver.deliveryHelper()).startBatchProcessing(
asyncId_,
winningBid
Expand Down
36 changes: 11 additions & 25 deletions contracts/apps/payload-delivery/app-gateway/BatchAsync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,11 @@ abstract contract BatchAsync is QueueAsync {
return asyncId;
}

address forwarderAppGateway = processRemainingPayloads(
payloadDetails_,
readEndIndex,
asyncId
);
address appGateway = processRemainingPayloads(payloadDetails_, readEndIndex, asyncId);

initializeBatch(
asyncId,
forwarderAppGateway,
appGateway,
feesData_,
auctionManager_,
onCompleteData_,
Expand Down Expand Up @@ -146,42 +142,38 @@ abstract contract BatchAsync is QueueAsync {
uint256 readEndIndex,
bytes32 asyncId
) internal returns (address) {
address forwarderAppGateway = msg.sender;
address appGateway = msg.sender;

for (uint256 i = readEndIndex; i < payloadDetails_.length; i++) {
if (payloadDetails_[i].payload.length > 24.5 * 1024) revert PayloadTooLarge();

if (payloadDetails_[i].callType == CallType.DEPLOY) {
// contract factory plug deploys new contracts
payloadDetails_[i].target = getPlugAddress(
address(this),
payloadDetails_[i].chainSlug
);
} else if (payloadDetails_[i].callType == CallType.WRITE) {
forwarderAppGateway = IAddressResolver(addressResolver).contractsToGateways(
msg.sender
);
if (forwarderAppGateway == address(0)) forwarderAppGateway = msg.sender;

payloadDetails_[i].appGateway = forwarderAppGateway;
appGateway = _getCoreAppGateway(appGateway);
payloadDetails_[i].appGateway = appGateway;
}

payloadBatchDetails[asyncId].push(payloadDetails_[i]);
}

return forwarderAppGateway;
return appGateway;
}

function initializeBatch(
bytes32 asyncId,
address forwarderAppGateway,
address appGateway,
FeesData memory feesData_,
address auctionManager_,
bytes memory onCompleteData_,
uint256 readEndIndex,
PayloadDetails[] memory payloadDetails_
) internal {
payloadBatches[asyncId] = PayloadBatch({
appGateway: forwarderAppGateway,
appGateway: appGateway,
feesData: feesData_,
currentPayloadIndex: readEndIndex,
auctionManager: auctionManager_,
Expand All @@ -194,18 +186,12 @@ abstract contract BatchAsync is QueueAsync {

uint256 delayInSeconds = IAuctionManager(auctionManager_).startAuction(asyncId);
watcherPrecompile().setTimeout(
forwarderAppGateway,
appGateway,
abi.encodeWithSelector(this.endTimeout.selector, asyncId),
delayInSeconds
);

emit PayloadSubmitted(
asyncId,
forwarderAppGateway,
payloadDetails_,
feesData_,
auctionManager_
);
emit PayloadSubmitted(asyncId, appGateway, payloadDetails_, feesData_, auctionManager_);
}

function endTimeout(bytes32 asyncId_) external onlyWatcherPrecompile {
Expand Down
20 changes: 10 additions & 10 deletions contracts/apps/payload-delivery/app-gateway/DeliveryHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ contract DeliveryHelper is BatchAsync, Ownable {
if (payloadBatch.isBatchCancelled) return;

// Check if there are remaining payloads to process
if (payloadBatch.totalPayloadsRemaining > 0) {
// Check if there are promises from last batch that need to be resolved
if (payloadBatch.lastBatchPromises.length > 0) {
// Check if all promises are resolved
for (uint256 i = 0; i < payloadBatch.lastBatchPromises.length; i++) {
if (!IPromise(payloadBatch.lastBatchPromises[i]).resolved()) {
revert PromisesNotResolved();
}
// Check if there are promises from last batch that need to be resolved
if (payloadBatch.lastBatchPromises.length > 0) {
// Check if all promises are resolved
for (uint256 i = 0; i < payloadBatch.lastBatchPromises.length; i++) {
if (!IPromise(payloadBatch.lastBatchPromises[i]).resolved()) {
revert PromisesNotResolved();
}
// Clear promises array after all are resolved
delete payloadBatch.lastBatchPromises;
}
// Clear promises array after all are resolved
delete payloadBatch.lastBatchPromises;
}

if (payloadBatch.totalPayloadsRemaining > 0) {
// Proceed with next payload only if all promises are resolved
_finalizeNextPayload(asyncId);
} else {
Expand Down
Loading