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
136 changes: 136 additions & 0 deletions e2e/tests/ton/executable.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
"fmt"
"math/big"
"strconv"
"testing"

"github.com/stretchr/testify/suite"

Check failure on line 13 in e2e/tests/ton/executable.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

File is not properly formatted (gofmt)
"github.com/stretchr/testify/require"

chainsel "github.com/smartcontractkit/chain-selectors"

chainwrappermocks "github.com/smartcontractkit/mcms/chainwrappers/mocks"

Check failure on line 18 in e2e/tests/ton/executable.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

File is not properly formatted (goimports)
"github.com/xssnick/tonutils-go/address"
"github.com/xssnick/tonutils-go/tlb"
"github.com/xssnick/tonutils-go/ton/wallet"
Expand Down Expand Up @@ -229,6 +232,121 @@
s.Require().Contains(proposers, s.mcmsAddr)
}

func (s *ExecutionTestSuite) TestScheduleAndCancelProposal() {
tests := []struct {
name string
targetRoles []*big.Int
}{
{
name: "valid schedule and cancel proposal with one tx and one op",
targetRoles: []*big.Int{timelock.RoleProposer},
},
{
name: "valid schedule and cancel proposal with one tx and three ops",
targetRoles: []*big.Int{timelock.RoleProposer, timelock.RoleBypasser, timelock.RoleCanceller},
},
}

for _, tt := range tests {
s.Run(tt.name, func() {
ctx := s.T().Context()

inspector := mcmston.NewInspector(s.TonClient)
opCount, err := inspector.GetOpCount(ctx, s.mcmsAddr)
s.Require().NoError(err)

chainID, err := strconv.ParseInt(s.TonBlockchain.ChainID, 10, 32)
s.Require().NoError(err)

grantee := must(tvm.NewRandomV5R1TestWallet(s.TonClient, int32(chainID))).Address()
accessor := chainwrappermocks.NewChainAccessor(s.T())
accessor.EXPECT().TonClient(uint64(s.ChainA)).Return(s.TonClient, true).Maybe()
accessor.EXPECT().TonSigner(uint64(s.ChainA)).Return(s.wallet, true).Maybe()

mcmslib.RunScheduleAndCancelTest(s.T(), mcmslib.ScheduleAndCancelTestHooks{
Setup: func(ctx context.Context, t *testing.T) (mcmslib.ScheduleAndCancelTestEnv, error) {

Check failure on line 267 in e2e/tests/ton/executable.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

test helper function should start from t.Helper() (thelper)
transactions := make([]types.Transaction, 0, len(tt.targetRoles))
for i, role := range tt.targetRoles {
grantRoleData, grantErr := tlb.ToCell(rbac.GrantRole{
QueryID: uint64(i + 1),
Role: tlbe.NewUint256(role),
Account: grantee,
})
if grantErr != nil {
return mcmslib.ScheduleAndCancelTestEnv{}, grantErr
}

tx, txErr := mcmston.NewTransaction(
address.MustParseAddr(s.timelockAddr),
grantRoleData.ToBuilder().ToSlice(),
tlb.MustFromTON("0.1").Nano(),
bindings.ShortTimelock,
nil,
bindings.TypeTimelock,
[]string{bindings.ShortTimelock, "GrantRole"},
)
if txErr != nil {
return mcmslib.ScheduleAndCancelTestEnv{}, txErr
}

transactions = append(transactions, tx)
}

return mcmslib.ScheduleAndCancelTestEnv{
Proposal: mcmslib.TimelockProposal{
BaseProposal: mcmslib.BaseProposal{
Version: "v1",
Kind: types.KindTimelockProposal,
Description: "Cancels scheduled TON timelock role grants",
ValidUntil: 2004259681,
OverridePreviousRoot: false,
Signatures: []types.Signature{},
ChainMetadata: map[types.ChainSelector]types.ChainMetadata{
s.ChainA: {
StartingOpCount: opCount,
MCMAddress: s.mcmsAddr,
AdditionalFields: testOpAdditionalFields,
},
},
},
Action: types.TimelockActionSchedule,
Delay: types.MustParseDuration("5m"),
TimelockAddresses: map[types.ChainSelector]string{
s.ChainA: s.timelockAddr,
},
Operations: []types.BatchOperation{
{
ChainSelector: s.ChainA,
Transactions: transactions,
},
},
},
Chains: accessor,
}, nil
},
Sign: func(t *testing.T, signable *mcmslib.Signable) {

Check failure on line 327 in e2e/tests/ton/executable.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

test helper function should start from t.Helper() (thelper)
_, err := signable.SignAndAppend(mcmslib.NewPrivateKeySigner(s.signers[1].Key))
require.NoError(t, err)
},
WaitForTransaction: func(ctx context.Context, t *testing.T, tx types.TransactionResult) {

Check failure on line 331 in e2e/tests/ton/executable.go

View workflow job for this annotation

GitHub Actions / Lint E2E tests

test helper function should start from t.Helper() (thelper)
rawTx, ok := tx.RawData.(*tlb.Transaction)
require.True(t, ok)
require.NotNil(t, rawTx)
require.NoError(t, tracetracking.WaitForTrace(ctx, s.TonClient, rawTx))
},
AssertExtraAfterCancel: func(ctx context.Context, t *testing.T, env *mcmslib.ScheduleAndCancelTestEnv) {
inspectorT := mcmston.NewTimelockInspector(s.TonClient)
for _, role := range tt.targetRoles {
members, membersErr := tonRoleMembersFor(ctx, inspectorT, s.timelockAddr, role)
require.NoError(t, membersErr)
require.NotContains(t, members, grantee.String())
}
},
})
})
}
}

// TestExecuteProposalMultiple executes 2 proposals to check nonce calculation mechanisms are working
func (s *ExecutionTestSuite) TestExecuteProposalMultiple() {
ctx := context.Background()
Expand Down Expand Up @@ -1005,3 +1123,21 @@
func (i mockEVMInspector) GetRootMetadata(ctx context.Context, mcmAddr string) (types.ChainMetadata, error) {
return i.rootMetadata, nil
}

func tonRoleMembersFor(
ctx context.Context,
inspector sdk.TimelockInspector,
timelockAddr string,
role *big.Int,
) ([]string, error) {
switch {
case role.Cmp(timelock.RoleProposer) == 0:
return inspector.GetProposers(ctx, timelockAddr)
case role.Cmp(timelock.RoleBypasser) == 0:
return inspector.GetBypassers(ctx, timelockAddr)
case role.Cmp(timelock.RoleCanceller) == 0:
return inspector.GetCancellers(ctx, timelockAddr)
default:
return nil, fmt.Errorf("unsupported timelock role: %s", role.String())
}
}
Loading
Loading