Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(builtins): extension v3 #67

Open
wants to merge 1 commit into
base: release/galactica
Choose a base branch
from
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))

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