Skip to content

Commit

Permalink
additional
Browse files Browse the repository at this point in the history
  • Loading branch information
igorcrevar committed Feb 15, 2024
1 parent 4c3182d commit 97f2dd4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,102 +3,64 @@
"contractName": "TestValidatorSetPrecompile",
"sourceName": "consensus/polybft/contractsapi/test-contracts/TestValidatorSetContract.sol",
"abi": [
{
"inputs":[

],
"name":"VALIDATOR_SET_PRECOMPILE",
"outputs":[
{
"internalType":"address",
"name":"",
"type":"address"
}
],
"stateMutability":"view",
"type":"function"
},
{
"inputs":[

],
"name":"VALIDATOR_SET_PRECOMPILE_GAS",
"outputs":[
{
"internalType":"uint256",
"name":"",
"type":"uint256"
}
],
"stateMutability":"view",
"type":"function"
},
{
"inputs":[

],
"name":"hasQuorum",
"outputs":[
{
"internalType":"bool",
"name":"",
"type":"bool"
}
],
"stateMutability":"view",
"type":"function"
{
"inputs":[

],
"name":"VALIDATOR_SET_PRECOMPILE",
"outputs":[
{
"internalType":"address",
"name":"",
"type":"address"
}
],
"stateMutability":"view",
"type":"function"
},
{
"inputs":[

],
"name":"inc",
"outputs":[

],
"stateMutability":"nonpayable",
"type":"function"
"inputs":[

],
"name":"VALIDATOR_SET_PRECOMPILE_GAS",
"outputs":[
{
"internalType":"uint256",
"name":"",
"type":"uint256"
}
],
"stateMutability":"view",
"type":"function"
},
{
"inputs":[
{
"internalType":"address",
"name":"",
"type":"address"
}
],
"name":"voteMap",
"outputs":[
{
"internalType":"bool",
"name":"",
"type":"bool"
}
],
"stateMutability":"view",
"type":"function"
"inputs":[

],
"name":"hasQuorum",
"outputs":[
{
"internalType":"bool",
"name":"",
"type":"bool"
}
],
"stateMutability":"view",
"type":"function"
},
{
"inputs":[
{
"internalType":"uint256",
"name":"",
"type":"uint256"
}
],
"name":"votes",
"outputs":[
{
"internalType":"address",
"name":"",
"type":"address"
}
],
"stateMutability":"view",
"type":"function"
"inputs":[

],
"name":"inc",
"outputs":[

],
"stateMutability":"nonpayable",
"type":"function"
}
],
"bytecode": "0x608060405234801561000f575f80fd5b5061085c8061001d5f395ff3fe608060405234801561000f575f80fd5b5060043610610060575f3560e01c8063371303c0146100645780635df813301461006e5780635e4f94881461009e578063815b4d1b146100bc57806384005d56146100da578063965844a6146100f8575b5f80fd5b61006c610128565b005b6100886004803603810190610083919061046e565b61031e565b60405161009591906104d8565b60405180910390f35b6100a6610359565b6040516100b391906104d8565b60405180910390f35b6100c461035f565b6040516100d1919061050b565b60405180910390f35b6100e2610414565b6040516100ef9190610533565b60405180910390f35b610112600480360381019061010d9190610576565b61041b565b60405161011f919061050b565b60405180910390f35b5f8061204073ffffffffffffffffffffffffffffffffffffffff16620249f03360405160200161015891906104d8565b604051602081830303815290604052604051610174919061060d565b5f604051808303818686fa925050503d805f81146101ad576040519150601f19603f3d011682016040523d82523d5f602084013e6101b2565b606091505b50915091505f8280156101d55750818060200190518101906101d4919061064d565b5b905080610217576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161020e906106d2565b60405180910390fd5b5f803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900460ff1661031957600133908060018154018082558091505060019003905f5260205f20015f9091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060015f803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548160ff0219169083151502179055505b505050565b6001818154811061032d575f80fd5b905f5260205f20015f915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b61204081565b5f805f61204073ffffffffffffffffffffffffffffffffffffffff16620249f060016040516020016103919190610806565b6040516020818303038152906040526040516103ad919061060d565b5f604051808303818686fa925050503d805f81146103e6576040519150601f19603f3d011682016040523d82523d5f602084013e6103eb565b606091505b509150915081801561040d57508080602001905181019061040c919061064d565b5b9250505090565b620249f081565b5f602052805f5260405f205f915054906101000a900460ff1681565b5f80fd5b5f819050919050565b61044d8161043b565b8114610457575f80fd5b50565b5f8135905061046881610444565b92915050565b5f6020828403121561048357610482610437565b5b5f6104908482850161045a565b91505092915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6104c282610499565b9050919050565b6104d2816104b8565b82525050565b5f6020820190506104eb5f8301846104c9565b92915050565b5f8115159050919050565b610505816104f1565b82525050565b5f60208201905061051e5f8301846104fc565b92915050565b61052d8161043b565b82525050565b5f6020820190506105465f830184610524565b92915050565b610555816104b8565b811461055f575f80fd5b50565b5f813590506105708161054c565b92915050565b5f6020828403121561058b5761058a610437565b5b5f61059884828501610562565b91505092915050565b5f81519050919050565b5f81905092915050565b5f5b838110156105d25780820151818401526020810190506105b7565b5f8484015250505050565b5f6105e7826105a1565b6105f181856105ab565b93506106018185602086016105b5565b80840191505092915050565b5f61061882846105dd565b915081905092915050565b61062c816104f1565b8114610636575f80fd5b50565b5f8151905061064781610623565b92915050565b5f6020828403121561066257610661610437565b5b5f61066f84828501610639565b91505092915050565b5f82825260208201905092915050565b7f76616c696461746f72206f6e6c790000000000000000000000000000000000005f82015250565b5f6106bc600e83610678565b91506106c782610688565b602082019050919050565b5f6020820190508181035f8301526106e9816106b0565b9050919050565b5f81549050919050565b5f82825260208201905092915050565b5f819050815f5260205f209050919050565b610725816104b8565b82525050565b5f610736838361071c565b60208301905092915050565b5f815f1c9050919050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61077e61077983610742565b61074d565b9050919050565b5f610790825461076c565b9050919050565b5f600182019050919050565b5f6107ad826106f0565b6107b781856106fa565b93506107c28361070a565b805f5b838110156107f9576107d682610785565b6107e0888261072b565b97506107eb83610797565b9250506001810190506107c5565b5085935050505092915050565b5f6020820190508181035f83015261081e81846107a3565b90509291505056fea26469706673582212204da3517de3a7d78ba0f5c424a698f8d7833d8bf6d56911c8075e8e6546a8649264736f6c63430008180033",
"bytecode": "0x608060405234801561000f575f80fd5b506106ea8061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c8063371303c01461004e5780635e4f948814610058578063815b4d1b1461007657806384005d5614610094575b5f80fd5b6100566100b2565b005b6100606102a8565b60405161006d91906103ae565b60405180910390f35b61007e6102ae565b60405161008b91906103e1565b60405180910390f35b61009c610368565b6040516100a99190610412565b60405180910390f35b5f8061204073ffffffffffffffffffffffffffffffffffffffff16620249f0336040516020016100e291906103ae565b6040516020818303038152906040526040516100fe9190610497565b5f604051808303818686fa925050503d805f8114610137576040519150601f19603f3d011682016040523d82523d5f602084013e61013c565b606091505b50915091505f8180602001905181019061015691906104db565b90508280156101625750805b6101a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161019890610560565b60405180910390fd5b5f803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f9054906101000a900460ff166102a357600133908060018154018082558091505060019003905f5260205f20015f9091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060015f803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f6101000a81548160ff0219169083151502179055505b505050565b61204081565b5f805f61204073ffffffffffffffffffffffffffffffffffffffff16620249f060016040516020016102e09190610694565b6040516020818303038152906040526040516102fc9190610497565b5f604051808303818686fa925050503d805f8114610335576040519150601f19603f3d011682016040523d82523d5f602084013e61033a565b606091505b50915091505f8180602001905181019061035491906104db565b90508280156103605750805b935050505090565b620249f081565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6103988261036f565b9050919050565b6103a88161038e565b82525050565b5f6020820190506103c15f83018461039f565b92915050565b5f8115159050919050565b6103db816103c7565b82525050565b5f6020820190506103f45f8301846103d2565b92915050565b5f819050919050565b61040c816103fa565b82525050565b5f6020820190506104255f830184610403565b92915050565b5f81519050919050565b5f81905092915050565b5f5b8381101561045c578082015181840152602081019050610441565b5f8484015250505050565b5f6104718261042b565b61047b8185610435565b935061048b81856020860161043f565b80840191505092915050565b5f6104a28284610467565b915081905092915050565b5f80fd5b6104ba816103c7565b81146104c4575f80fd5b50565b5f815190506104d5816104b1565b92915050565b5f602082840312156104f0576104ef6104ad565b5b5f6104fd848285016104c7565b91505092915050565b5f82825260208201905092915050565b7f76616c696461746f72206f6e6c790000000000000000000000000000000000005f82015250565b5f61054a600e83610506565b915061055582610516565b602082019050919050565b5f6020820190508181035f8301526105778161053e565b9050919050565b5f81549050919050565b5f82825260208201905092915050565b5f819050815f5260205f209050919050565b6105b38161038e565b82525050565b5f6105c483836105aa565b60208301905092915050565b5f815f1c9050919050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61060c610607836105d0565b6105db565b9050919050565b5f61061e82546105fa565b9050919050565b5f600182019050919050565b5f61063b8261057e565b6106458185610588565b935061065083610598565b805f5b838110156106875761066482610613565b61066e88826105b9565b975061067983610625565b925050600181019050610653565b5085935050505092915050565b5f6020820190508181035f8301526106ac8184610631565b90509291505056fea2646970667358221220efe83875fb1246787277c88a460f768e19f019c8e2e557e6d05731425a3210f864736f6c63430008180033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ contract TestValidatorSetPrecompile {
address public constant VALIDATOR_SET_PRECOMPILE = 0x0000000000000000000000000000000000002040;
uint256 public constant VALIDATOR_SET_PRECOMPILE_GAS = 150000;

mapping(address => bool) public voteMap;
address[] public votes;
mapping(address => bool) voteMap;
address[] votes;

modifier onlyValidator() {
(bool callSuccess, bytes memory returnData) = VALIDATOR_SET_PRECOMPILE.staticcall{
gas: VALIDATOR_SET_PRECOMPILE_GAS
}(abi.encode(msg.sender));
bool isValidator = callSuccess && abi.decode(returnData, (bool));
require(isValidator, "validator only");
bool state = abi.decode(returnData, (bool));
require(callSuccess && state, "validator only");
_;
}

Expand All @@ -30,6 +30,7 @@ contract TestValidatorSetPrecompile {
(bool callSuccess, bytes memory returnData) = VALIDATOR_SET_PRECOMPILE.staticcall{
gas: VALIDATOR_SET_PRECOMPILE_GAS
}(abi.encode(votes));
return callSuccess && abi.decode(returnData, (bool));
bool state = abi.decode(returnData, (bool));
return callSuccess && state;
}
}
30 changes: 20 additions & 10 deletions e2e-polybft/e2e/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/genesis"
"github.com/0xPolygon/polygon-edge/command/validator/helper"

Check failure on line 20 in e2e-polybft/e2e/consensus_test.go

View workflow job for this annotation

GitHub Actions / Lint / Run Lint

ST1019: package "github.com/0xPolygon/polygon-edge/command/validator/helper" is being imported more than once (stylecheck)
validatorHelper "github.com/0xPolygon/polygon-edge/command/validator/helper"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
Expand Down Expand Up @@ -826,22 +827,31 @@ func TestE2E_TestValidatorSetPrecompile(t *testing.T) {
admin, err := wallet.GenerateKey()
require.NoError(t, err)

validators := []types.Address(nil)
validatorAddrs := []types.Address(nil)
adminAddr := types.Address(admin.Address())

cluster := framework.NewTestCluster(t, 4,
framework.WithBladeAdmin(adminAddr.String()),
framework.WithSecretsCallback(func(addrs []types.Address, _ *framework.TestClusterConfig) {
validators = addrs
validatorAddrs = addrs
}))
defer cluster.Stop()

cluster.WaitForReady(t)

validatorKeys := make([]*wallet.Key, len(validatorAddrs))

for i, s := range cluster.Servers {
voterAcc, err := helper.GetAccountFromDir(s.DataDir())
require.NoError(t, err)

validatorKeys[i] = voterAcc.Ecdsa
}

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithClient(cluster.Servers[0].JSONRPC()))
require.NoError(t, err)

// deploy Wrapper contract
// deploy contract
receipt, err := txRelayer.SendTransaction(
&ethgo.Transaction{
To: nil,
Expand All @@ -866,7 +876,7 @@ func TestE2E_TestValidatorSetPrecompile(t *testing.T) {
return response == "true"
}

sendIncTx := func(addr types.Address) {
sendIncTx := func(validatorID int) {
t.Helper()

incFn := contractsapi.TestValidatorSetPrecompile.Abi.GetMethod("inc")
Expand All @@ -875,27 +885,27 @@ func TestE2E_TestValidatorSetPrecompile(t *testing.T) {
require.NoError(t, err)

txn := &ethgo.Transaction{
From: ethgo.Address(addr),
From: ethgo.Address(validatorAddrs[validatorID]),
To: &validatorSetPrecompileTestAddr,
Input: incFnBytes,
}

receipt, err = txRelayer.SendTransaction(txn, admin)
receipt, err = txRelayer.SendTransaction(txn, validatorKeys[validatorID])
require.NoError(t, err)
require.Equal(t, uint64(types.ReceiptSuccess), receipt.Status)
}

require.False(t, hasQuorum())

sendIncTx(validators[0])
sendIncTx(0)
require.False(t, hasQuorum())

sendIncTx(validators[1])
sendIncTx(1)
require.False(t, hasQuorum())

sendIncTx(validators[1])
sendIncTx(1)
require.False(t, hasQuorum())

sendIncTx(validators[3])
sendIncTx(3)
require.True(t, hasQuorum())
}

0 comments on commit 97f2dd4

Please sign in to comment.