-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: port makeAuction action (#131)
* feat: makeAuction action has been added * test: run test against localhost and move vault creation inside makeAuction action * test: refactored utility actions * refactor: move utility actions to separate folder with test migration to localhost * refactor: move test localhost connection and wallet generation to separate function * refactor: test/shared/index import ordering * test: fix addTokensToVault test Co-authored-by: Tymur Biedukhin <123@example.com>
- Loading branch information
1 parent
d5c8983
commit 715d1d4
Showing
14 changed files
with
185 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,4 +116,4 @@ | |
"@commitlint/config-conventional" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
src/actions/createVault.ts → src/actions/utility/createVault.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './closeVault'; | ||
export * from './createExternalPriceAccount'; | ||
export * from './createVault'; | ||
export * from './initAuction'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Transaction } from '@metaplex-foundation/mpl-core'; | ||
import { | ||
Auction, | ||
AuctionExtended, | ||
CreateAuction, | ||
CreateAuctionArgs, | ||
} from '@metaplex-foundation/mpl-auction'; | ||
import { PublicKey, TransactionSignature } from '@solana/web3.js'; | ||
|
||
import { Wallet } from '../../wallet'; | ||
import { Connection } from '../../Connection'; | ||
import { sendTransaction } from '../transactions'; | ||
|
||
interface MakeAuctionParams { | ||
connection: Connection; | ||
wallet: Wallet; | ||
vault: PublicKey; | ||
auctionSettings: Omit<CreateAuctionArgs, 'resource' | 'authority'>; | ||
} | ||
|
||
interface MakeAuctionResponse { | ||
txId: TransactionSignature; | ||
auction: PublicKey; | ||
} | ||
|
||
export const initAuction = async ({ | ||
connection, | ||
wallet, | ||
vault, | ||
auctionSettings, | ||
}: MakeAuctionParams): Promise<MakeAuctionResponse> => { | ||
const txOptions = { feePayer: wallet.publicKey }; | ||
|
||
const [auctionKey, auctionExtended] = await Promise.all([ | ||
Auction.getPDA(vault), | ||
AuctionExtended.getPDA(vault), | ||
]); | ||
|
||
const fullSettings = new CreateAuctionArgs({ | ||
...auctionSettings, | ||
authority: wallet.publicKey.toBase58(), | ||
resource: vault.toBase58(), | ||
}); | ||
|
||
const auctionTx: Transaction = new CreateAuction(txOptions, { | ||
args: fullSettings, | ||
auction: auctionKey, | ||
creator: wallet.publicKey, | ||
auctionExtended, | ||
}); | ||
|
||
const txId = await sendTransaction({ | ||
connection, | ||
signers: [], | ||
txs: [auctionTx], | ||
wallet, | ||
}); | ||
|
||
return { txId, auction: auctionKey }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
...ctions/createExternalPriceAccount.test.ts → ...y/createExternalPriceAccountLocal.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 8 additions & 10 deletions
18
test/actions/createVault.test.ts → test/actions/utility/createVault.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import { Connection, NodeWallet } from '../../src'; | ||
import { createVault, createExternalPriceAccount } from '../../src/actions'; | ||
import { FEE_PAYER, pause } from '../utils'; | ||
import { Vault, VaultState } from '@metaplex-foundation/mpl-token-vault'; | ||
|
||
describe('creating a Vault', () => { | ||
const connection = new Connection('devnet'); | ||
const wallet = new NodeWallet(FEE_PAYER); | ||
import { pause } from '../../utils'; | ||
import { createVault, createExternalPriceAccount } from '../../../src/actions/utility'; | ||
import { generateConnectionAndWallet } from '../shared'; | ||
|
||
describe('creating a Vault', () => { | ||
describe('success', () => { | ||
test('generates vault', async () => { | ||
const externalPriceAccountData = await createExternalPriceAccount({ connection, wallet }); | ||
const { connection, wallet } = await generateConnectionAndWallet(); | ||
|
||
await pause(20000); | ||
const externalPriceAccountData = await createExternalPriceAccount({ connection, wallet }); | ||
|
||
const vaultResponse = await createVault({ | ||
connection, | ||
wallet, | ||
...externalPriceAccountData, | ||
}); | ||
|
||
await pause(20000); | ||
await pause(1000); | ||
const vault = await Vault.load(connection, vaultResponse.vault); | ||
expect(vault).toHaveProperty('data'); | ||
expect(vault.data.state).toEqual(VaultState.Inactive); | ||
}, 50000); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.