Skip to content

Commit

Permalink
fix: remove valid unit to reuse util for proposal creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ecPablo committed Dec 13, 2024
1 parent f0aa7da commit 7c2ecf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 40 deletions.
28 changes: 8 additions & 20 deletions deployment/common/changeset/example/link_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type TransferConfig struct {
}

type MCMSConfig struct {
ValidUntil uint32 // unix time until the proposal will be valid
MinDelay time.Duration // delay for timelock worker to execute the transfers.
OverrideRoot bool
}
Expand Down Expand Up @@ -113,10 +112,7 @@ func (cfg LinkTransferConfig) Validate(e deployment.Environment) error {
if cfg.McmsConfig.MinDelay > MaxTimelockDelay {
return errors.New("minDelay must be less than 7 days")
}
// Check that validUntil is in the future
if time.Unix(int64(cfg.McmsConfig.ValidUntil), 0).Before(time.Now()) {
return fmt.Errorf("validUntil must be in the future")
}

return nil
}

Expand Down Expand Up @@ -180,7 +176,7 @@ func LinkTransfer(e deployment.Environment, cfg *LinkTransferConfig) (deployment
}
mcmsPerChain := map[uint64]*owner_helpers.ManyChainMultiSig{}

timelockAddresses := map[mcms.ChainIdentifier]common.Address{}
timelockAddresses := map[uint64]common.Address{}
// Initialize state for each chain
linkStatePerChain, mcmsStatePerChain, err := initStatePerChain(cfg, e)

Expand All @@ -196,7 +192,7 @@ func LinkTransfer(e deployment.Environment, cfg *LinkTransferConfig) (deployment

mcmsPerChain[uint64(chainID)] = mcmsState.ProposerMcm

timelockAddresses[chainID] = timelockAddress
timelockAddresses[chainSelector] = timelockAddress
batch := timelock.BatchChainOperation{
ChainIdentifier: chainID,
Batch: []mcms.Operation{},
Expand All @@ -221,22 +217,14 @@ func LinkTransfer(e deployment.Environment, cfg *LinkTransferConfig) (deployment

allBatches = append(allBatches, batch)
}
chainMetadata, err := proposalutils.BuildProposalMetadata(chainSelectors, mcmsPerChain)
if err != nil {
return deployment.ChangesetOutput{}, err
}

if cfg.McmsConfig != nil {
proposal, err := timelock.NewMCMSWithTimelockProposal(
"1",
cfg.McmsConfig.ValidUntil,
[]mcms.Signature{},
cfg.McmsConfig.OverrideRoot,
chainMetadata,
proposal, err := proposalutils.BuildProposalFromBatches(
timelockAddresses,
"Value transfer proposal",
mcmsPerChain,
allBatches,
timelock.Schedule,
cfg.McmsConfig.MinDelay.String(),
"LINK Value transfer proposal",
cfg.McmsConfig.MinDelay,
)
if err != nil {
return deployment.ChangesetOutput{}, err
Expand Down
23 changes: 3 additions & 20 deletions deployment/common/changeset/example/link_transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func TestLinkTransferMCMS(t *testing.T) {
},
},
McmsConfig: &example.MCMSConfig{
ValidUntil: 4131638958,
MinDelay: 0,
OverrideRoot: true,
},
Expand Down Expand Up @@ -237,8 +236,7 @@ func TestValidate(t *testing.T) {
chainSelector: {{To: mcmsState.Timelock.Address(), Value: big.NewInt(100)}}},
From: chain.DeployerKey.From,
McmsConfig: &example.MCMSConfig{
ValidUntil: uint32(time.Now().Add(1 * time.Hour).Unix()),
MinDelay: time.Hour,
MinDelay: time.Hour,
},
},
},
Expand All @@ -262,8 +260,7 @@ func TestValidate(t *testing.T) {
},
From: mcmsState.Timelock.Address(),
McmsConfig: &example.MCMSConfig{
ValidUntil: uint32(time.Now().Add(1 * time.Hour).Unix()),
MinDelay: time.Hour,
MinDelay: time.Hour,
},
},
errorMsg: "sender does not have enough funds for transfers for chain selector 909606746561742123, required: 1850, available: 0",
Expand Down Expand Up @@ -347,8 +344,7 @@ func TestValidate(t *testing.T) {
chainSelector: {{To: mcmsState.Timelock.Address(), Value: big.NewInt(100)}}},
From: chain.DeployerKey.From,
McmsConfig: &example.MCMSConfig{
ValidUntil: uint32(time.Now().Add(1 * time.Hour).Unix()),
MinDelay: time.Hour * 24 * 10,
MinDelay: time.Hour * 24 * 10,
},
},
errorMsg: "minDelay must be less than 7 days",
Expand All @@ -361,19 +357,6 @@ func TestValidate(t *testing.T) {
},
errorMsg: "'to' address for transfers must be set",
},
{
name: "invalid config: validUntil in the past",
cfg: example.LinkTransferConfig{
Transfers: map[uint64][]example.TransferConfig{
chainSelector: {{To: mcmsState.Timelock.Address(), Value: big.NewInt(100)}}},
From: chain.DeployerKey.From,
McmsConfig: &example.MCMSConfig{
ValidUntil: uint32(time.Now().Add(-1 * time.Hour).Unix()),
MinDelay: time.Hour,
},
},
errorMsg: "validUntil must be in the future",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 7c2ecf0

Please sign in to comment.