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

Remove redundant Initialize() on TestUtils #3781

Closed
OnedgeLee opened this issue May 9, 2024 · 4 comments · Fixed by #3972
Closed

Remove redundant Initialize() on TestUtils #3781

OnedgeLee opened this issue May 9, 2024 · 4 comments · Fixed by #3972
Assignees
Labels
good first issue Good for newcomers hacktoberfest Newcomer-welcoming issues for Hacktoberfest

Comments

@OnedgeLee
Copy link
Contributor

OnedgeLee commented May 9, 2024

Context

txs.AddRange(
validatorSet.Validators.Select(
validator => Transaction.Create(
nonce++,
GenesisProposer,
null,
actions: new IAction[]
{
new Initialize(
validatorSet: validatorSet,
states: ImmutableDictionary.Create<Address, IValue>()),
}.Select(x => x.PlainValue),
timestamp: DateTimeOffset.MinValue)));
txs = txs.OrderBy(tx => tx.Id).ToList();

Action Initialize() updates validator set of IWorld with given parameter validatorSet.
So above code, that iterates validatorSet, is redundant.
(Initialize() only needs to be called once.)

@OnedgeLee OnedgeLee added the good first issue Good for newcomers label May 9, 2024
@Atralupus Atralupus added the hacktoberfest Newcomer-welcoming issues for Hacktoberfest label Oct 10, 2024
@hpatel292-seneca
Copy link
Contributor

Hi @Atralupus, could you please assign this to me.

@Atralupus
Copy link
Member

Hi @Atralupus, could you please assign this to me.

Sure! I just assigned you to this issue.

And we're also running a hackathon right now named Modathon. We'd love for you to check it out 🙏🏻

https://nine-chronicles.dev/event/2024modathon

@hpatel292-seneca
Copy link
Contributor

Hi @Atralupus, in the issue you mentioned about that iterates validatorSet, is redundant. , so you are saying to remove the iterator like this

var txs = transactions?.ToList() ?? new List<Transaction>();
long nonce = 0;
validatorSet = validatorSet ?? ValidatorSet;

// single transaction for the Initialize action, instead of iterating over validators.
txs.Add(
    Transaction.Create(
        nonce++,
        GenesisProposer,
        null,
        actions: new IAction[]
        {
            new Initialize(
                validatorSet: validatorSet,
                states: ImmutableDictionary.Create<Address, IValue>()),
        }.Select(x => x.PlainValue),
        timestamp: DateTimeOffset.MinValue));

@Atralupus
Copy link
Member

Hi @Atralupus, in the issue you mentioned about that iterates validatorSet, is redundant. , so you are saying to remove the iterator like this

var txs = transactions?.ToList() ?? new List<Transaction>();
long nonce = 0;
validatorSet = validatorSet ?? ValidatorSet;

// single transaction for the Initialize action, instead of iterating over validators.
txs.Add(
    Transaction.Create(
        nonce++,
        GenesisProposer,
        null,
        actions: new IAction[]
        {
            new Initialize(
                validatorSet: validatorSet,
                states: ImmutableDictionary.Create<Address, IValue>()),
        }.Select(x => x.PlainValue),
        timestamp: DateTimeOffset.MinValue));

Looks great! Please submit a PR, and we’ll review it with the team. Thanks, and happy contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest Newcomer-welcoming issues for Hacktoberfest
Projects
Development

Successfully merging a pull request may close this issue.

3 participants