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
2 changes: 1 addition & 1 deletion config.test.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"appName":"RosettaNet","port":3000,"host":"localhost","rpcUrls":["http://127.0.0.1:6050"],"chainId":"0x52535453","accountClass":"0x56ab4cd1d769d746256546b81f34f5b4f416da9e3d5696d2f362ab1a86fae9","ethAddress":"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7","strkAddress":"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d","rosettanet":"0x2005d48f7bbdff70f7102eab69d67909800ebc562044469e89dcf4544c2c48e","featureTarget":"0x0000000000000000000000004645415455524553","logging":{"active":true,"sniffer":true,"output":"file","minSeverity":"0","fileName":"./e2e/logs.log","format":"text"}}
{"appName":"RosettaNet","port":3000,"host":"localhost","rpcUrls":["http://127.0.0.1:6050"],"chainId":"0x52535453","accountClass":"0x70af38bca727839a6f1501f883f0dcc3e3a73033fd48b852e25da2e0163d92","ethAddress":"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7","strkAddress":"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d","rosettanet":"0x4cad109dfee10dfe764a439956c64bf219085915550ca79a5f7f91ca0f7e080","validateFeeEstimator":"0x4c28482306cd18d2af6c0df29a32a92944f2251de3e3a83e913eee2efa68be8","featureTarget":"0x0000000000000000000000004645415455524553","logging":{"active":true,"sniffer":true,"output":"file","minSeverity":"0","fileName":"./e2e/logs.log","format":"text"}}
4 changes: 4 additions & 0 deletions e2e/jest.globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ export default async function globalSetup() {

const rosettanetClass = await declareContract(account, 'Rosettanet')
const accountClass = await declareContract(account, 'RosettaAccount')
const validateFeeEstimator = await declareContract(account, 'ValidateFeeEstimator')

const rosettanetAddress = await deployContract(account, rosettanetClass, [
accountClass,
account.address,
STRK_ADDRESS,
])
const validateFeeEstimatorAddress = await deployContract(account, validateFeeEstimator, [])

const nodeConfig = testConfig
nodeConfig.accountClass = accountClass
nodeConfig.rosettanet = rosettanetAddress
nodeConfig.validateFeeEstimator = validateFeeEstimatorAddress
await updateNodeConfig(JSON.stringify(nodeConfig))

await fundAccountsForBalanceTests();
Expand Down
580 changes: 291 additions & 289 deletions e2e/libraries/ethers.test.ts

Large diffs are not rendered by default.

44 changes: 32 additions & 12 deletions e2e/rpc/sendRawTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@

const toAddress = '0x8b4ee3F7a16ed6b793BD7907f87778AC11624c27';
const ERC20_ABI = [
'function balanceOf(address owner) view returns (uint256)',
'function decimals() view returns (uint8)',
'function transfer(address to, uint256 amount) public returns (bool)'
'function balanceOf(address owner) view returns (uint256)',
'function decimals() view returns (uint8)',
'function transfer(address to, uint256 amount) public returns (bool)'
];
const tokenAddress = await getEthAddress(ETH_ADDRESS);
const devAcc = getDevAccount()
const precalculatedSnAddress = await precalculateStarknetAddress(wallet.address);
await sendStrksFromSnAccount(devAcc, precalculatedSnAddress, '100000000000000000000')

const iface = new ethers.Interface(ERC20_ABI);

const data = iface.encodeFunctionData('transfer', [
toAddress,
ethers.parseUnits('1', 18)
toAddress,
ethers.parseUnits('1', 18)
]);

const txRequest = {
to: tokenAddress.ethereum, // Token kontrat adresi
data: data,
to: tokenAddress.ethereum, // Token kontrat adresi
data: data,
};

const tx = await wallet.populateTransaction(txRequest);
Expand Down Expand Up @@ -116,7 +116,25 @@
}, 30000)

test.only('Send already sent tx twice in array', async () => {
const txs = ['0x02f8b4845253545380843b9aca00852ecc889a0082520894b5e1278663de249f8580ec51b6b61739bd90621580b844a9059cbb0000000000000000000000008b4ee3f7a16ed6b793bd7907f87778ac11624c270000000000000000000000000000000000000000000000000de0b6b3a7640000c080a07ec65572fb7f245736b47900c99a0818f588c69a09e3dc3132bd752adf5a665ca06bb0ee1ce53ac2b0e88b6aecac60ffba66d90613ad3cc8b1ac13df5bae6221f9', '0x02f8b4845253545380843b9aca00852ecc889a0082520894b5e1278663de249f8580ec51b6b61739bd90621580b844a9059cbb0000000000000000000000008b4ee3f7a16ed6b793bd7907f87778ac11624c270000000000000000000000000000000000000000000000000de0b6b3a7640000c080a07ec65572fb7f245736b47900c99a0818f588c69a09e3dc3132bd752adf5a665ca06bb0ee1ce53ac2b0e88b6aecac60ffba66d90613ad3cc8b1ac13df5bae6221f9']
const provider = new ethers.JsonRpcProvider(SERVER);
// Fund initial address first
const devAcc = getDevAccount();
const privateKey = '0x9979f9c93cbca19e905a21ce4d6ee9233948bcfe67d95c11de664ebe4b78c506';
const wallet = new ethers.Wallet(privateKey, provider);

const precalculatedSnAddress = await precalculateStarknetAddress(wallet.address);
await sendStrksFromSnAccount(devAcc, precalculatedSnAddress, '100000000000000000000') // sends 100 strk

const toAddress = '0xDbA5375833DBbA1D58C87864369D4Be5d1a24bCe';

const txRequest = await wallet.populateTransaction({
to: toAddress,
value: ethers.parseEther('1.0') // 1 STRK
});

const signedTx = await wallet.signTransaction(txRequest);

const txs = [signedTx, signedTx] // Sending same tx twice

const response = await axios.post(SERVER, [{
jsonrpc: '2.0',
Expand All @@ -127,9 +145,11 @@
jsonrpc: '2.0',
method: 'eth_sendRawTransaction',
params: [txs[1]],
id: 2,
id: 2,
}])

console.log(response.data)

Check failure on line 151 in e2e/rpc/sendRawTransaction.test.ts

View workflow job for this annotation

GitHub Actions / node

Unexpected console statement

expect(response.data.length).toBe(2)
expect(response.data[0].id).toBe(1)
expect(response.data[0].jsonrpc).toBe('2.0')
Expand Down
35 changes: 24 additions & 11 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const testConfig = {
'0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d',
rosettanet:
'0x007288a71619eca9397bf0d3066d236b41de33fd6af3a420d16b2f55c93f8af7',
validateFeeEstimator: "0x0",
featureTarget: "0x0000000000000000000000004645415455524553",
logging: {
active: true,
Expand Down Expand Up @@ -80,7 +81,7 @@ export async function updateNodeConfig(config: string) {
const configFilePath = path.resolve(__dirname, '../config.test.json')

await fs.writeFile(configFilePath, config, 'utf-8')
console.log('Configuration updated.')
console.log('Contracts deployed & Configuration updated.')
return
} catch (ex) {
console.error('Error at updating node config:', ex)
Expand Down Expand Up @@ -130,19 +131,31 @@ export function getEthStrkHolderAccount(): Account {
}

export async function sendStrksFromSnAccount(account: Account, recipient: string, amount: BigNumberish) {
await account.execute({
contractAddress: STRK_ADDRESS,
entrypoint: 'transfer',
calldata: [recipient, uint256.bnToUint256(amount).low, uint256.bnToUint256(amount).high]
})
try {
await account.execute({
contractAddress: STRK_ADDRESS,
entrypoint: 'transfer',
calldata: [recipient, uint256.bnToUint256(amount).low, uint256.bnToUint256(amount).high]
})
return true
} catch (e) {
console.log(e);
throw new Error("Failed to sendStrksFromSnAccount");
}
}

export async function sendERC20FromSnAccount(account: Account, erc20Contract: string, recipient: string, amount: BigNumberish) {
await account.execute({
contractAddress: erc20Contract,
entrypoint: 'transfer',
calldata: [recipient, uint256.bnToUint256(amount).low, uint256.bnToUint256(amount).high]
})
try {
await account.execute({
contractAddress: erc20Contract,
entrypoint: 'transfer',
calldata: [recipient, uint256.bnToUint256(amount).low, uint256.bnToUint256(amount).high]
})
return true
} catch (e) {
console.log(e);
throw new Error("Failed to sendERC20FromSnAccount");
}
}

export function getProvider(): RpcProvider {
Expand Down
3 changes: 1 addition & 2 deletions scripts/e2e_tests_specific.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ start_devnet() {
echo "Starting Starknet Devnet..."
starknet-devnet \
--seed "$SEED" \
--request-body-size-limit "$REQUEST_BODY_SIZE_LIMIT" \
--port "$PORT" &

# Store the PID of the devnet process
Expand All @@ -23,7 +22,7 @@ start_devnet() {
# Function to run E2E tests
run_e2e_tests() {
echo "Running E2E tests..."
jest --config ./e2e/jest_specific.config.ts --runInBand
npx jest --config ./e2e/jest_specific.config.ts --runInBand
}

# Function to cleanup devnet process
Expand Down
31 changes: 15 additions & 16 deletions src/rpc/calls/sendRawTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ export async function sendRawTransactionHandler(

const signedValidRawTransaction: SignedRawTransaction | ValidationError =
validateRawTransaction(tx)
writeLog(1, 'signed valid tx')
writeLog(1, JSON.stringify(signedValidRawTransaction,(k, v) => typeof v === 'bigint' ? v.toString() : v))
//console.log(signedValidRawTransaction)
writeLog(1, 'signed valid tx')
writeLog(1, JSON.stringify(signedValidRawTransaction, (k, v) => typeof v === 'bigint' ? v.toString() : v))
if (!isSignedRawTransaction(signedValidRawTransaction)) {
return {
jsonrpc: request.jsonrpc,
Expand All @@ -78,12 +77,11 @@ export async function sendRawTransactionHandler(
const deployedAccountAddress: RosettanetAccountResult =
await getRosettaAccountAddress(signedValidRawTransaction.from)
if (!deployedAccountAddress.isDeployed) {
writeLog(0, JSON.stringify(signedValidRawTransaction,(k, v) => typeof v === 'bigint' ? v.toString() : v))
writeLog(0, JSON.stringify(signedValidRawTransaction, (k, v) => typeof v === 'bigint' ? v.toString() : v))
return deployAndBroadcastTransaction(request, signedValidRawTransaction)
}

const starknetAccountAddress = deployedAccountAddress.contractAddress
// console.log(starknetAccountAddress)
const rosettanetCalldata = prepareRosettanetCalldata(
signedValidRawTransaction,
)
Expand Down Expand Up @@ -112,7 +110,7 @@ export async function sendRawTransactionHandler(
resourceBounds
)

writeLog(0, JSON.stringify(invokeTx,(k, v) => typeof v === 'bigint' ? v.toString() : v))
writeLog(0, JSON.stringify(invokeTx, (k, v) => typeof v === 'bigint' ? v.toString() : v))

return await broadcastTransaction(request, invokeTx)
}
Expand All @@ -124,14 +122,14 @@ async function broadcastTransaction(
): Promise<RPCResponse | RPCError> {
const response: RPCResponse | StarknetRPCError = await callStarknet(<
RPCRequest
>{
jsonrpc: request.jsonrpc,
id: request.id,
params: params,
method: 'starknet_addInvokeTransaction',
})
>{
jsonrpc: request.jsonrpc,
id: request.id,
params: params,
method: 'starknet_addInvokeTransaction',
})
if (isStarknetRPCError(response)) {
writeLog(1, 'Starknet RPC returned error at broadcastTransaction: ' + JSON.stringify(response,(k, v) => typeof v === 'bigint' ? v.toString() : v))
writeLog(1, 'Starknet RPC returned error at broadcastTransaction: ' + JSON.stringify(response, (k, v) => typeof v === 'bigint' ? v.toString() : v))
if (response.code == 55) {
return <RPCError>{
jsonrpc: request.jsonrpc,
Expand Down Expand Up @@ -168,7 +166,9 @@ async function deployAndBroadcastTransaction(
txn: SignedRawTransaction,
): Promise<RPCResponse | RPCError> {
const starknetNonce = '0x1'
writeLog(0,'will be deployed and executed')
writeLog(0, 'will be deployed and executed')

const resourceBounds = await resourceBoundsFromSignedTxn(txn);

// This means account is not registered on rosettanet registry. Lets deploy the address
const accountDeployResult: AccountDeployResult | AccountDeployError =
Expand Down Expand Up @@ -200,7 +200,6 @@ async function deployAndBroadcastTransaction(
}
}

const resourceBounds = await resourceBoundsFromSignedTxn(txn);

const invokeTx = prepareStarknetInvokeTransaction(
accountDeployResult.contractAddress,
Expand All @@ -211,6 +210,6 @@ async function deployAndBroadcastTransaction(
resourceBounds
)
writeLog(0, 'invoke tx')
writeLog(0,JSON.stringify(invokeTx,(k, v) => typeof v === 'bigint' ? v.toString() : v))
writeLog(0, JSON.stringify(invokeTx, (k, v) => typeof v === 'bigint' ? v.toString() : v))
return await broadcastTransaction(request, invokeTx)
}
Loading
Loading