-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ipfs-manager): adapt RPC usage with POST methods #871
Changes from all commits
0c31677
405cf63
c45b964
e2b349c
b6c8aad
1eccc21
d5d2652
efddbbe
70ad147
a6a5acf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,9 @@ import { BigNumber } from 'ethers'; | |
|
||
// This contains default values used to use Ethereum Network and IPFS | ||
// if information are not provided by the user | ||
const config: any = { | ||
const config = { | ||
ethereum: { | ||
default: 'private', | ||
default: 'private' as const, | ||
gasPriceDefault: '100000000000', | ||
maxRetries: 5, | ||
nodeUrlDefault: { | ||
|
@@ -22,22 +22,19 @@ const config: any = { | |
defaultNode: { | ||
host: 'localhost', | ||
port: 5001, | ||
protocol: 'http', | ||
protocol: 'http' as StorageTypes.IpfsGatewayProtocol, | ||
timeout: 30000, | ||
}, | ||
errorHandling: { | ||
delayBetweenRetries: 500, | ||
maxRetries: 3, | ||
}, | ||
expectedBootstrapNodes: [ | ||
'/dns4/ipfs-bootstrap.request.network/tcp/4001/ipfs/QmaSrBXFBaupfeGMTuigswtKtsthbVaSonurjTV967Fdxx', | ||
|
||
'/dns4/ipfs-bootstrap-2.request.network/tcp/4001/ipfs/QmYdcSoVNU1axgSnkRAyHtwsKiSvFHXeVvRonGCAV9LVEj', | ||
|
||
'/dns4/ipfs-2.request.network/tcp/4001/ipfs/QmPBPgTDVjveRu6KjGVMYixkCSgGtVyV8aUe6wGQeLZFVd', | ||
|
||
'/dns4/ipfs-survival.request.network/tcp/4001/ipfs/Qmb6a5DH45k8JwLdLVZUhRhv1rnANpsbXjtsH41esGhNCh', | ||
], | ||
expectedBootstrapNodes: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the format of the address changed, this accounts for the change while supporting older format |
||
'ipfs-bootstrap.request.network': 'QmaSrBXFBaupfeGMTuigswtKtsthbVaSonurjTV967Fdxx', | ||
'ipfs-bootstrap-2.request.network': 'QmYdcSoVNU1axgSnkRAyHtwsKiSvFHXeVvRonGCAV9LVEj', | ||
'ipfs-2.request.network': 'QmPBPgTDVjveRu6KjGVMYixkCSgGtVyV8aUe6wGQeLZFVd', | ||
'ipfs-survival.request.network': 'Qmb6a5DH45k8JwLdLVZUhRhv1rnANpsbXjtsH41esGhNCh', | ||
}, | ||
maxIpfsReadRetry: 1, | ||
pinRequest: { | ||
delayBetweenCalls: 1000, | ||
|
@@ -147,10 +144,12 @@ export function getIpfsErrorHandlingConfig(): StorageTypes.IIpfsErrorHandlingCon | |
|
||
/** | ||
* Retrieve from config the ipfs bootstrap nodes of the ipfs node | ||
* @returns array of the swarm addresses | ||
* @returns array of the swarm addresses regexes | ||
*/ | ||
export function getIpfsExpectedBootstrapNodes(): string[] { | ||
return config.ipfs.expectedBootstrapNodes; | ||
export function getIpfsExpectedBootstrapNodes(): RegExp[] { | ||
return Object.entries(config.ipfs.expectedBootstrapNodes).map( | ||
([host, id]) => new RegExp(`/dns4/${host}/tcp/4001/(ipfs|p2p)/${id}`), | ||
); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ const invalidHostIpfsGatewayConnection: StorageTypes.IIpfsGatewayConnection = { | |
host: 'nonexistent', | ||
port: 5001, | ||
protocol: StorageTypes.IpfsGatewayProtocol.HTTP, | ||
timeout: 1000, | ||
timeout: 1500, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure what changed, but without this the test fails... |
||
}; | ||
|
||
const testErrorHandling: StorageTypes.IIpfsErrorHandlingConfiguration = { | ||
|
@@ -76,24 +76,24 @@ describe('Ipfs manager', () => { | |
it('allows to pin one file ipfs', async () => { | ||
await ipfsManager.add(content); | ||
const pinnedHash = await ipfsManager.pin([hash]); | ||
expect(hash).toBe(pinnedHash[0]); | ||
expect(pinnedHash[0]).toBe(hash); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrong order for expect |
||
}); | ||
|
||
it('allows to pin multiple files to ipfs', async () => { | ||
await ipfsManager.add(content); | ||
await ipfsManager.add(content2); | ||
const pinnedHashes = await ipfsManager.pin([hash, hash2]); | ||
expect([hash, hash2]).toMatchObject(pinnedHashes); | ||
expect(pinnedHashes).toMatchObject([hash, hash2]); | ||
}); | ||
|
||
it('allows to read files from ipfs', async () => { | ||
await ipfsManager.add(content); | ||
let contentReturned = await ipfsManager.read(hash, 36); | ||
expect(content).toBe(contentReturned.content); | ||
expect(contentReturned.content).toBe(content); | ||
|
||
await ipfsManager.add(content2); | ||
contentReturned = await ipfsManager.read(hash2); | ||
expect(content2).toBe(contentReturned.content); | ||
expect(contentReturned.content).toBe(content2); | ||
}); | ||
|
||
it('must throw if max size reached', async () => { | ||
|
@@ -108,11 +108,11 @@ describe('Ipfs manager', () => { | |
it('allows to get file size from ipfs', async () => { | ||
await ipfsManager.add(content); | ||
let sizeReturned = await ipfsManager.getContentLength(hash); | ||
expect(contentLengthOnIpfs).toEqual(sizeReturned); | ||
expect(sizeReturned).toEqual(contentLengthOnIpfs); | ||
|
||
await ipfsManager.add(content2); | ||
sizeReturned = await ipfsManager.getContentLength(hash2); | ||
expect(contentLengthOnIpfs2).toEqual(sizeReturned); | ||
expect(sizeReturned).toEqual(contentLengthOnIpfs2); | ||
}); | ||
|
||
it('operations with a invalid host network should throw ENOTFOUND errors', async () => { | ||
|
@@ -146,10 +146,10 @@ describe('Ipfs manager', () => { | |
const axiosInstanceMock = new MockAdapter(axiosInstance); | ||
axiosInstanceMock.onAny().networkError(); | ||
await expect(ipfsManager.read(hash)).rejects.toThrowError('Network Error'); | ||
expect(axiosInstanceMock.history.get.length).toBe(retryTestErrorHandling.maxRetries + 1); | ||
expect(axiosInstanceMock.history.post.length).toBe(retryTestErrorHandling.maxRetries + 1); | ||
}); | ||
|
||
it('timeout errors should not generate any retry', async () => { | ||
it('timeout errors should generate retry', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMPORTANT. We now want to retry on timeout |
||
ipfsManager = new IpfsManager({ | ||
ipfsGatewayConnection: { ...ipfsGatewayConnection, timeout: 1 }, | ||
ipfsErrorHandling: retryTestErrorHandling, | ||
|
@@ -158,8 +158,7 @@ describe('Ipfs manager', () => { | |
const axiosInstanceMock = new MockAdapter(axiosInstance); | ||
axiosInstanceMock.onAny().timeout(); | ||
await expect(ipfsManager.add('test')).rejects.toThrowError('timeout of 1ms exceeded'); | ||
// only one request should have been sent, no retry should happen on timeouts | ||
expect(axiosInstanceMock.history.post.length).toBe(1); | ||
expect(axiosInstanceMock.history.post.length).toBe(retryTestErrorHandling.maxRetries + 1); | ||
}); | ||
|
||
it('added and read files should have the same size and content', async () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated, annying any