Skip to content
Open
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
4 changes: 4 additions & 0 deletions contracts/built-in/Extension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ interface Extension {

/// @notice Get the account that pays the TX fee at runtime.
function txGasPayer() external view returns (address);

// extension v3 methods
function txClauseIndex() external view returns (uint256);
function txClauseCount() external view returns (uint256);
}
2 changes: 1 addition & 1 deletion network/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ETH_IST": 0,
"VIP214": 0,
"FINALITY": 0,
"GALACTICA": 0
"GALACTICA": 1
},
"accounts": [
{
Expand Down
64 changes: 64 additions & 0 deletions test/evm/builtins/extension.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ThorWallet } from '../../../src/wallet'
import { Client } from '../../../src/thor-client'
import { contractAddresses } from '../../../src/contracts/addresses'
import { Extension__factory } from '../../../typechain-types'
import { addUintPadding } from '../../../src/utils/padding-utils'

describe('Builtin :: Extension', () => {
const wallet = ThorWallet.withFunds()
const extension = Client.sdk.contracts.load(
contractAddresses.extension,
Extension__factory.abi,
)

it.e2eTest('should be able to get the clause count', 'all', async () => {
const count = 100
const contractCall = await extension.clause.txClauseCount()
const clause = {
to: extension.address,
value: '0x0',
data: contractCall.clause.data,
}
const best = await Client.raw.getBlock('best')
const clauses = Array.from({ length: count }).map(() => clause)
const batchCall = await Client.raw.executeAccountBatch(
{
gas: 10_000_000,
caller: wallet.address,
clauses,
},
best.body.id,
)

for (let i = 0; i < count; i++) {
expect(batchCall.body[i].data).toEqual('0x' + addUintPadding(count))
}
})

it.e2eTest('should be able to get the clause index', 'all', async () => {
const amount = 50

const contractCall = await extension.clause.txClauseIndex()
const clause = {
to: extension.address,
value: '0x0',
data: contractCall.clause.data,
}

const clauses = Array.from({ length: amount }).map(() => clause)

const best = await Client.raw.getBlock('best')
const batchCall = await Client.raw.executeAccountBatch(
{
gas: 10_000_000,
caller: wallet.address,
clauses,
},
best.body.id,
)

for (let i = 0; i < amount; i++) {
expect(batchCall.body[i].data).toEqual('0x' + addUintPadding(i))
}
})
})