Skip to content

Commit

Permalink
v14.8.0: latestBlockNumber in solana is slot
Browse files Browse the repository at this point in the history
  • Loading branch information
10xSebastian committed May 16, 2023
1 parent b07ad35 commit 1d717c8
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 3 deletions.
7 changes: 7 additions & 0 deletions dist/esm/index.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -64502,6 +64502,13 @@ let request$1 = ({ blockchain, provider, method, params }) => {
result: getCurrentBlock()
}

case 'getSlot':
return {
jsonrpc: '2.0',
id: '1',
result: getCurrentBlock()
}

case 'getMinimumBalanceForRentExemption':
return responseData({ blockchain, provider, method, params })
.then((data)=>{
Expand Down
7 changes: 7 additions & 0 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,13 @@ let request$1 = ({ blockchain, provider, method, params }) => {
result: getCurrentBlock()
}

case 'getSlot':
return {
jsonrpc: '2.0',
id: '1',
result: getCurrentBlock()
}

case 'getMinimumBalanceForRentExemption':
return responseData({ blockchain, provider, method, params })
.then((data)=>{
Expand Down
7 changes: 7 additions & 0 deletions dist/esm/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@ let request$1 = ({ blockchain, provider, method, params }) => {
result: getCurrentBlock()
}

case 'getSlot':
return {
jsonrpc: '2.0',
id: '1',
result: getCurrentBlock()
}

case 'getMinimumBalanceForRentExemption':
return responseData({ blockchain, provider, method, params })
.then((data)=>{
Expand Down
7 changes: 7 additions & 0 deletions dist/umd/index.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -64510,6 +64510,13 @@
result: getCurrentBlock()
}

case 'getSlot':
return {
jsonrpc: '2.0',
id: '1',
result: getCurrentBlock()
}

case 'getMinimumBalanceForRentExemption':
return responseData({ blockchain, provider, method, params })
.then((data)=>{
Expand Down
7 changes: 7 additions & 0 deletions dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,13 @@
result: getCurrentBlock()
}

case 'getSlot':
return {
jsonrpc: '2.0',
id: '1',
result: getCurrentBlock()
}

case 'getMinimumBalanceForRentExemption':
return responseData({ blockchain, provider, method, params })
.then((data)=>{
Expand Down
7 changes: 7 additions & 0 deletions dist/umd/index.solana.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,13 @@
result: getCurrentBlock()
}

case 'getSlot':
return {
jsonrpc: '2.0',
id: '1',
result: getCurrentBlock()
}

case 'getMinimumBalanceForRentExemption':
return responseData({ blockchain, provider, method, params })
.then((data)=>{
Expand Down
2 changes: 1 addition & 1 deletion package.evm.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-mock-evm",
"moduleName": "Web3Mock",
"version": "14.7.2",
"version": "14.8.0",
"description": "JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.",
"main": "./dist/umd/index.evm.js",
"module": "./dist/esm/index.evm.js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-mock",
"moduleName": "Web3Mock",
"version": "14.7.2",
"version": "14.8.0",
"description": "JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.",
"main": "./dist/umd/index.js",
"module": "./dist/esm/index.js",
Expand Down
2 changes: 1 addition & 1 deletion package.solana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@depay/web3-mock-solana",
"moduleName": "Web3Mock",
"version": "14.7.2",
"version": "14.8.0",
"description": "JavaScript library to mock web3 responses either by emulating web3 wallets or web3 RPC requests.",
"main": "./dist/umd/index.solana.js",
"module": "./dist/esm/index.solana.js",
Expand Down
8 changes: 8 additions & 0 deletions src/platforms/solana/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ let request = ({ blockchain, provider, method, params }) => {
}
break

case 'getSlot':
return {
jsonrpc: '2.0',
id: '1',
result: getCurrentBlock()
}
break

case 'getMinimumBalanceForRentExemption':
return responseData({ blockchain, provider, method, params })
.then((data)=>{
Expand Down
14 changes: 14 additions & 0 deletions tests/units/solana/blockHeight.solana.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ describe('mocks solana block height', ()=> {

expect(blockHeight).toEqual(1)
})

it('mocks getSlot', async ()=>{

let connection = new Connection('https://api.mainnet-beta.solana.com')

let balanceMock = mock({
provider: connection,
blockchain
})

let blockHeight = await connection.getSlot()

expect(blockHeight).toEqual(1)
})
})
})
});
14 changes: 14 additions & 0 deletions tests/units/solana/blockHeight.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ describe('mocks solana block height', ()=> {

expect(blockHeight).toEqual(1)
})

it('mocks getSlot', async ()=>{

let connection = new Connection('https://api.mainnet-beta.solana.com')

let balanceMock = mock({
provider: connection,
blockchain
})

let blockHeight = await connection.getSlot()

expect(blockHeight).toEqual(1)
})
})
})
});
54 changes: 54 additions & 0 deletions tests/units/solana/request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,60 @@ describe('mocks solana requests', ()=> {
'F7e4iBrxoSmHhEzhuBcXXs1KAknYvEoZWieiocPvrCD9'
])
})

it('mocks a gets getProgramAccounts with data', async ()=>{
let connection = new Connection('https://api.mainnet-beta.solana.com')

let wallet = '2wmVCSfPxGPjrnMMn7rchp4uaeoTqN39mXFC2zhPdri9'
let mint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'

let filters = [
{ dataSize: 165 },
{ memcmp: { offset: 32, bytes: wallet }},
{ memcmp: { offset: 0, bytes: mint }}
]

let requestMock = mock({
provider: connection,
blockchain,
request: {
method: 'getProgramAccounts',
to: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA',
params: { filters },
return: [
{
account: { data: new Buffer([]), executable: false, lamports: 2039280, owner: mint, rentEpoch: 327 },
pubkey: '3JdKXacGdntfNKXzSGC2EwUDKFPrXdsqowbuc9hEiNBb'
}, {
account: { data: new Buffer([]), executable: false, lamports: 2039280, owner: mint, rentEpoch: 327 },
pubkey: 'FjtHL8ki3GXMhCqY2Lum9CCAv5tSQMkhJEnXbEkajTrZ'
}, {
account: { data: new Buffer([]), executable: false, lamports: 2039280, owner: mint, rentEpoch: 327 },
pubkey: 'F7e4iBrxoSmHhEzhuBcXXs1KAknYvEoZWieiocPvrCD9'
}
]
}
})

let rentMock = mock({
provider: connection,
blockchain,
request: {
method: 'getMinimumBalanceForRentExemption',
return: 2039280
}
})

let accounts = await connection.getProgramAccounts(new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'), { filters })

expect(requestMock).toHaveBeenCalled()

expect(accounts.map((account)=>account.pubkey.toString())).toEqual([
'3JdKXacGdntfNKXzSGC2EwUDKFPrXdsqowbuc9hEiNBb',
'FjtHL8ki3GXMhCqY2Lum9CCAv5tSQMkhJEnXbEkajTrZ',
'F7e4iBrxoSmHhEzhuBcXXs1KAknYvEoZWieiocPvrCD9'
])
})
})
})
});

0 comments on commit 1d717c8

Please sign in to comment.