fix: add test coverage and fixup getters
This commit is contained in:
committed by
Michael Vines
parent
fdece1a8a9
commit
825a43fecc
@ -107,12 +107,12 @@ export class StakeInstruction extends TransactionInstruction {
|
|||||||
*/
|
*/
|
||||||
get stakePublicKey(): PublicKey | null {
|
get stakePublicKey(): PublicKey | null {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Initialize:
|
case 'Initialize':
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Delegate:
|
case 'Delegate':
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Authorize:
|
case 'Authorize':
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Split:
|
case 'Split':
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Withdraw:
|
case 'Withdraw':
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Deactivate:
|
case 'Deactivate':
|
||||||
return this.keys[0].pubkey;
|
return this.keys[0].pubkey;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
@ -126,16 +126,16 @@ export class StakeInstruction extends TransactionInstruction {
|
|||||||
*/
|
*/
|
||||||
get authorizedPublicKey(): PublicKey | null {
|
get authorizedPublicKey(): PublicKey | null {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Delegate:
|
case 'Delegate':
|
||||||
return this.keys[5].pubkey;
|
return this.keys[5].pubkey;
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Authorize:
|
case 'Authorize':
|
||||||
return this.keys[2].pubkey;
|
return this.keys[2].pubkey;
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Split:
|
case 'Split':
|
||||||
return this.keys[2].pubkey;
|
return this.keys[2].pubkey;
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Withdraw:
|
case 'Withdraw':
|
||||||
return this.keys[4].pubkey;
|
return this.keys[4].pubkey;
|
||||||
case STAKE_INSTRUCTION_LAYOUTS.Deactivate:
|
case 'Deactivate':
|
||||||
return this.keys[0].pubkey;
|
return this.keys[2].pubkey;
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,8 @@ test('createAccountWithSeed', () => {
|
|||||||
SystemProgram.programId,
|
SystemProgram.programId,
|
||||||
);
|
);
|
||||||
expect(transaction.instructions[1].programId).toEqual(StakeProgram.programId);
|
expect(transaction.instructions[1].programId).toEqual(StakeProgram.programId);
|
||||||
|
const stakeInstruction = StakeInstruction.from(transaction.instructions[1]);
|
||||||
|
expect(stakeInstruction.stakePublicKey).toEqual(newAccountPubkey);
|
||||||
// TODO: Validate transaction contents more
|
// TODO: Validate transaction contents more
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -71,6 +73,12 @@ test('createAccount', () => {
|
|||||||
SystemProgram.programId,
|
SystemProgram.programId,
|
||||||
);
|
);
|
||||||
expect(transaction.instructions[1].programId).toEqual(StakeProgram.programId);
|
expect(transaction.instructions[1].programId).toEqual(StakeProgram.programId);
|
||||||
|
const stakeInstruction = StakeInstruction.from(transaction.instructions[1]);
|
||||||
|
expect(stakeInstruction.stakePublicKey).toEqual(newAccount.publicKey);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
StakeInstruction.from(transaction.instructions[0]);
|
||||||
|
}).toThrow();
|
||||||
// TODO: Validate transaction contents more
|
// TODO: Validate transaction contents more
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -88,6 +96,9 @@ test('delegate', () => {
|
|||||||
|
|
||||||
expect(transaction.keys).toHaveLength(6);
|
expect(transaction.keys).toHaveLength(6);
|
||||||
expect(transaction.programId).toEqual(StakeProgram.programId);
|
expect(transaction.programId).toEqual(StakeProgram.programId);
|
||||||
|
const stakeInstruction = StakeInstruction.from(transaction.instructions[0]);
|
||||||
|
expect(stakeInstruction.stakePublicKey).toEqual(stake.publicKey);
|
||||||
|
expect(stakeInstruction.authorizedPublicKey).toEqual(authorized.publicKey);
|
||||||
// TODO: Validate transaction contents more
|
// TODO: Validate transaction contents more
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -107,6 +118,9 @@ test('authorize', () => {
|
|||||||
|
|
||||||
expect(transaction.keys).toHaveLength(3);
|
expect(transaction.keys).toHaveLength(3);
|
||||||
expect(transaction.programId).toEqual(StakeProgram.programId);
|
expect(transaction.programId).toEqual(StakeProgram.programId);
|
||||||
|
const stakeInstruction = StakeInstruction.from(transaction.instructions[0]);
|
||||||
|
expect(stakeInstruction.stakePublicKey).toEqual(stake.publicKey);
|
||||||
|
expect(stakeInstruction.authorizedPublicKey).toEqual(authorized.publicKey);
|
||||||
// TODO: Validate transaction contents more
|
// TODO: Validate transaction contents more
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -128,6 +142,9 @@ test('split', () => {
|
|||||||
SystemProgram.programId,
|
SystemProgram.programId,
|
||||||
);
|
);
|
||||||
expect(transaction.instructions[1].programId).toEqual(StakeProgram.programId);
|
expect(transaction.instructions[1].programId).toEqual(StakeProgram.programId);
|
||||||
|
const stakeInstruction = StakeInstruction.from(transaction.instructions[1]);
|
||||||
|
expect(stakeInstruction.stakePublicKey).toEqual(stake.publicKey);
|
||||||
|
expect(stakeInstruction.authorizedPublicKey).toEqual(authorized.publicKey);
|
||||||
// TODO: Validate transaction contents more
|
// TODO: Validate transaction contents more
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -146,6 +163,9 @@ test('withdraw', () => {
|
|||||||
|
|
||||||
expect(transaction.keys).toHaveLength(5);
|
expect(transaction.keys).toHaveLength(5);
|
||||||
expect(transaction.programId).toEqual(StakeProgram.programId);
|
expect(transaction.programId).toEqual(StakeProgram.programId);
|
||||||
|
const stakeInstruction = StakeInstruction.from(transaction.instructions[0]);
|
||||||
|
expect(stakeInstruction.stakePublicKey).toEqual(stake.publicKey);
|
||||||
|
expect(stakeInstruction.authorizedPublicKey).toEqual(withdrawer.publicKey);
|
||||||
// TODO: Validate transaction contents more
|
// TODO: Validate transaction contents more
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -158,6 +178,9 @@ test('deactivate', () => {
|
|||||||
|
|
||||||
expect(transaction.keys).toHaveLength(3);
|
expect(transaction.keys).toHaveLength(3);
|
||||||
expect(transaction.programId).toEqual(StakeProgram.programId);
|
expect(transaction.programId).toEqual(StakeProgram.programId);
|
||||||
|
const stakeInstruction = StakeInstruction.from(transaction.instructions[0]);
|
||||||
|
expect(stakeInstruction.stakePublicKey).toEqual(stake.publicKey);
|
||||||
|
expect(stakeInstruction.authorizedPublicKey).toEqual(authorized.publicKey);
|
||||||
// TODO: Validate transaction contents more
|
// TODO: Validate transaction contents more
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user