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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class StakingTransaction extends Transaction {
private _levelId: number;
private _autorenew = true;
private _amountToStake: string;
private _stakingContractABI: EthereumAbi;

constructor(_coinConfig: Readonly<CoinConfig>) {
super(_coinConfig);
Expand Down Expand Up @@ -53,14 +52,6 @@ export class StakingTransaction extends Transaction {
this._amountToStake = amount;
}

get stakingContractABI(): EthereumAbi {
return this._stakingContractABI;
}

set stakingContractABI(abi: EthereumAbi) {
this._stakingContractABI = abi;
}

buildClauses(): void {
if (!this.stakingContractAddress) {
throw new Error('Staking contract address is not set');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { TransactionClause } from '@vechain/sdk-core';
import { TransactionBuilder } from './transactionBuilder';
import { Transaction } from '../transaction/transaction';
import { StakingTransaction } from '../transaction/stakingTransaction';
import EthereumAbi from 'ethereumjs-abi';
import utils from '../utils';

export class StakingBuilder extends TransactionBuilder {
Expand Down Expand Up @@ -114,17 +113,6 @@ export class StakingBuilder extends TransactionBuilder {
return this;
}

/**
* Sets the staking contract ABI for this staking tx.
*
* @param {EthereumAbi} abi - The staking contract ABI
* @returns {StakingBuilder} This transaction builder
*/
stakingContractABI(abi: EthereumAbi): this {
this.stakingTransaction.stakingContractABI = abi;
return this;
}

/**
* Sets the transaction data for this staking tx.
*
Expand Down Expand Up @@ -156,7 +144,6 @@ export class StakingBuilder extends TransactionBuilder {
}
}

assert(transaction.stakingContractABI, 'Staking contract ABI is required');
assert(transaction.levelId, 'Level ID is required');
assert(transaction.autorenew, 'Autorenew flag is required');
this.validateAddress({ address: transaction.stakingContractAddress });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ describe('VET Staking Transaction', function () {
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.amountToStake(amountToStake);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);
txBuilder.sender('0x9378c12BD7502A11F770a5C1F223c959B2805dA9');
txBuilder.chainTag(0x27); // Testnet chain tag
txBuilder.blockRef('0x0000000000000000');
Expand All @@ -49,7 +48,6 @@ describe('VET Staking Transaction', function () {
stakingTx.amountToStake.should.equal(amountToStake);
stakingTx.levelId.should.equal(levelId);
stakingTx.autorenew.should.equal(autorenew);
stakingTx.stakingContractABI.should.deepEqual(EthereumAbi);

// Verify clauses
stakingTx.clauses.length.should.equal(1);
Expand Down Expand Up @@ -84,7 +82,6 @@ describe('VET Staking Transaction', function () {
const txBuilder = createBasicTxBuilder();
txBuilder.amountToStake(amountToStake);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);

await txBuilder.build().should.be.rejectedWith('Staking contract address is required');
});
Expand All @@ -93,7 +90,6 @@ describe('VET Staking Transaction', function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.amountToStake(amountToStake);
txBuilder.stakingContractABI(EthereumAbi);

await txBuilder.build().should.be.rejectedWith('Level ID is required');
});
Expand All @@ -102,7 +98,6 @@ describe('VET Staking Transaction', function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);

await txBuilder.build().should.be.rejectedWith('Amount to stake is required');
});
Expand All @@ -120,7 +115,6 @@ describe('VET Staking Transaction', function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);

// Invalid amount (not a number)
txBuilder.amountToStake('not-a-number');
Expand All @@ -129,33 +123,10 @@ describe('VET Staking Transaction', function () {
await txBuilder.build().should.be.rejected();
});

it('should pass validation with any ABI object but may fail during build', async function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.amountToStake(amountToStake);
txBuilder.levelId(levelId);

// Set an invalid ABI object
const invalidAbi = {};
txBuilder.stakingContractABI(invalidAbi as EthereumAbi);

// The validation will pass because it only checks if the ABI property exists
// But the build might fail if the ABI is actually used in the build process
// Since the actual encoding is done by utils.getStakingData() which doesn't use
// the ABI set on the transaction, this might still succeed
try {
await txBuilder.build();
} catch (e) {
// If it fails, it should be because of an invalid ABI
e.message.should.match(/methodID|rawEncode/);
}
});

it('should allow zero amountToStake but encode it properly', async function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);
txBuilder.amountToStake('0');

const tx = await txBuilder.build();
Expand Down Expand Up @@ -188,7 +159,6 @@ describe('VET Staking Transaction', function () {
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.amountToStake(amountToStake);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);
txBuilder.chainTag(0x27);
txBuilder.blockRef('0x0000000000000000');
txBuilder.expiration(64);
Expand Down Expand Up @@ -216,7 +186,6 @@ describe('VET Staking Transaction', function () {
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.amountToStake(amountToStake);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);
// Not setting chainTag
txBuilder.blockRef('0x0000000000000000');
txBuilder.expiration(64);
Expand All @@ -237,7 +206,6 @@ describe('VET Staking Transaction', function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);

// Test with a different amount
const differentAmount = '500000000000000000'; // 0.5 VET
Expand All @@ -264,7 +232,6 @@ describe('VET Staking Transaction', function () {
const txBuilder = createBasicTxBuilder();
txBuilder.stakingContractAddress(stakingContractAddress);
txBuilder.levelId(levelId);
txBuilder.stakingContractABI(EthereumAbi);

// Test with a very large amount (near uint256 max)
const largeAmount = '115792089237316195423570985008687907853269984665640564039457584007913129639935'; // 2^256 - 1
Expand Down