fix: createAccountWithSeed account handling (#15482)

This commit is contained in:
Tyera Eulberg
2021-02-25 23:47:22 -07:00
committed by GitHub
parent 817b163703
commit d866f742e2
2 changed files with 44 additions and 4 deletions

View File

@ -745,12 +745,16 @@ export class SystemProgram {
space: params.space,
programId: params.programId.toBuffer(),
});
let keys = [
{pubkey: params.fromPubkey, isSigner: true, isWritable: true},
{pubkey: params.newAccountPubkey, isSigner: false, isWritable: true},
];
if (params.basePubkey != params.fromPubkey) {
keys.push({pubkey: params.basePubkey, isSigner: true, isWritable: false});
}
return new TransactionInstruction({
keys: [
{pubkey: params.fromPubkey, isSigner: true, isWritable: true},
{pubkey: params.newAccountPubkey, isSigner: false, isWritable: true},
],
keys,
programId: this.programId,
data,
});

View File

@ -475,6 +475,42 @@ describe('SystemProgram', () => {
);
expect(createAccountWithSeedBalance).to.eq(minimumAmount);
// Test CreateAccountWithSeed where fromPubkey != basePubkey
const uniqueFromAccount = new Account();
const newBaseAccount = new Account();
const createAccountWithSeedAddress2 = await PublicKey.createWithSeed(
newBaseAccount.publicKey,
seed,
programId,
);
await helpers.airdrop({
connection,
address: uniqueFromAccount.publicKey,
amount: 2 * LAMPORTS_PER_SOL,
});
const createAccountWithSeedParams2 = {
fromPubkey: uniqueFromAccount.publicKey,
newAccountPubkey: createAccountWithSeedAddress2,
basePubkey: newBaseAccount.publicKey,
seed,
lamports: minimumAmount,
space,
programId,
};
const createAccountWithSeedTransaction2 = new Transaction().add(
SystemProgram.createAccountWithSeed(createAccountWithSeedParams2),
);
await sendAndConfirmTransaction(
connection,
createAccountWithSeedTransaction2,
[uniqueFromAccount, newBaseAccount],
{preflightCommitment: 'confirmed'},
);
const createAccountWithSeedBalance2 = await connection.getBalance(
createAccountWithSeedAddress2,
);
expect(createAccountWithSeedBalance2).to.eq(minimumAmount);
// Transfer to a derived address to prep for TransferWithSeed
const programId2 = new Account().publicKey;
const transferWithSeedAddress = await PublicKey.createWithSeed(