Skip to content

Commit a7b45de

Browse files
robot-uxdevinxl
andauthored
feat: Enhance GNFD module with payment account management (#5)
* feat: Enhance GNFD services with payment account management * feat: Add gnfd store fee calculation method (#8) * feat: Add get_bucket_quota, get_bucket_full_info and payment_account_related_buckets * feat: Add netflowRate calculation function * refactor: Update GNFD tests and services for improved functionality * feat: Add 'gnfd_get_bucket_full_info' tool and update README with new payment account methods * feat: Update package.json for e2e testing and enhance README with ERC1155 metadata description --------- Co-authored-by: devinxl <devin@nodereal.io>
1 parent 73ff94a commit a7b45de

30 files changed

Lines changed: 1122 additions & 393 deletions

README.md

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,32 @@ bun run test
219219
| get_erc20_balance | Get ERC20 token balance for an address |
220220
| get_nft_info | Get detailed information about a specific NFT |
221221
| check_nft_ownership | Check if an address owns a specific NFT |
222-
| get_erc1155_token_uri | Get the metadata URI for an ERC1155 token |
222+
| get_erc1155_token_metadata | Get the metadata for an ERC1155 token |
223223
| get_nft_balance | Get the total number of NFTs owned by an address from a specific collection |
224224
| get_erc1155_balance | Get the balance of a specific ERC1155 token ID owned by an address |
225-
| gnfd_get_bucket_info | Get detailed information about a specific bucket |
226-
| gnfd_list_buckets | List all buckets owned by an address |
227-
| gnfd_create_bucket | Create a new bucket |
228-
| gnfd_delete_bucket | Delete a bucket |
229-
| gnfd_get_object_info | Get detailed information about a specific object |
230-
| gnfd_list_objects | List all objects in a bucket |
231-
| gnfd_upload_object | Upload an object to a bucket |
232-
| gnfd_download_object | Download an object from a bucket |
233-
| gnfd_delete_object | Delete an object from a bucket |
234-
| gnfd_create_folder | Create a folder in a bucket |
225+
226+
### Greenfield tools
227+
228+
| Name | Description |
229+
| ----------------------------- | --------------------------------------------------- |
230+
| gnfd_get_bucket_info | Get detailed information about a specific bucket |
231+
| gnfd_list_buckets | List all buckets owned by an address |
232+
| gnfd_create_bucket | Create a new bucket |
233+
| gnfd_delete_bucket | Delete a bucket |
234+
| gnfd_get_object_info | Get detailed information about a specific object |
235+
| gnfd_list_objects | List all objects in a bucket |
236+
| gnfd_upload_object | Upload an object to a bucket |
237+
| gnfd_download_object | Download an object from a bucket |
238+
| gnfd_delete_object | Delete an object from a bucket |
239+
| gnfd_create_folder | Create a folder in a bucket |
240+
| gnfd_get_account_balance | Get the balance for an account |
241+
| gnfd_deposit_to_payment | Deposit funds into a payment account |
242+
| gnfd_withdraw_from_payment | Withdraw funds from a payment account |
243+
| gnfd_disable_refund | Disable refund for a payment account (IRREVERSIBLE) |
244+
| gnfd_get_payment_accounts | List all payment accounts owned by an address |
245+
| gnfd_get_payment_account_info | Get detailed information about a payment account |
246+
| gnfd_create_payment | Create a new payment account |
247+
| gnfd_get_payment_balance | Get payment account balance |
235248

236249
## Supported Networks
237250

bun.lockb

788 Bytes
Binary file not shown.

e2e/evm/ens.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ import { getClient, parseText } from "../util"
55
describe("EVM ENS Test", async () => {
66
const client = await getClient()
77

8-
it("resolve ETH ENS name", async () => {
9-
const res = await client.callTool({
10-
name: "resolve_ens",
11-
arguments: {
12-
ensName: "vitalik.eth",
13-
network: "eth" // only for eth mainnet
14-
}
15-
})
16-
const text = res.content?.[0]?.text
17-
const obj = parseText<{
18-
resolvedAddress: string
19-
}>(text)
20-
expect(obj.resolvedAddress).toStartWith("0x")
21-
})
8+
// it("resolve ETH ENS name", async () => {
9+
// const res = await client.callTool({
10+
// name: "resolve_ens",
11+
// arguments: {
12+
// ensName: "vitalik.eth",
13+
// network: "eth" // only for eth mainnet
14+
// }
15+
// })
16+
// const text = res.content?.[0]?.text
17+
// const obj = parseText<{
18+
// resolvedAddress: string
19+
// }>(text)
20+
// expect(obj.resolvedAddress).toStartWith("0x")
21+
// })
2222
})

e2e/evm/network.test.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,48 +19,6 @@ describe("EVM Network Test", async () => {
1919
expect(obj.chainId).toBe(56) // BSC mainnet chain ID
2020
})
2121

22-
it("get chain info for BSC testnet", async () => {
23-
const res = await client.callTool({
24-
name: "get_chain_info",
25-
arguments: {
26-
network: "bsc-testnet"
27-
}
28-
})
29-
const text = res.content?.[0]?.text
30-
const obj = parseText<{
31-
chainId: number
32-
}>(text)
33-
expect(obj.chainId).toBe(97) // BSC testnet chain ID
34-
})
35-
36-
it("get chain info for opBNB", async () => {
37-
const res = await client.callTool({
38-
name: "get_chain_info",
39-
arguments: {
40-
network: "opbnb"
41-
}
42-
})
43-
const text = res.content?.[0]?.text
44-
const obj = parseText<{
45-
chainId: number
46-
}>(text)
47-
expect(obj.chainId).toBe(204) // opBNB mainnet chain ID
48-
})
49-
50-
it("get chain info for opBNB testnet", async () => {
51-
const res = await client.callTool({
52-
name: "get_chain_info",
53-
arguments: {
54-
network: "opbnb-testnet"
55-
}
56-
})
57-
const text = res.content?.[0]?.text
58-
const obj = parseText<{
59-
chainId: number
60-
}>(text)
61-
expect(obj.chainId).toBe(5611) // opBNB testnet chain ID
62-
})
63-
6422
it("get supported networks", async () => {
6523
const res = await client.callTool({
6624
name: "get_supported_networks",

e2e/evm/nft.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("EVM NFT Test", async () => {
3434
describe("ERC1155 Tests", () => {
3535
it("get ERC1155 token URI", async () => {
3636
const res = await client.callTool({
37-
name: "get_erc1155_token_uri",
37+
name: "get_erc1155_token_metadata",
3838
arguments: {
3939
tokenAddress: ERC1155_ADDRESS,
4040
tokenId: ERC1155_TOKEN_ID,

e2e/evm/transactions.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ describe("EVM Transactions Test", async () => {
2424
expect(obj.blockHash).toStartWith("0x")
2525
})
2626

27-
it("get transaction receipt", async () => {
28-
const res = await client.callTool({
29-
name: "get_transaction_receipt",
30-
arguments: {
31-
txHash: TX_HASH,
32-
network: "bsc"
33-
}
34-
})
35-
const text = res.content?.[0]?.text
36-
const obj = parseText<{
37-
blockHash: string
38-
}>(text)
39-
expect(obj.blockHash).toStartWith("0x")
40-
})
27+
// it("get transaction receipt", async () => {
28+
// const res = await client.callTool({
29+
// name: "get_transaction_receipt",
30+
// arguments: {
31+
// txHash: TX_HASH,
32+
// network: "bsc"
33+
// }
34+
// })
35+
// const text = res.content?.[0]?.text
36+
// const obj = parseText<{
37+
// blockHash: string
38+
// }>(text)
39+
// expect(obj.blockHash).toStartWith("0x")
40+
// })
4141

4242
it("estimate gas", async () => {
4343
const res = await client.callTool({

e2e/gnfd/account.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ describe("Greenfield Account Test", async () => {
99
const res = await client.callTool({
1010
name: "gnfd_get_account_balance",
1111
arguments: {
12-
network: "mainnet"
12+
network: "testnet"
1313
}
1414
})
1515
const text = res.content?.[0]?.text
1616
const obj = parseText<{
17-
balance: {
18-
amount: string
19-
denom: string
20-
}
17+
denom: string
2118
}>(text)
22-
expect(BigInt(obj.balance.amount)).toBeTypeOf("bigint")
19+
expect(obj.denom).toBe("BNB")
2320
})
2421

2522
it("get all storage providers", async () => {
2623
const res = await client.callTool({
2724
name: "gnfd_get_all_sps",
2825
arguments: {
29-
network: "mainnet"
26+
network: "testnet"
3027
}
3128
})
3229
const text = res.content?.[0]?.text

e2e/gnfd/payment.test.ts

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
import { describe, expect, it } from "bun:test"
2+
3+
import { getClient, parseText } from "../util"
4+
5+
const _getPaymentAccountAddress = async () => {
6+
const client = await getClient()
7+
8+
const paymentAccountsRes = await client.callTool({
9+
name: "gnfd_get_payment_accounts",
10+
arguments: {
11+
network: "testnet"
12+
}
13+
})
14+
const paymentAccount = parseText<string[]>(
15+
paymentAccountsRes.content?.[0]?.text
16+
)
17+
const paymentAccountAddress = paymentAccount[0]
18+
return paymentAccountAddress
19+
}
20+
21+
const _createPaymentAccount = async () => {
22+
const client = await getClient()
23+
const res = await client.callTool({
24+
name: "gnfd_create_payment_account",
25+
arguments: {
26+
network: "testnet"
27+
}
28+
})
29+
const text = res.content?.[0]?.text
30+
const obj = parseText<{
31+
status: string
32+
}>(text)
33+
34+
return obj.status
35+
}
36+
37+
const _getPaymentAccountInfo = async () => {
38+
const client = await getClient()
39+
const paymentAccountAddress = await _getPaymentAccountAddress()
40+
const res = await client.callTool({
41+
name: "gnfd_get_payment_account_info",
42+
arguments: {
43+
network: "testnet",
44+
paymentAddress: paymentAccountAddress
45+
}
46+
})
47+
const text = res.content?.[0]?.text
48+
const obj = parseText<{
49+
status: string
50+
data: {
51+
refundable: boolean
52+
}
53+
}>(text)
54+
55+
return obj
56+
}
57+
58+
describe("Greenfield Payment Test", async () => {
59+
const client = await getClient()
60+
let paymentAccountAddress = await _getPaymentAccountAddress()
61+
if (!paymentAccountAddress) {
62+
await _createPaymentAccount()
63+
paymentAccountAddress = await _getPaymentAccountAddress()
64+
}
65+
66+
it("get payment accounts", async () => {
67+
const res = await client.callTool({
68+
name: "gnfd_get_payment_accounts",
69+
arguments: {
70+
network: "testnet"
71+
}
72+
})
73+
const text = res.content?.[0]?.text
74+
const obj = parseText<string[]>(text)
75+
expect(obj.length).toBeGreaterThan(0)
76+
})
77+
78+
it("deposit to payment account", async () => {
79+
const res = await client.callTool({
80+
name: "gnfd_deposit_to_payment",
81+
arguments: {
82+
network: "testnet",
83+
to: paymentAccountAddress, // Example address
84+
amount: "0.01"
85+
}
86+
})
87+
const text = res.content?.[0]?.text
88+
const obj = parseText<{
89+
status: string
90+
}>(text)
91+
expect(obj.status).toBe("success")
92+
})
93+
94+
it("get payment account info", async () => {
95+
const obj = await _getPaymentAccountInfo()
96+
97+
expect(obj.status).toBe("success")
98+
})
99+
100+
it("withdraw from payment account", async () => {
101+
const accountInfo = await _getPaymentAccountInfo()
102+
const res = await client.callTool({
103+
name: "gnfd_withdraw_from_payment",
104+
arguments: {
105+
network: "testnet",
106+
from: paymentAccountAddress, // Example address
107+
amount: "0.01"
108+
}
109+
})
110+
const text = res.content?.[0]?.text
111+
const obj = parseText<{
112+
status: string
113+
}>(text)
114+
expect(obj.status).toBe(accountInfo.data.refundable ? "success" : "error")
115+
})
116+
117+
// it("disable refund for payment account", async () => {
118+
// const res = await client.callTool({
119+
// name: "gnfd_disable_refund",
120+
// arguments: {
121+
// network: "testnet",
122+
// address: paymentAccountAddress
123+
// }
124+
// })
125+
// const text = res.content?.[0]?.text
126+
// const obj = parseText<{
127+
// status: string
128+
// }>(text)
129+
// expect(obj.status).toBe("success")
130+
// })
131+
132+
// it("get payment account related buckets", async () => {
133+
// const res = await client.callTool({
134+
// name: "gnfd_get_payment_account_related_buckets",
135+
// arguments: {
136+
// network: "testnet",
137+
// paymentAddress: paymentAccountAddress
138+
// }
139+
// })
140+
// const text = res.content?.[0]?.text
141+
// const obj = parseText<{
142+
// status: string
143+
// data: any
144+
// }>(text)
145+
146+
// console.log("payment account related buckets", obj.data)
147+
// expect(obj.status).toBe("success")
148+
// })
149+
})

0 commit comments

Comments
 (0)