Skip to content

Commit 603c3db

Browse files
committed
fix: improve code and add new tests on transfer reservation ownership
1 parent 228eca8 commit 603c3db

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/entities/SecurityTokenReservation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class SecurityTokenReservation extends Entity<Params> {
116116
};
117117

118118
/**
119-
* Transfers the ownership of the ticker
119+
* Transfer the ownership of the ticker
120120
*/
121121
public transferOwnership = async (args: { newOwner: string }) => {
122122
const { context, symbol } = this;

src/procedures/TransferReservationOwnership.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ export class TransferReservationOwnership extends Procedure<
3131
if (status) {
3232
throw new PolymathError({
3333
code: ErrorCode.ProcedureValidationError,
34-
message: `You can not transfer a Security Token already launched`,
34+
message: `The ${symbol} Security Token has already been launched, ownership cannot be transferred`,
3535
});
3636
}
3737

38-
if (account === owner) {
38+
if (account !== owner) {
39+
throw new PolymathError({
40+
code: ErrorCode.ProcedureValidationError,
41+
message: `Only the reservation owner can transfer ownership to another wallet`,
42+
});
43+
}
44+
45+
if (newOwner === owner) {
3946
throw new PolymathError({
4047
code: ErrorCode.ProcedureValidationError,
4148
message: `New owner must be different from the current one to transfer ownership`,

src/procedures/__tests__/TransferReservationOwnership.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ describe('TransferReservationOwnership', () => {
7676

7777
describe('Types', () => {
7878
test('should extend procedure and have TransferReservationOwnership type', async () => {
79-
target = new TransferReservationOwnership(params, contextMock.getMockInstance());
8079
expect(target instanceof Procedure).toBe(true);
8180
expect(target.type).toBe(ProcedureType.TransferReservationOwnership);
8281
});
@@ -92,14 +91,30 @@ describe('TransferReservationOwnership', () => {
9291
await expect(target.prepareTransactions()).rejects.toThrowError(
9392
new PolymathError({
9493
code: ErrorCode.ProcedureValidationError,
95-
message: `You can not transfer a Security Token already launched`,
94+
message: `The ${
95+
params.symbol
96+
} Security Token has already been launched, ownership cannot be transferred`,
97+
})
98+
);
99+
});
100+
101+
test('should throw error if current wallet is not the reservation ticker owner', async () => {
102+
await expect(target.prepareTransactions()).rejects.toThrowError(
103+
new PolymathError({
104+
code: ErrorCode.ProcedureValidationError,
105+
message: `Only the reservation owner can transfer ownership to another wallet`,
96106
})
97107
);
98108
});
99109

100110
test('should throw error if new owner is equals to the current one', async () => {
101111
contextMock.set('currentWallet', new Wallet({ address: () => Promise.resolve('0x01') }));
102112

113+
target = new TransferReservationOwnership(
114+
{ ...params, newOwner: '0x01' },
115+
contextMock.getMockInstance()
116+
);
117+
103118
await expect(target.prepareTransactions()).rejects.toThrowError(
104119
new PolymathError({
105120
code: ErrorCode.ProcedureValidationError,
@@ -109,6 +124,8 @@ describe('TransferReservationOwnership', () => {
109124
});
110125

111126
test('should add a transaction to the queue to change the transfer reservation ownership', async () => {
127+
contextMock.set('currentWallet', new Wallet({ address: () => Promise.resolve('0x01') }));
128+
112129
const addTransactionSpy = spy(target, 'addTransaction');
113130
securityTokenRegistryMock.mock(
114131
'transferTickerOwnership',

0 commit comments

Comments
 (0)