diff --git a/web3.js/src/publickey.ts b/web3.js/src/publickey.ts index cc8b2f8efa98ca..de067020dca30d 100644 --- a/web3.js/src/publickey.ts +++ b/web3.js/src/publickey.ts @@ -143,10 +143,10 @@ export class PublicKey extends Struct { * Derive a program address from seeds and a program ID. */ /* eslint-disable require-await */ - static async createProgramAddress( + static createProgramAddress( seeds: Array, programId: PublicKey, - ): Promise { + ): PublicKey { let buffer = Buffer.alloc(0); seeds.forEach(function (seed) { if (seed.length > MAX_SEED_LENGTH) { @@ -174,16 +174,16 @@ export class PublicKey extends Struct { * iterates a nonce until it finds one that when combined with the seeds * results in a valid program address. */ - static async findProgramAddress( + static findProgramAddress( seeds: Array, programId: PublicKey, - ): Promise<[PublicKey, number]> { + ): [PublicKey, number] { let nonce = 255; let address; while (nonce != 0) { try { const seedsWithNonce = seeds.concat(Buffer.from([nonce])); - address = await this.createProgramAddress(seedsWithNonce, programId); + address = this.createProgramAddress(seedsWithNonce, programId); } catch (err) { if (err instanceof TypeError) { throw err; diff --git a/web3.js/test/publickey.test.ts b/web3.js/test/publickey.test.ts index d6a725c4f53e70..1dfedd59ce9a2d 100644 --- a/web3.js/test/publickey.test.ts +++ b/web3.js/test/publickey.test.ts @@ -121,7 +121,7 @@ describe('PublicKey', function () { ).to.be.true; }); - it('createProgramAddress', async () => { + it('createProgramAddress', () => { const programId = new PublicKey( 'BPFLoader1111111111111111111111111111111111', ); @@ -129,7 +129,7 @@ describe('PublicKey', function () { 'SeedPubey1111111111111111111111111111111111', ); - let programAddress = await PublicKey.createProgramAddress( + let programAddress = PublicKey.createProgramAddress( [Buffer.from('', 'utf8'), Buffer.from([1])], programId, ); @@ -139,7 +139,7 @@ describe('PublicKey', function () { ), ).to.be.true; - programAddress = await PublicKey.createProgramAddress( + programAddress = PublicKey.createProgramAddress( [Buffer.from('☉', 'utf8')], programId, ); @@ -149,7 +149,7 @@ describe('PublicKey', function () { ), ).to.be.true; - programAddress = await PublicKey.createProgramAddress( + programAddress = PublicKey.createProgramAddress( [Buffer.from('Talking', 'utf8'), Buffer.from('Squirrels', 'utf8')], programId, ); @@ -159,7 +159,7 @@ describe('PublicKey', function () { ), ).to.be.true; - programAddress = await PublicKey.createProgramAddress( + programAddress = PublicKey.createProgramAddress( [publicKey.toBuffer()], programId, ); @@ -169,18 +169,18 @@ describe('PublicKey', function () { ), ).to.be.true; - const programAddress2 = await PublicKey.createProgramAddress( + const programAddress2 = PublicKey.createProgramAddress( [Buffer.from('Talking', 'utf8')], programId, ); expect(programAddress.equals(programAddress2)).to.eq(false); - await expect( + expect(() => PublicKey.createProgramAddress( [Buffer.alloc(MAX_SEED_LENGTH + 1)], programId, ), - ).to.be.rejectedWith('Max seed length exceeded'); + ).to.be.throw('Max seed length exceeded'); // https://github.com/solana-labs/solana/issues/11950 { @@ -193,7 +193,7 @@ describe('PublicKey', function () { let programId = new PublicKey( '4ckmDgGdxQoPDLUkDT3vHgSAkzA3QRdNq5ywwY4sUSJn', ); - programAddress = await PublicKey.createProgramAddress(seeds, programId); + programAddress = PublicKey.createProgramAddress(seeds, programId); expect( programAddress.equals( new PublicKey('12rqwuEgBYiGhBrDJStCiqEtzQpTTiZbh7teNVLuYcFA'), @@ -206,7 +206,7 @@ describe('PublicKey', function () { const programId = new PublicKey( 'BPFLoader1111111111111111111111111111111111', ); - let [programAddress, nonce] = await PublicKey.findProgramAddress( + let [programAddress, nonce] = PublicKey.findProgramAddress( [Buffer.from('', 'utf8')], programId, );