import { solanaInstructionDecoder, solanaPortalStream } from '@subsquid/pipes/solana'
import { MockPortal, MockResponse, mockPortal, readAll } from '@subsquid/pipes/testing'
import { beforeEach, describe, expect, it } from 'vitest'
import * as tokenProgram from './abi/tokenProgram/index.js'
const PORTAL_MOCK_RESPONSE: MockResponse[] = [
{
statusCode: 200,
data: [
{
header: { number: 1, hash: 'ooooooooooooooooooooooooooooooooooooooooooo1', timestamp: 2000 },
instructions: [
{
transactionIndex: 85,
instructionAddress: [2, 0, 0],
programId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
accounts: [
'98vhGWL5CtK61KSKCJjJn2PVfkjzaw9QF6sRLptBWZvZ',
'49gyyvxzf61PknHoTg2cFGYQCJRnUrC7Web8h8go7ceM',
'EDMGEpKKGKS7nxpu1gjLmuHHWAmvLNy3BZWDxNC3nhAt',
],
data: '3DXy58UDhJuu',
},
],
},
],
},
]
describe('Solana pipe', () => {
let portal: MockPortal
beforeEach(async () => {
await portal?.close()
portal = await mockPortal(PORTAL_MOCK_RESPONSE)
})
it('decodes instructions from mock blocks', async () => {
const stream = solanaPortalStream({
id: 'test',
portal: portal.url,
logger: false,
outputs: solanaInstructionDecoder({
range: { from: 0, to: 1 },
programId: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
instructions: { transfers: tokenProgram.instructions.transfer },
}).pipe((e) => e.transfers),
})
const res = await readAll(stream)
expect(res).toHaveLength(1)
})
})