~singpolyma/sgx-jmp

ref: d799a928330b0a8709084e8ea6a431979949a37e sgx-jmp/test/test_helper.rb -rw-r--r-- 2.3 KiB
d799a928Stephen Paul Weber Ask electrum to notify on new BTC addresses 1 year, 14 days ago
                                                                                
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
138
139
# frozen_string_literal: true

require "simplecov"
SimpleCov.start do
	add_filter "/test/"
	enable_coverage :branch
end

require "em_promise"
require "fiber"
require "minitest/autorun"
require "rantly/minitest_extensions"
require "webmock/minitest"
begin
	require "pry-rescue/minitest"
	require "pry-reload"

	module Minitest
		class Test
			alias old_capture_exceptions capture_exceptions
			def capture_exceptions
				old_capture_exceptions do
					yield
				rescue Minitest::Skip => e
					failures << e
				end
			end
		end
	end
rescue LoadError
	# Just helpers for dev, no big deal if missing
	nil
end

require "backend_sgx"

CONFIG = {
	sgx: "sgx",
	component: {
		jid: "component"
	},
	creds: {
		account: "test_bw_account",
		username: "test_bw_user",
		password: "test_bw_password"
	},
	catapult: {
		user: "catapult_user",
		token: "catapult_token",
		secret: "catapult_secret",
		domain: "catapult_domain",
		sip_host: "host.bwapp.io.example.com",
		application_id: "catapult_app"
	},
	activation_amount: 1,
	plans: [
		{
			name: "test_usd",
			currency: :USD,
			monthly_price: 10000
		},
		{
			name: "test_bad_currency",
			currency: :BAD
		},
		{
			name: "test_cad",
			currency: :CAD,
			monthly_price: 10000
		}
	],
	braintree: {
		merchant_accounts: {
			USD: "merchant_usd"
		}
	},
	credit_card_url: ->(*) { "http://creditcard.example.com" },
	electrum_notify_url: ->(*) { "http://notify.example.com" }
}.freeze

BLATHER = Class.new {
	def <<(*); end
}.new.freeze

class Matching
	def initialize(&block)
		@block = block
	end

	def ===(other)
		@block.call(other)
	end
end

class PromiseMock < Minitest::Mock
	def then(succ=nil, _=nil)
		if succ
			succ.call(self)
		else
			yield self
		end
	end
end

module EventMachine
	class << self
		# Patch EM.add_timer to be instant in tests
		alias old_add_timer add_timer
		def add_timer(*args, &block)
			args[0] = 0
			old_add_timer(*args, &block)
		end
	end
end

module Minitest
	class Test
		def self.property(m, &block)
			define_method("test_#{m}") do
				property_of(&block).check { |args| send(m, *args) }
			end
		end

		def self.em(m)
			alias_method "raw_#{m}", m
			define_method(m) do
				EM.run do
					Fiber.new {
						begin
							send("raw_#{m}")
						ensure
							EM.stop
						end
					}.resume
				end
			end
		end
	end
end