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

Delegation transaction intents factory #328

Merged
merged 8 commits into from
Sep 11, 2023

Conversation

popenta
Copy link
Contributor

@popenta popenta commented Sep 5, 2023

Implemented the delegation transaction intents factory based on the sdk-specs.

@popenta popenta self-assigned this Sep 5, 2023
@popenta popenta marked this pull request as draft September 5, 2023 11:57
Base automatically changed from sc-intents-factories to feat/factories September 8, 2023 09:39
@popenta popenta marked this pull request as ready for review September 8, 2023 11:32
}).build();
}

private computeExecutionGasLimitForNodesManagement(numNodes: number): BigNumber.Value {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please move this at the end of the file or maybe decide on a pattern, first public then private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the end of file.

@@ -140,23 +141,12 @@ describe("test smart contract intents factory", function () {
assert.equal(deployIntent.sender, "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th");
assert.equal(deployIntent.receiver, "erd1qqqqqqqqqqqqqpgqhy6nl6zq07rnzry8uyh6rtyq0uzgtk3e69fqgtz9l4");
assert.isDefined(deployIntent.data);
assert(checkIfByteArrayStartsWith(deployIntent.data!, "upgradeContract@"));
assert.isTrue(Buffer.from(deployIntent.data!).toString().startsWith("upgradeContract@"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

import { SignableMessage } from "../signableMessage";

describe("test delegation intents factory", function () {
const delegationFactory = new DelegationTransactionIntentsFactory({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created the config file.

additionalGasLimitForDelegationOperations: 10000000
});

it("should build intent for new delegation contract", async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I see, we can change "should build" to "should create" (optional, "philosophical").

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to should create

it("should build intent for new delegation contract", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delagationCap = new BigNumber("5000000000000000000000");
const serviceFee = new BigNumber(10);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also use raw strings and numbers, and the factory methods should be able to handle them appropriately. Perhaps do this in some tests? E.g. directly pass "5000000000000000000000".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this test, works as expected.

sender: sender,
delegationContract: delegationContract,
publicKeys: [publicKey],
signedMessages: [signedMessage.getSignature()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a mock message, we can do:

const mockMessage = {
    getSignature: () => Buffer.from("...", hex)
}

Should work. Then, we'll remove new SignableMessage() and applySignature() from the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 70 to 75
let dataParts = ["addNodes"];
for (let i = 0; i < numNodes; i++) {
dataParts = dataParts.concat(options.publicKeys[i].hex());
dataParts = dataParts.concat(byteArrayToHex(options.signedMessages[i]));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, we can have const dataParts, and use .push().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have const dataParts and are using .push() now

let dataParts = ["removeNodes"];

for (const key of options.publicKeys) {
dataParts = dataParts.concat(key.hex());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why concat works fine in this case. Does the compiler complain if you add the typing markers dataParts: string[] = ...? Perhaps use append, as mentioned in the comment above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now using push(). It does not complain if I add typing markers but it already shows the correct type.

}

const numNodes = options.publicKeys.length;
const executionGasLimit = new BigNumber(numNodes).multipliedBy(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be split, a temporary variable can be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

let dataParts = ["unJailNodes"];

for (const key of options.publicKeys) {
dataParts = dataParts.concat(key.hex());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append vs. concat.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now using push()

createTransactionIntentForNewDelegationContract(options: {
sender: IAddress,
totalDelegationCap: BigNumber.Value,
serviceFee: BigNumber.Value,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we receive as the BigNumber.Value interface.

@popenta popenta merged commit 3afd6cc into feat/factories Sep 11, 2023
1 check passed
@popenta popenta deleted the delegation-intents-factories branch September 11, 2023 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants