Skip to content

Commit

Permalink
[web3js] fixing type guard on parsedaccountdata
Browse files Browse the repository at this point in the history
  • Loading branch information
ochaloup committed Jan 21, 2025
1 parent 5a3f6c1 commit 1df3e59
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
5 changes: 4 additions & 1 deletion packages/lib/web3js-common/src/stakeAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ function isAccountInfoParsedData(
if (data === null) {
return false
}
if (!data.data) {
return false
}
return (
data.data &&
!(data.data instanceof Buffer) &&
'parsed' in data.data &&
data.data.parsed !== undefined
)
}
Expand Down
43 changes: 29 additions & 14 deletions packages/marinade-ts-cli/__tests__/orderUnstakeAndClaim.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,35 @@ describe('Order unstake and claim using CLI', () => {
})

// Waiting for the ticket to be ready; max time is now hardcoded
// (timeout comes from fact having setup slots_per_epoch to 35)
const timeoutSeconds = 60
const tickets = await marinade.getDelayedUnstakeTickets(

let [ticketPubkey, ticketAccount] = await getTicket(
marinade,
walletKeypair.publicKey
)
expect(tickets.size).toBe(1)
const startTime = Date.now()
let ticket: [PublicKey, TicketAccount] = tickets.entries().next().value
while (
!ticket[1].ticketDueDate ||
isNaN(ticket[1].ticketDueDate.getTime())
!ticketAccount.ticketDueDate ||
isNaN(ticketAccount.ticketDueDate.getTime())
) {
console.log(
'Waiting for ticket',
ticket[0].toBase58(),
ticketPubkey.toBase58(),
'elapsed time:',
(Date.now() - startTime) / 1000,
'seconds'
)
await sleep(5000)
ticket = (
await marinade.getDelayedUnstakeTickets(walletKeypair.publicKey)
)
.entries()
.next().value
if (Date.now() - startTime > timeoutSeconds * 1000) {
throw new Error(
`Ticket ${ticket[0]} was not available for claiming in timeout of ${timeoutSeconds} seconds`
`Ticket ${ticketPubkey} was not available for claiming in timeout of ${timeoutSeconds} seconds`
)
}
await sleep(5000)
;[ticketPubkey, ticketAccount] = await getTicket(
marinade,
walletKeypair.publicKey
)
}

await (
Expand All @@ -106,7 +106,7 @@ describe('Order unstake and claim using CLI', () => {
'--url',
CONNECTION.rpcEndpoint,
'claim',
ticket[0].toBase58(),
ticketPubkey.toBase58(),
'--keypair',
walletPath,
'--confirmation-finality',
Expand All @@ -120,3 +120,18 @@ describe('Order unstake and claim using CLI', () => {
})
})
})

async function getTicket(
marinade: Marinade,
walletPubkey: PublicKey
): Promise<[PublicKey, TicketAccount]> {
const tickets = await marinade.getDelayedUnstakeTickets(walletPubkey)
expect(tickets.size).toBe(1)
const ticket = tickets.entries().next().value
if (!ticket) {
throw new Error(
'Ticket entries should be of size 1, no ticket available for claiming'
)
}
return ticket
}

0 comments on commit 1df3e59

Please sign in to comment.