Skip to content

Commit

Permalink
Code review follow up
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Dec 11, 2024
1 parent 7585eb9 commit 6345f37
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/accountManagement/accountTransactionsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class AccountTransactionsFactory {
createTransactionForSettingGuardian(sender: Address, options: SetGuardianInput): Transaction {
const dataParts = [
"SetGuardian",
Address.fromBech32(options.guardianAddress.toBech32()).toHex(),
Address.fromBech32(options.guardianAddress.bech32()).toHex(),
Buffer.from(options.serviceID).toString("hex"),
];

Expand Down
4 changes: 2 additions & 2 deletions src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export class Compatibility {
* For internal use only.
*/
static guardAddressIsSetAndNonZero(address: IAddress | undefined, context: string, resolution: string) {
if (!address || address.toBech32() == "") {
if (!address || address.bech32() == "") {
console.warn(
`${context}: address should be set; ${resolution}. In the future, this will throw an exception instead of emitting a WARN.`,
);
} else if (address.toBech32() == Address.Zero().toBech32()) {
} else if (address.bech32() == Address.Zero().toBech32()) {
console.warn(
`${context}: address should not be the 'zero' address (also known as the 'contracts deployment address'); ${resolution}. In the future, this will throw an exception instead of emitting a WARN.`,
);
Expand Down
97 changes: 26 additions & 71 deletions src/delegation/delegationTransactionsFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("test delegation transactions factory", function () {

it("should create 'Transaction' for adding nodes", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);
const publicKey = new ValidatorPublicKey(
Buffer.from(
"e7beaa95b3877f47348df4dd1cb578a4f7cabf7a20bfeefe5cdd263878ff132b765e04fef6f40c93512b666c47ed7719b8902f6c922c04247989b7137e837cc81a62e54712471c97a2ddab75aa9c2f58f813ed4c0fa722bde0ab718bff382208",
Expand All @@ -61,10 +61,7 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(
transaction.data,
Expand All @@ -77,7 +74,7 @@ describe("test delegation transactions factory", function () {

it("should create 'Transaction' for removing nodes", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);

const publicKey = new ValidatorPublicKey(
Buffer.from(
Expand All @@ -94,10 +91,7 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(
transaction.data,
Expand All @@ -110,7 +104,7 @@ describe("test delegation transactions factory", function () {

it("should create 'Transaction' for staking nodes", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);
const publicKey = new ValidatorPublicKey(
Buffer.from(
"be2e593ff10899a2ee8e1d5c8094e36c9f48e04b87e129991ff09475808743e07bb41bf6e7bc1463fa554c4b46594b98",
Expand All @@ -126,10 +120,7 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(
transaction.data,
Expand All @@ -142,7 +133,7 @@ describe("test delegation transactions factory", function () {

it("should create 'Transaction' for unbonding nodes", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);
const publicKey = new ValidatorPublicKey(
Buffer.from(
"be2e593ff10899a2ee8e1d5c8094e36c9f48e04b87e129991ff09475808743e07bb41bf6e7bc1463fa554c4b46594b98",
Expand All @@ -158,10 +149,7 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(
transaction.data,
Expand All @@ -175,7 +163,7 @@ describe("test delegation transactions factory", function () {

it("should create 'Transaction' for unstaking nodes", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);
const publicKey = new ValidatorPublicKey(
Buffer.from(
"be2e593ff10899a2ee8e1d5c8094e36c9f48e04b87e129991ff09475808743e07bb41bf6e7bc1463fa554c4b46594b98",
Expand All @@ -191,10 +179,7 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(
transaction.data,
Expand All @@ -208,9 +193,7 @@ describe("test delegation transactions factory", function () {

it("should create 'Transaction' for unjailing nodes", async function () {
const sender = Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.newFromBech32(
"erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc",
);
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);
const publicKey = new ValidatorPublicKey(
Buffer.from(
"be2e593ff10899a2ee8e1d5c8094e36c9f48e04b87e129991ff09475808743e07bb41bf6e7bc1463fa554c4b46594b98",
Expand All @@ -226,10 +209,7 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(
transaction.data,
Expand All @@ -242,9 +222,7 @@ describe("test delegation transactions factory", function () {

it("should create 'Transaction' for changing service fee", async function () {
const sender = Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.newFromBech32(
"erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc",
);
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);
const serviceFee = 10n;

const transaction = delegationFactory.createTransactionForChangingServiceFee(sender, {
Expand All @@ -256,18 +234,15 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(transaction.data, Buffer.from("changeServiceFee@0a"));
assert.equal(transaction.value, 0n);
});

it("should create 'Transaction' for changing delegation cap", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);
const delegationCap = 5000000000000000000000n;

const transaction = delegationFactory.createTransactionForModifyingDelegationCap(sender, {
Expand All @@ -279,18 +254,15 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(transaction.data, Buffer.from("modifyTotalDelegationCap@010f0cf064dd59200000"));
assert.equal(transaction.value, 0n);
});

it("should create 'Transaction' for setting automatic activation", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);

const transaction = delegationFactory.createTransactionForSettingAutomaticActivation(sender, {
delegationContract: delegationContract,
Expand All @@ -300,18 +272,15 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(transaction.data, Buffer.from("setAutomaticActivation@74727565"));
assert.equal(transaction.value, 0n);
});

it("should create 'Transaction' for unsetting automatic activation", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);

const transaction = delegationFactory.createTransactionForUnsettingAutomaticActivation(sender, {
delegationContract: delegationContract,
Expand All @@ -321,18 +290,15 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(transaction.data, Buffer.from("setAutomaticActivation@66616c7365"));
assert.equal(transaction.value, 0n);
});

it("should create 'Transaction' for setting cap check on redelegate rewards", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);

const transaction = delegationFactory.createTransactionForSettingCapCheckOnRedelegateRewards(sender, {
delegationContract: delegationContract,
Expand All @@ -342,18 +308,15 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(transaction.data, Buffer.from("setCheckCapOnReDelegateRewards@74727565"));
assert.equal(transaction.value, 0n);
});

it("should create 'Transaction' for unsetting cap check on redelegate rewards", async function () {
const sender = Address.fromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.fromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc");
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);

const transaction = delegationFactory.createTransactionForUnsettingCapCheckOnRedelegateRewards(sender, {
delegationContract: delegationContract,
Expand All @@ -363,20 +326,15 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(transaction.data, Buffer.from("setCheckCapOnReDelegateRewards@66616c7365"));
assert.equal(transaction.value, 0n);
});

it("should create 'Transaction' for setting metadata", async function () {
const sender = Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2");
const delegationContract = Address.newFromBech32(
"erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc",
);
const delegationContract = Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX);

const transaction = delegationFactory.createTransactionForSettingMetadata(sender, {
delegationContract: delegationContract,
Expand All @@ -389,10 +347,7 @@ describe("test delegation transactions factory", function () {
transaction.sender,
Address.newFromBech32("erd18s6a06ktr2v6fgxv4ffhauxvptssnaqlds45qgsrucemlwc8rawq553rt2"),
);
assert.deepEqual(
transaction.receiver,
Address.newFromBech32("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqtllllls002zgc"),
);
assert.deepEqual(transaction.receiver, Address.newFromHex(DELEGATION_MANAGER_SC_ADDRESS_HEX));
assert.isDefined(transaction.data);
assert.deepEqual(transaction.data, Buffer.from("setMetaData@6e616d65@77656273697465@6964656e746966696572"));
assert.equal(transaction.value, 0n);
Expand Down
Loading

0 comments on commit 6345f37

Please sign in to comment.