Skip to content

Commit

Permalink
Add blobbasefee unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
timemarkovqtum committed Sep 11, 2024
1 parent b457176 commit ddcfaa5
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions src/test/qtumtests/cancunfork_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const dev::h256 HASHTX = dev::h256(ParseHex("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

// Codes used to check that cancun fork
const std::vector<valtype> CODE = {
// EIP-1153
/*
pragma solidity ^0.8.24;
Expand All @@ -30,19 +31,37 @@ const std::vector<valtype> CODE = {
return value * getMultiplier();
}
}
*/ valtype(ParseHex("6080604052348015600e575f80fd5b506101db8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c8063641579a614610038578063c6888fa114610054575b5f80fd5b610052600480360381019061004d91906100e4565b610084565b005b61006e600480360381019061006991906100e4565b61008a565b60405161007b919061011e565b60405180910390f35b805f5d50565b5f6100936100a5565b8261009e9190610164565b9050919050565b5f805c905090565b5f80fd5b5f819050919050565b6100c3816100b1565b81146100cd575f80fd5b50565b5f813590506100de816100ba565b92915050565b5f602082840312156100f9576100f86100ad565b5b5f610106848285016100d0565b91505092915050565b610118816100b1565b82525050565b5f6020820190506101315f83018461010f565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61016e826100b1565b9150610179836100b1565b9250828202610187816100b1565b9150828204841483151761019e5761019d610137565b5b509291505056fea26469706673582212203dda524f45e82e20c7a5140d36ef2410c23bec4dee31ca21bc368cf508cde0f764736f6c634300081a0033")),
*/
valtype(ParseHex("6080604052348015600e575f80fd5b506101db8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c8063641579a614610038578063c6888fa114610054575b5f80fd5b610052600480360381019061004d91906100e4565b610084565b005b61006e600480360381019061006991906100e4565b61008a565b60405161007b919061011e565b60405180910390f35b805f5d50565b5f6100936100a5565b8261009e9190610164565b9050919050565b5f805c905090565b5f80fd5b5f819050919050565b6100c3816100b1565b81146100cd575f80fd5b50565b5f813590506100de816100ba565b92915050565b5f602082840312156100f9576100f86100ad565b5b5f610106848285016100d0565b91505092915050565b610118816100b1565b82525050565b5f6020820190506101315f83018461010f565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61016e826100b1565b9150610179836100b1565b9250828202610187816100b1565b9150828204841483151761019e5761019d610137565b5b509291505056fea26469706673582212203dda524f45e82e20c7a5140d36ef2410c23bec4dee31ca21bc368cf508cde0f764736f6c634300081a0033")),
// setMultiplier(5)
valtype(ParseHex("641579a60000000000000000000000000000000000000000000000000000000000000005")),
// multiply(7)
valtype(ParseHex("c6888fa10000000000000000000000000000000000000000000000000000000000000007")),
// EIP-7516
/*
pragma solidity 0.8.25;
contract BlobBaseFee {
function getBlobBaseFee() external view returns (uint256 blobBaseFee) {
assembly {
blobBaseFee := blobbasefee()
}
}
}
*/
valtype(ParseHex("6080604052348015600e575f80fd5b5060ae80601a5f395ff3fe6080604052348015600e575f80fd5b50600436106026575f3560e01c80631f6d6ef714602a575b5f80fd5b60306044565b604051603b91906061565b60405180910390f35b5f4a905090565b5f819050919050565b605b81604b565b82525050565b5f60208201905060725f8301846054565b9291505056fea2646970667358221220d07c85aaeda13f99ab3684717e3cb625952e90b29aeb1493d1e517a3832d385564736f6c63430008190033")),
// getBlobBaseFee()
valtype(ParseHex("1f6d6ef7")),
};

// Codes IDs used to check that london fork is present
enum class CodeID
{
mulService = 0,
transientStorageContract = 0,
setMultiplier_5,
multiply_7,
blobBaseFeeContract,
getBlobBaseFee
};

// Get the code identified by the ID
Expand Down Expand Up @@ -91,7 +110,7 @@ BOOST_AUTO_TEST_CASE(checking_transient_storage_after_fork){

// Create contract
std::vector<QtumTransaction> txs;
txs.push_back(createQtumTransaction(getCode(CodeID::mulService), 0, GASLIMIT, dev::u256(1), ++hashTx, dev::Address()));
txs.push_back(createQtumTransaction(getCode(CodeID::transientStorageContract), 0, GASLIMIT, dev::u256(1), ++hashTx, dev::Address()));
auto result = executeBC(txs, *m_node.chainman);
BOOST_CHECK(result.first[0].execRes.excepted == dev::eth::TransactionException::None);

Expand Down Expand Up @@ -128,7 +147,7 @@ BOOST_AUTO_TEST_CASE(checking_transient_storage_before_fork){

// Create contract
std::vector<QtumTransaction> txs;
txs.push_back(createQtumTransaction(getCode(CodeID::mulService), 0, GASLIMIT, dev::u256(1), ++hashTx, dev::Address()));
txs.push_back(createQtumTransaction(getCode(CodeID::transientStorageContract), 0, GASLIMIT, dev::u256(1), ++hashTx, dev::Address()));
auto result = executeBC(txs, *m_node.chainman);
BOOST_CHECK(result.first[0].execRes.excepted == dev::eth::TransactionException::None);

Expand All @@ -142,6 +161,47 @@ BOOST_AUTO_TEST_CASE(checking_transient_storage_before_fork){
BOOST_CHECK(result.first[1].execRes.excepted == dev::eth::TransactionException::BadInstruction);
}

BOOST_AUTO_TEST_CASE(checking_blobbasefee_after_fork){
genesisLoading();
createNewBlocks(this, 499);
dev::h256 hashTx(HASHTX);

// Create contract
std::vector<QtumTransaction> txs;
txs.push_back(createQtumTransaction(getCode(CodeID::blobBaseFeeContract), 0, GASLIMIT, dev::u256(1), ++hashTx, dev::Address()));
auto result = executeBC(txs, *m_node.chainman);
BOOST_CHECK(result.first[0].execRes.excepted == dev::eth::TransactionException::None);

// Check that blobbasefee is 0
dev::Address proxy = createQtumAddress(txs[0].getHashWith(), txs[0].getNVout());
std::vector<QtumTransaction> txCancun;
txCancun.push_back(createQtumTransaction(getCode(CodeID::getBlobBaseFee), 0, GASLIMIT, dev::u256(1), ++hashTx, proxy));
result = executeBC(txCancun, *m_node.chainman);
BOOST_CHECK(result.first[0].execRes.excepted == dev::eth::TransactionException::None);
BOOST_CHECK(result.first[0].execRes.gasUsed == 21373);
BOOST_CHECK(result.first[0].execRes.output.size() == 32);
BOOST_CHECK(dev::h256(result.first[0].execRes.output) == dev::h256(0));
}

BOOST_AUTO_TEST_CASE(checking_blobbasefee_before_fork){
genesisLoading();
createNewBlocks(this, 498);
dev::h256 hashTx(HASHTX);

// Create contract
std::vector<QtumTransaction> txs;
txs.push_back(createQtumTransaction(getCode(CodeID::blobBaseFeeContract), 0, GASLIMIT, dev::u256(1), ++hashTx, dev::Address()));
auto result = executeBC(txs, *m_node.chainman);
BOOST_CHECK(result.first[0].execRes.excepted == dev::eth::TransactionException::None);

// Check that blobbasefee is bad instruction
dev::Address proxy = createQtumAddress(txs[0].getHashWith(), txs[0].getNVout());
std::vector<QtumTransaction> txCancun;
txCancun.push_back(createQtumTransaction(getCode(CodeID::getBlobBaseFee), 0, GASLIMIT, dev::u256(1), ++hashTx, proxy));
result = executeBC(txCancun, *m_node.chainman);
BOOST_CHECK(result.first[0].execRes.excepted == dev::eth::TransactionException::BadInstruction);
}

BOOST_AUTO_TEST_SUITE_END()

}

0 comments on commit ddcfaa5

Please sign in to comment.