Skip to content

Commit

Permalink
feat(builtins): extension v3
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Jan 20, 2025
1 parent 5011531 commit 78d0d0c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
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))

Check failure on line 34 in test/evm/builtins/extension.test.js

View workflow job for this annotation

GitHub Actions / Run E2E Tests

test/evm/builtins/extension.test.js > Builtin :: Extension > should be able to get the clause count

AssertionError: expected '0x' to deeply equal '0x00000000000000000000000000000000000…' Expected: "0x0000000000000000000000000000000000000000000000000000000000000064" Received: "0x" ❯ test/evm/builtins/extension.test.js:34:44

Check failure on line 34 in test/evm/builtins/extension.test.js

View workflow job for this annotation

GitHub Actions / Run E2E Tests

test/evm/builtins/extension.test.js > Builtin :: Extension > should be able to get the clause count

AssertionError: expected '0x' to deeply equal '0x00000000000000000000000000000000000…' Expected: "0x0000000000000000000000000000000000000000000000000000000000000064" Received: "0x" ❯ test/evm/builtins/extension.test.js:34:44

Check failure on line 34 in test/evm/builtins/extension.test.js

View workflow job for this annotation

GitHub Actions / Run E2E Tests

test/evm/builtins/extension.test.js > Builtin :: Extension > should be able to get the clause count

AssertionError: expected '0x' to deeply equal '0x00000000000000000000000000000000000…' Expected: "0x0000000000000000000000000000000000000000000000000000000000000064" Received: "0x" ❯ test/evm/builtins/extension.test.js:34:44

Check failure on line 34 in test/evm/builtins/extension.test.js

View workflow job for this annotation

GitHub Actions / Run E2E Tests

test/evm/builtins/extension.test.js > Builtin :: Extension > should be able to get the clause count

AssertionError: expected '0x' to deeply equal '0x00000000000000000000000000000000000…' Expected: "0x0000000000000000000000000000000000000000000000000000000000000064" Received: "0x" ❯ test/evm/builtins/extension.test.js:34:44
}
})

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))

Check failure on line 61 in test/evm/builtins/extension.test.js

View workflow job for this annotation

GitHub Actions / Run E2E Tests

test/evm/builtins/extension.test.js > Builtin :: Extension > should be able to get the clause index

AssertionError: expected '0x' to deeply equal '0x00000000000000000000000000000000000…' Expected: "0x0000000000000000000000000000000000000000000000000000000000000000" Received: "0x" ❯ test/evm/builtins/extension.test.js:61:44

Check failure on line 61 in test/evm/builtins/extension.test.js

View workflow job for this annotation

GitHub Actions / Run E2E Tests

test/evm/builtins/extension.test.js > Builtin :: Extension > should be able to get the clause index

AssertionError: expected '0x' to deeply equal '0x00000000000000000000000000000000000…' Expected: "0x0000000000000000000000000000000000000000000000000000000000000000" Received: "0x" ❯ test/evm/builtins/extension.test.js:61:44

Check failure on line 61 in test/evm/builtins/extension.test.js

View workflow job for this annotation

GitHub Actions / Run E2E Tests

test/evm/builtins/extension.test.js > Builtin :: Extension > should be able to get the clause index

AssertionError: expected '0x' to deeply equal '0x00000000000000000000000000000000000…' Expected: "0x0000000000000000000000000000000000000000000000000000000000000000" Received: "0x" ❯ test/evm/builtins/extension.test.js:61:44

Check failure on line 61 in test/evm/builtins/extension.test.js

View workflow job for this annotation

GitHub Actions / Run E2E Tests

test/evm/builtins/extension.test.js > Builtin :: Extension > should be able to get the clause index

AssertionError: expected '0x' to deeply equal '0x00000000000000000000000000000000000…' Expected: "0x0000000000000000000000000000000000000000000000000000000000000000" Received: "0x" ❯ test/evm/builtins/extension.test.js:61:44
}
})
})

0 comments on commit 78d0d0c

Please sign in to comment.