Skip to content

Commit 4940106

Browse files
committed
add tests
1 parent 526c1ba commit 4940106

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

lib/xrp/jest.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
roots: ['<rootDir>/test'],
4+
testMatch: ['**/*.test.ts'],
5+
transform: {
6+
'^.+\\.tsx?$': 'ts-jest'
7+
},
8+
setupFiles: [
9+
'dotenv/config'
10+
]
11+
};

lib/xrp/test/.env-test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
AWS_ACCOUNT_ID="xxxxxxxxxxx"
2+
AWS_REGION="xxxxxxxxxx"
3+
XRP_INSTANCE_TYPE="r7a.12xlarge"
4+
XRP_CPU_TYPE="x86_64" # All options: "x86_64". ARM currently not supported
5+
DATA_VOL_TYPE="gp3" # Other options: "io1" | "io2" | "gp3" | "instance-store" . IMPORTANT: Use "instance-store" option only with instance types that support that feature, like popular for node im4gn, d3, i3en, and i4i instance families
6+
DATA_VOL_SIZE="2000" # Current required data size to keep both smapshot archive and unarchived version of it
7+
DATA_VOL_IOPS="12000" # Max IOPS for EBS volumes (not applicable for "instance-store")
8+
DATA_VOL_THROUGHPUT="700"
9+
XRP_HA_ALB_HEALTHCHECK_GRACE_PERIOD_MIN="60"
10+
XRP_HA_NODES_HEARTBEAT_DELAY_MIN="5"
11+
XRP_HA_NUMBER_OF_NODES="2"
12+
HUB_NETWORK_ID="testnet"
13+

lib/xrp/test/common-stack.test.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Template } from "aws-cdk-lib/assertions";
2+
import * as cdk from "aws-cdk-lib";
3+
import * as dotenv from "dotenv";
4+
import * as config from "../lib/config/XRPConfig";
5+
import { XRPCommonStack } from "../lib/common-stack";
6+
7+
dotenv.config({ path: './test/.env-test' });
8+
9+
describe("SolanaCommonStack", () => {
10+
test("synthesizes the way we expect", () => {
11+
const app = new cdk.App();
12+
13+
// Create the SolanaCommonStack.
14+
const xrpCommonStack = new XRPCommonStack(app, "xrp-common", {
15+
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },
16+
stackName: `xrp-nodes-common`,
17+
});
18+
19+
// Prepare the stack for assertions.
20+
const template = Template.fromStack(xrpCommonStack);
21+
22+
// Has EC2 instance role.
23+
template.hasResourceProperties("AWS::IAM::Role", {
24+
AssumeRolePolicyDocument: {
25+
Statement: [
26+
{
27+
Action: "sts:AssumeRole",
28+
Effect: "Allow",
29+
Principal: {
30+
Service: "ec2.amazonaws.com"
31+
}
32+
}
33+
]
34+
},
35+
ManagedPolicyArns: [
36+
{
37+
"Fn::Join": [
38+
"",
39+
[
40+
"arn:",
41+
{
42+
"Ref": "AWS::Partition"
43+
},
44+
":iam::aws:policy/SecretsManagerReadWrite"
45+
]
46+
]
47+
},
48+
{
49+
"Fn::Join": [
50+
"",
51+
[
52+
"arn:",
53+
{
54+
Ref: "AWS::Partition"
55+
},
56+
":iam::aws:policy/AmazonSSMManagedInstanceCore"
57+
]
58+
]
59+
},
60+
{
61+
"Fn::Join": [
62+
"",
63+
[
64+
"arn:",
65+
{
66+
"Ref": "AWS::Partition"
67+
},
68+
":iam::aws:policy/CloudWatchAgentServerPolicy"
69+
]
70+
]
71+
}
72+
]
73+
})
74+
75+
});
76+
});
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import { Match, Template } from "aws-cdk-lib/assertions";
2+
import * as cdk from "aws-cdk-lib";
3+
import * as dotenv from "dotenv";
4+
import * as config from "../lib/config/XRPConfig";
5+
import { XRPCommonStack } from "../lib/common-stack";
6+
import { XRPSingleNodeStack } from "../lib/single-node-stack";
7+
8+
dotenv.config({ path: './test/.env-test' });
9+
10+
describe("SolanaSingleNodeStack", () => {
11+
test("synthesizes the way we expect", () => {
12+
const app = new cdk.App();
13+
const xrpCommonStack = new XRPCommonStack(app, "xrp-common", {
14+
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },
15+
stackName: `xrp-nodes-common`,
16+
});
17+
18+
// Create the XRPSingleNodeStack.
19+
const xrpSingleNodeStack = new XRPSingleNodeStack(app, "XRP-sync-node", {
20+
env: { account: config.baseConfig.accountId, region: config.baseConfig.region },
21+
stackName: `XRP-single-node`,
22+
instanceType: config.baseNodeConfig.instanceType,
23+
instanceCpuType: config.baseNodeConfig.instanceCpuType,
24+
dataVolume: config.baseNodeConfig.dataVolume,
25+
hubNetworkID: config.baseNodeConfig.hubNetworkID,
26+
instanceRole: xrpCommonStack.instanceRole,
27+
});
28+
29+
// Prepare the stack for assertions.
30+
const template = Template.fromStack(xrpSingleNodeStack);
31+
32+
// Has EC2 instance security group.
33+
template.hasResourceProperties("AWS::EC2::SecurityGroup", {
34+
GroupDescription: Match.anyValue(),
35+
VpcId: Match.anyValue(),
36+
SecurityGroupEgress: [
37+
{
38+
"CidrIp": "0.0.0.0/0",
39+
"Description": "Allow all outbound traffic by default",
40+
"IpProtocol": "-1"
41+
}
42+
],
43+
SecurityGroupIngress: [
44+
{
45+
"CidrIp": "0.0.0.0/0",
46+
"Description": "P2P protocols",
47+
"FromPort": 51235,
48+
"IpProtocol": "tcp",
49+
"ToPort": 51235
50+
},
51+
{
52+
"CidrIp": "0.0.0.0/0",
53+
"Description": "P2P protocols",
54+
"FromPort": 2459,
55+
"IpProtocol": "tcp",
56+
"ToPort": 2459
57+
},
58+
{
59+
"CidrIp": "1.2.3.4/5",
60+
"Description": "RPC port HTTP (user access needs to be restricted. Allowed access only from internal IPs)",
61+
"FromPort": 6005,
62+
"IpProtocol": "tcp",
63+
"ToPort": 6005
64+
}
65+
]
66+
})
67+
68+
// Has EC2 instance with node configuration
69+
template.hasResourceProperties("AWS::EC2::Instance", {
70+
AvailabilityZone: Match.anyValue(),
71+
UserData: Match.anyValue(),
72+
BlockDeviceMappings: [
73+
{
74+
DeviceName: "/dev/xvda",
75+
Ebs: {
76+
DeleteOnTermination: true,
77+
Encrypted: true,
78+
Iops: 3000,
79+
VolumeSize: 46,
80+
VolumeType: "gp3"
81+
}
82+
}
83+
],
84+
IamInstanceProfile: Match.anyValue(),
85+
ImageId: Match.anyValue(),
86+
InstanceType: "r7a.12xlarge",
87+
Monitoring: true,
88+
PropagateTagsToVolumeOnCreation: true,
89+
SecurityGroupIds: Match.anyValue(),
90+
SubnetId: Match.anyValue(),
91+
})
92+
93+
// Has EBS data volume.
94+
template.hasResourceProperties("AWS::EC2::Volume", {
95+
AvailabilityZone: Match.anyValue(),
96+
Encrypted: true,
97+
Iops: 12000,
98+
MultiAttachEnabled: false,
99+
Size: 2000,
100+
Throughput: 700,
101+
VolumeType: "gp3"
102+
})
103+
104+
// Has EBS data volume attachment.
105+
template.hasResourceProperties("AWS::EC2::VolumeAttachment", {
106+
Device: "/dev/sdf",
107+
InstanceId: Match.anyValue(),
108+
VolumeId: Match.anyValue(),
109+
})
110+
111+
// Has CloudWatch dashboard.
112+
template.hasResourceProperties("AWS::CloudWatch::Dashboard", {
113+
DashboardBody: Match.anyValue(),
114+
DashboardName: {"Fn::Join": ["", ["XRP-single-node-",{ "Ref": Match.anyValue() }]]}
115+
})
116+
117+
});
118+
});

0 commit comments

Comments
 (0)