Skip to content
Merged
Show file tree
Hide file tree
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
128 changes: 12 additions & 116 deletions service/dealpusher/ddo_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ import (
ddotypes "github.com/Eastore-project/ddo-client/pkg/types"
"github.com/data-preservation-programs/go-synapse/signer"
"github.com/data-preservation-programs/singularity/util/testutil"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ipfs/go-cid"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -230,134 +228,32 @@ func TestIntegration_DDOFullDealFlow(t *testing.T) {
require.NoError(t, err)
t.Log("EnsurePayments succeeded — deposit and operator approval completed on-chain")

// --- Step 6: Deploy MockAllocationFacet ---
// The real createAllocationRequests calls DataCapAPI.transfer() which
// requires Filecoin built-in actors (CALL_ACTOR_ID precompile). Anvil
// doesn't have those, so we deploy the MockAllocationFacet which skips
// the DataCap path and generates mock allocation IDs.
mockFacet := testutil.DeployMockAllocationFacet(t, rpcURL, ddoAddr, owner)
// --- Step 6: Install FVM precompile mocks ---
// createAllocationRequests routes through DataCapAPI.transfer() which
// invokes CALL_ACTOR_BY_ID against actor 7 (DataCap). The mock's burn-only
// path used to revert; the DataCap dispatch added in fvm-solidity now
// returns a canned empty TransferReturn so the contract proceeds.
testutil.SetupFVMPrecompiles(t, rpcURL)

// --- Step 7: Call mockCreateAllocationRequests ---
// ABI-encode the pieceInfos for the mock function call.
// --- Step 7: Call the real createAllocationRequests ---
pieceInfos, err := ddo.buildPieceInfos(pieces, cfg)
require.NoError(t, err)

parsedABI, err := abi.JSON(strings.NewReader(ddocontract.DDOClientABI))
require.NoError(t, err)

// Use mockCreateRawAllocationRequests which skips DataCap AND payment
// rails — it only emits AllocationCreated events with mock IDs.
// It takes the same parameter shape as createAllocationRequests, so we
// pack the real method and derive the mock selector by replacing the
// function name in the canonical signature. This stays in sync if the
// pieceInfos struct ever changes.
realCallData, err := parsedABI.Pack("createAllocationRequests", pieceInfos)
callData, err := parsedABI.Pack("createAllocationRequests", pieceInfos)
require.NoError(t, err)
realMethod := parsedABI.Methods["createAllocationRequests"]
mockSig := strings.Replace(realMethod.Sig, "createAllocationRequests", "mockCreateRawAllocationRequests", 1)
mockSelector := crypto.Keccak256([]byte(mockSig))[:4]
copy(realCallData[0:4], mockSelector)

clientAddr := evmSigner.EVMAddress()
testutil.AnvilImpersonate(t, rpcURL, clientAddr)
mockTxHash := testutil.SendImpersonatedTx(t, rpcURL, clientAddr, ddoAddr, realCallData)
t.Logf("mockCreateAllocationRequests tx: %s", mockTxHash.Hex())
txHash := testutil.SendImpersonatedTx(t, rpcURL, clientAddr, ddoAddr, callData)
t.Logf("createAllocationRequests tx: %s", txHash.Hex())

// --- Step 8: Parse AllocationCreated events ---
allocationIDs, err := ddo.ParseAllocationIDs(ctx, mockTxHash.Hex())
allocationIDs, err := ddo.ParseAllocationIDs(ctx, txHash.Hex())
require.NoError(t, err)
require.Len(t, allocationIDs, 1, "should get exactly 1 allocation ID for 1 piece")
t.Logf("Mock allocation ID: %d", allocationIDs[0])

_ = mockFacet
}

// TestIntegration_DDOAllocationCallHitsDataCapPrecompile is a tripwire for the
// FVM precompile mocks in util/testutil. It deploys the mocks and simulates
// the real createAllocationRequests path -- which dispatches through
// DataCapAPI.transfer() to CALL_ACTOR_BY_ID against actor ID 7 (DataCap).
// Our mock only honors actor ID 99 (burn), so the call must revert.
//
// When/if a DataCap actor stub is added to the precompile mocks, this test
// flips green and TestIntegration_DDOFullDealFlow's MockAllocationFacet
// bypass can be retired.
func TestIntegration_DDOAllocationCallHitsDataCapPrecompile(t *testing.T) {
anvil := startCalibnetFork(t)
rpcURL := anvil.RPCURL

ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()

ddoAddr := common.HexToAddress(testutil.CalibnetDDOContract)
usdfcAddr := common.HexToAddress(testutil.CalibnetUSDFC)

// register SP, fund wallet, do payments setup -- mirrors DDOFullDealFlow
owner := testutil.ReadContractOwner(t, rpcURL, ddoAddr)
testutil.AnvilImpersonate(t, rpcURL, owner)
testutil.FundEVMWallet(t, rpcURL, owner, testutil.OneEther)
registerSPViaImpersonation(t, rpcURL, ddoAddr, owner, testutil.CalibnetDDOProviderActorID, usdfcAddr)

ddo, err := NewOnChainDDO(ctx, rpcURL,
testutil.CalibnetDDOContract,
testutil.CalibnetPaymentsContract,
testutil.CalibnetUSDFC,
)
require.NoError(t, err)
defer ddo.Close()

clientKey := testutil.AnvilFunderKey(t)
clientSigner, err := signer.NewSecp256k1SignerFromECDSA(clientKey)
require.NoError(t, err)
evmSigner, ok := signer.AsEVM(clientSigner)
require.True(t, ok)

pieceCID := calculateCommp(t, generateRandomBytes(1000), 2048)
pieces := []DDOPieceSubmission{{
PieceCID: pieceCID,
PieceSize: 2048,
ProviderID: testutil.CalibnetDDOProviderActorID,
DownloadURL: "https://example.test/piece/" + pieceCID.String(),
}}
cfg := DDOSchedulingConfig{
BatchSize: 10,
ConfirmationDepth: 1,
PollingInterval: 100 * time.Millisecond,
TermMin: 518400,
TermMax: 5256000,
ExpirationOffset: 172800,
}
require.NoError(t, ddo.EnsurePayments(ctx, evmSigner, pieces, cfg))

// install the FVM precompile mocks -- the bit being exercised
testutil.SetupFVMPrecompiles(t, rpcURL)

pieceInfos, err := ddo.buildPieceInfos(pieces, cfg)
require.NoError(t, err)
parsedABI, err := abi.JSON(strings.NewReader(ddocontract.DDOClientABI))
require.NoError(t, err)
callData, err := parsedABI.Pack("createAllocationRequests", pieceInfos)
require.NoError(t, err)

client, err := ethclient.DialContext(ctx, rpcURL)
require.NoError(t, err)
defer client.Close()

// eth_call simulation surfaces the revert reason directly in err
clientAddr := evmSigner.EVMAddress()
_, err = client.CallContract(ctx, ethereum.CallMsg{
From: clientAddr,
To: &ddoAddr,
Data: callData,
}, nil)
require.Error(t, err, "createAllocationRequests should revert without DataCap actor emulation")
// 0x8a7db5bf = FailToCallActor() in DDOClientABI. filecoin-solidity wraps
// the precompile call as (success, data) = 0xfe..05.call(...) and re-raises
// this typed error when success == false. Our mock returns success only
// for actor ID 99; calling DataCap (ID 7) trips the wrapper. When DataCap
// emulation lands in the precompile mock, this assertion will fail and
// signal that TestIntegration_DDOFullDealFlow can drop MockAllocationFacet.
require.Contains(t, err.Error(), "0x8a7db5bf",
"expected FailToCallActor() from filecoin-solidity wrapper around our precompile mock; got: %v", err)
t.Logf("Allocation ID: %d", allocationIDs[0])
}

// registerSPViaImpersonation registers an SP in the DDO contract using
Expand Down
2 changes: 1 addition & 1 deletion util/testutil/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func SendImpersonatedTx(t *testing.T, rpcURL string, from, to common.Address, da
From: from.Hex(),
To: to.Hex(),
Data: fmt.Sprintf("0x%x", data),
Gas: fmt.Sprintf("0x%x", 500000),
Gas: fmt.Sprintf("0x%x", 5000000),
GasPrice: fmt.Sprintf("0x%x", gasPrice),
Nonce: fmt.Sprintf("0x%x", nonce),
}
Expand Down
2 changes: 1 addition & 1 deletion util/testutil/fvm_call_actor_by_address_bytecode.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x60806040525f5f5f5f5f5f5f3681019061001991906105c8565b9550955095509550955095506002815111610069576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161006090610709565b60405180910390fd5b600460f81b815f8151811061008157610080610727565b5b602001015160f81c60f81b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916146100ee576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100e5906107c4565b60405180910390fd5b600a60f81b8160018151811061010757610106610727565b5b602001015160f81c60f81b7effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614610174576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161016b90610852565b60405180910390fd5b60168151146101b8576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101af906108e0565b60405180910390fd5b5f67ffffffffffffffff168667ffffffffffffffff161461020e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102059061096e565b60405180910390fd5b5f67ffffffffffffffff168467ffffffffffffffff1614610264576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161025b906109fc565b60405180910390fd5b5f67ffffffffffffffff168367ffffffffffffffff16146102ba576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102b190610a8a565b60405180910390fd5b5f8251146102fd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102f490610b18565b60405180910390fd5b5f816016015190505f8173ffffffffffffffffffffffffffffffffffffffff168760405161032a90610b63565b5f6040518083038185875af1925050503d805f8114610364576040519150601f19603f3d011682016040523d82523d5f602084013e610369565b606091505b50509050606081156103ae575f5f60405180602001604052805f81525060405160200161039893929190610bfe565b6040516020818303038152906040529050610403565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb5f60405180602001604052805f8152506040516020016103f193929190610bfe565b60405160208183030381529060405290505b805160208201f35b5f604051905090565b5f5ffd5b5f5ffd5b5f67ffffffffffffffff82169050919050565b6104388161041c565b8114610442575f5ffd5b50565b5f813590506104538161042f565b92915050565b5f819050919050565b61046b81610459565b8114610475575f5ffd5b50565b5f8135905061048681610462565b92915050565b5f5ffd5b5f5ffd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6104da82610494565b810181811067ffffffffffffffff821117156104f9576104f86104a4565b5b80604052505050565b5f61050b61040b565b905061051782826104d1565b919050565b5f67ffffffffffffffff821115610536576105356104a4565b5b61053f82610494565b9050602081019050919050565b828183375f83830152505050565b5f61056c6105678461051c565b610502565b90508281526020810184848401111561058857610587610490565b5b61059384828561054c565b509392505050565b5f82601f8301126105af576105ae61048c565b5b81356105bf84826020860161055a565b91505092915050565b5f5f5f5f5f5f60c087890312156105e2576105e1610414565b5b5f6105ef89828a01610445565b965050602061060089828a01610478565b955050604061061189828a01610445565b945050606061062289828a01610445565b935050608087013567ffffffffffffffff81111561064357610642610418565b5b61064f89828a0161059b565b92505060a087013567ffffffffffffffff8111156106705761066f610418565b5b61067c89828a0161059b565b9150509295509295509295565b5f82825260208201905092915050565b7f46564d43616c6c4163746f724279416464726573733a20496e76616c696420735f8201527f686f727420616464726573730000000000000000000000000000000000000000602082015250565b5f6106f3602c83610689565b91506106fe82610699565b604082019050919050565b5f6020820190508181035f830152610720816106e7565b9050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b7f46564d43616c6c4163746f724279416464726573733a204f6e6c7920663420615f8201527f646472657373657320737570706f727465640000000000000000000000000000602082015250565b5f6107ae603283610689565b91506107b982610754565b604082019050919050565b5f6020820190508181035f8301526107db816107a2565b9050919050565b7f46564d43616c6c4163746f724279416464726573733a204f6e6c7920663431305f8201527f2061646472657373657320737570706f72746564000000000000000000000000602082015250565b5f61083c603483610689565b9150610847826107e2565b604082019050919050565b5f6020820190508181035f83015261086981610830565b9050919050565b7f46564d43616c6c4163746f724279416464726573733a20496e76616c696420665f8201527f3431302061646472657373206c656e6774680000000000000000000000000000602082015250565b5f6108ca603283610689565b91506108d582610870565b604082019050919050565b5f6020820190508181035f8301526108f7816108be565b9050919050565b7f46564d43616c6c4163746f724279416464726573733a204f6e6c79206d6574685f8201527f6f642030202873656e642920737570706f727465640000000000000000000000602082015250565b5f610958603583610689565b9150610963826108fe565b604082019050919050565b5f6020820190508181035f8301526109858161094c565b9050919050565b7f46564d43616c6c4163746f724279416464726573733a204f6e6c79206e6f6e2d5f8201527f726561646f6e6c792063616c6c7320737570706f727465640000000000000000602082015250565b5f6109e6603883610689565b91506109f18261098c565b604082019050919050565b5f6020820190508181035f830152610a13816109da565b9050919050565b7f46564d43616c6c4163746f724279416464726573733a204f6e6c79206e6f2d635f8201527f6f6465632063616c6c7320737570706f72746564000000000000000000000000602082015250565b5f610a74603483610689565b9150610a7f82610a1a565b604082019050919050565b5f6020820190508181035f830152610aa181610a68565b9050919050565b7f46564d43616c6c4163746f724279416464726573733a204e6f20706172616d735f8201527f2065787065637465640000000000000000000000000000000000000000000000602082015250565b5f610b02602983610689565b9150610b0d82610aa8565b604082019050919050565b5f6020820190508181035f830152610b2f81610af6565b9050919050565b5f81905092915050565b50565b5f610b4e5f83610b36565b9150610b5982610b40565b5f82019050919050565b5f610b6d82610b43565b9150819050919050565b5f819050919050565b610b8981610b77565b82525050565b610b988161041c565b82525050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f610bd082610b9e565b610bda8185610ba8565b9350610bea818560208601610bb8565b610bf381610494565b840191505092915050565b5f606082019050610c115f830186610b80565b610c1e6020830185610b8f565b8181036040830152610c308184610bc6565b905094935050505056fea2646970667358221220f1098bf2d0d55cf798988475faf22c2d74b959957bae4fca1e77ac1a7c9b6a0264736f6c63430008210033
0x608060405260c03612610526575f3567ffffffffffffffff81168091036105265760403567ffffffffffffffff81168091036105265760603567ffffffffffffffff81168091036105265760803567ffffffffffffffff81116105265761006790369061057c565b9160a03567ffffffffffffffff81116105265761008590369061057c565b936002855111156104cc578451156104585760208501516001600160f81b031916603f60fa1b0161046c578451600110156104585760218501516001600160f81b031916607b60f91b016103f657601685510361039657610333576102c857610266575161020f57601601515f90819081908190602035906001600160a01b03165af13d1561020a573d61011881610560565b90610126604051928361052a565b81525f60203d92013e5b606090156101a25750602061019a608060405161014d848261052a565b5f8152836040519485925f828501525f6040850152606080850152805191829182878701520160a085015e5f8483838601010152601f80199101168201010301601f19810183528261052a565b602081519101f35b6102056080602092604051936101b8818661052a565b5f855280604051958693600419838601525f604086015280850152805191829182878701520160a085015e5f8483838601010152601f80199101168201010301601f19810183528261052a565b61019a565b610130565b60405162461bcd60e51b815260206004820152602960248201527f46564d43616c6c4163746f724279416464726573733a204e6f20706172616d7360448201526808195e1c1958dd195960ba1b6064820152608490fd5b60405162461bcd60e51b815260206004820152603460248201527f46564d43616c6c4163746f724279416464726573733a204f6e6c79206e6f2d636044820152731bd91958c818d85b1b1cc81cdd5c1c1bdc9d195960621b6064820152608490fd5b60405162461bcd60e51b815260206004820152603860248201527f46564d43616c6c4163746f724279416464726573733a204f6e6c79206e6f6e2d60448201527f726561646f6e6c792063616c6c7320737570706f7274656400000000000000006064820152608490fd5b60405162461bcd60e51b815260206004820152603560248201527f46564d43616c6c4163746f724279416464726573733a204f6e6c79206d6574686044820152741bd9080c080a1cd95b990a481cdd5c1c1bdc9d1959605a1b6064820152608490fd5b60405162461bcd60e51b815260206004820152603260248201527f46564d43616c6c4163746f724279416464726573733a20496e76616c69642066604482015271068626040c2c8c8e4cae6e640d8cadccee8d60731b6064820152608490fd5b60405162461bcd60e51b815260206004820152603460248201527f46564d43616c6c4163746f724279416464726573733a204f6e6c792066343130604482015273081859191c995cdcd95cc81cdd5c1c1bdc9d195960621b6064820152608490fd5b634e487b7160e01b5f52603260045260245ffd5b60405162461bcd60e51b815260206004820152603260248201527f46564d43616c6c4163746f724279416464726573733a204f6e6c79206634206160448201527119191c995cdcd95cc81cdd5c1c1bdc9d195960721b6064820152608490fd5b60405162461bcd60e51b815260206004820152602c60248201527f46564d43616c6c4163746f724279416464726573733a20496e76616c6964207360448201526b686f7274206164647265737360a01b6064820152608490fd5b5f80fd5b90601f8019910116810190811067ffffffffffffffff82111761054c57604052565b634e487b7160e01b5f52604160045260245ffd5b67ffffffffffffffff811161054c57601f01601f191660200190565b81601f820112156105265780359061059382610560565b926105a1604051948561052a565b8284526020838301011161052657815f92602080930183860137830101529056fea2646970667358221220dc2e362d8f7c1ae15b02c879f6f99dbb01d8bda26be76e125b675ef7f1b20e8e64736f6c634300081e0033
Loading
Loading