forked from valyakin/aa-testkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaa_response.feature.spec.js
137 lines (109 loc) · 4.6 KB
/
aa_response.feature.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const { Testkit } = require('../../main')
const { Network } = Testkit()
const { bouncingAa, dataFeedAa } = require('./agents')
describe('Check receiving AA response feature', function () {
this.timeout(120000)
before(async () => {
this.network = await Network.create().run()
this.genesis = await this.network.getGenesisNode().ready()
this.deployer = await this.network.newHeadlessWallet().ready()
this.wallet = await this.network.newHeadlessWallet().ready()
const deployerAddress = await this.deployer.getAddress()
const { unit, error } = await this.genesis.sendBytes({ toAddress: deployerAddress, amount: 1e9 })
expect(error).to.be.null
expect(unit).to.be.validUnit
await this.network.witnessUntilStable(unit)
})
it('Deploy bouncing Agent', async () => {
const { address: agentAddress, unit: agentUnit, error: deploymentError } = await this.deployer.deployAgent(bouncingAa)
expect(agentAddress).to.be.validAddress
expect(agentUnit).to.be.validUnit
expect(deploymentError).to.be.null
this.bouncingAgentAddress = agentAddress
await this.network.witnessUntilStable(agentUnit)
}).timeout(15000)
it('Deploy data feed Agent', async () => {
const { address: agentAddress, unit: agentUnit, error: deploymentError } = await this.deployer.deployAgent(dataFeedAa)
expect(agentAddress).to.be.validAddress
expect(agentUnit).to.be.validUnit
expect(deploymentError).to.be.null
this.dataFeedAgentAddress = agentAddress
await this.network.witnessUntilStable(agentUnit)
}).timeout(15000)
it('Send money to wallet', async () => {
const walletAddress = await this.wallet.getAddress()
const { unit, error } = await this.genesis.sendBytes({ toAddress: walletAddress, amount: 1e9 })
expect(error).to.be.null
expect(unit).to.be.validUnit
await this.network.witnessUntilStable(unit)
}).timeout(10000)
it('Trigger bouncing AA not enough fees', async () => {
const { unit, error } = await this.wallet.triggerAaWithData({
toAddress: this.bouncingAgentAddress,
amount: 100,
data: {
bounceMessage: 'BOUNCED!',
},
})
expect(error).to.be.string('The amounts are less than bounce fees')
expect(unit).to.be.null
await this.network.witnessUntilStable(unit)
}).timeout(10000)
it('Trigger bouncing AA', async () => {
const { unit, error } = await this.wallet.triggerAaWithData({
toAddress: this.bouncingAgentAddress,
amount: 10000,
data: {
bounceMessage: 'BOUNCED!',
},
})
expect(error).to.be.null
expect(unit).to.be.validUnit
await this.network.witnessUntilStable(unit)
const { response } = await this.network.getAaResponseToUnit(unit)
expect(response.response.error).to.be.string('Bounce with message BOUNCED!')
}).timeout(10000)
it('Trigger data feed AA without data', async () => {
const { unit, error } = await this.wallet.triggerAaWithData({
toAddress: this.dataFeedAgentAddress,
amount: 10000,
data: {
notDataFeedPayload: '123',
},
})
expect(error).to.be.null
expect(unit).to.be.validUnit
await this.network.witnessUntilStable(unit)
const { response: triggerResponse } = await this.network.getAaResponseToUnit(unit)
expect(triggerResponse.bounced).to.be.false
expect(triggerResponse.response.responseVars.dataFeedAaResponse).to.be.string('aa response!')
const aaResponseUnit = triggerResponse.response_unit
const { unitObj, error: aaResponseUnitError } = await this.wallet.getUnitInfo({ unit: aaResponseUnit })
expect(aaResponseUnitError).to.be.null
const dataFeedMessage = unitObj.messages.find(e => e.app === 'data_feed')
expect(dataFeedMessage.payload.dataFeedPayload).to.be.string('no datafeed provided')
}).timeout(20000)
it('Trigger data feed AA with data', async () => {
const { unit, error } = await this.wallet.triggerAaWithData({
toAddress: this.dataFeedAgentAddress,
amount: 10000,
data: {
dataFeedPayload: 'this will be a datafeed',
},
})
expect(error).to.be.null
expect(unit).to.be.validUnit
await this.network.witnessUntilStable(unit)
const { response: triggerResponse } = await this.network.getAaResponseToUnit(unit)
expect(triggerResponse.bounced).to.be.false
expect(triggerResponse.response.responseVars.dataFeedAaResponse).to.be.string('aa response!')
const aaResponseUnit = triggerResponse.response_unit
const { unitObj, error: aaResponseUnitError } = await this.wallet.getUnitInfo({ unit: aaResponseUnit })
expect(aaResponseUnitError).to.be.null
const dataFeedMessage = unitObj.messages.find(e => e.app === 'data_feed')
expect(dataFeedMessage.payload.dataFeedPayload).to.be.string('this will be a datafeed')
}).timeout(20000)
after(async () => {
await this.network.stop()
})
})