Skip to content

Commit

Permalink
[Codegen]: Refactor codegen-v1 to allow to generate mobile tests only
Browse files Browse the repository at this point in the history
  • Loading branch information
satoshiotomakan committed Nov 23, 2023
1 parent b6831b5 commit d9a9694
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 24 deletions.
2 changes: 1 addition & 1 deletion codegen/bin/newcoin
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ end

coin_id = command_line_args[0]

generate_skeleton(coin_id, "")
generate_skeleton(coin_id, "full")
22 changes: 22 additions & 0 deletions codegen/bin/newcoin-mobile-tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env ruby

# Sript for creating new skeleton files for new coin mobile tests. See also `newcoin` or `newevmchain`.
# It is considered to be used by codegen-v2 tool until Swift and Android tests generating supported.
# 1. Add relevant entry to registry.json (in order to minimize merge conflict, don't add at the very end)
# 2. Invoke this script with the id of the coin, e.g.: codegen/bin/newcoin-mobile-tests ethereum

require 'fileutils'

CurrentDir = File.dirname(__FILE__)
$LOAD_PATH.unshift(File.join(CurrentDir, '..', 'lib'))
require 'coin_skeleton_gen'

command_line_args = ARGV
if command_line_args.length < 1
puts "Usage: newcoin-mobile-tests <new_coin_id>"
return
end

coin_id = command_line_args[0]

generate_skeleton(coin_id, "mobile-tests")
63 changes: 40 additions & 23 deletions codegen/lib/coin_skeleton_gen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,36 @@ def self.insert_target_line(target_file, target_line, original_line)
return true
end

def generate_blockchain_files(coin)
name = format_name(coin)

generate_file("newcoin/Address.h.erb", "src/#{name}", "Address.h", coin)
generate_file("newcoin/Address.cpp.erb", "src/#{name}", "Address.cpp", coin)
generate_file("newcoin/Entry.h.erb", "src/#{name}", "Entry.h", coin)
generate_file("newcoin/Entry.cpp.erb", "src/#{name}", "Entry.cpp", coin)
generate_file("newcoin/Proto.erb", "src/proto", "#{name}.proto", coin)
generate_file("newcoin/Signer.h.erb", "src/#{name}", "Signer.h", coin)
generate_file("newcoin/Signer.cpp.erb", "src/#{name}", "Signer.cpp", coin)

generate_file("newcoin/AddressTests.cpp.erb", "tests/chains/#{name}", "AddressTests.cpp", coin)
generate_file("newcoin/SignerTests.cpp.erb", "tests/chains/#{name}", "SignerTests.cpp", coin)
generate_file("newcoin/TransactionCompilerTests.cpp.erb", "tests/chains/#{name}", "TransactionCompilerTests.cpp", coin)
generate_file("newcoin/TWAddressTests.cpp.erb", "tests/chains/#{name}", "TWAnyAddressTests.cpp", coin)
generate_file("newcoin/TWSignerTests.cpp.erb", "tests/chains/#{name}", "TWAnySignerTests.cpp", coin)
end

def generate_mobile_tests(coin)
name = format_name(coin)

generate_file("newcoin/AddressTests.kt.erb", "android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/#{format_name_lowercase(coin)}", "Test#{name}Address.kt", coin)
generate_file("newcoin/SignerTests.kt.erb", "android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/#{format_name_lowercase(coin)}", "Test#{name}Signer.kt", coin)
generate_file("newcoin/Tests.swift.erb", "swift/Tests/Blockchains", "#{name}Tests.swift", coin)
end

def generate_coin_type_tests(coin)
coin_test_gen.generate_coin_test_file(coin, 'TWCoinTypeTests.cpp.erb', true)
end

def generate_skeleton(coin_id, mode)
puts "New coin template for coin '#{coin_id}' #{mode} requested"

Expand All @@ -112,32 +142,19 @@ def generate_skeleton(coin_id, mode)
return
end
coin = coinSelect.first
name = format_name(coin)


insert_coin_type(coin, mode)
if (mode != "evm")
if (mode == "full")
insert_coin_type(coin, mode)
insert_coin_entry(coin)

generate_file("newcoin/Address.h.erb", "src/#{name}", "Address.h", coin)
generate_file("newcoin/Address.cpp.erb", "src/#{name}", "Address.cpp", coin)
generate_file("newcoin/Entry.h.erb", "src/#{name}", "Entry.h", coin)
generate_file("newcoin/Entry.cpp.erb", "src/#{name}", "Entry.cpp", coin)
generate_file("newcoin/Proto.erb", "src/proto", "#{name}.proto", coin)
generate_file("newcoin/Signer.h.erb", "src/#{name}", "Signer.h", coin)
generate_file("newcoin/Signer.cpp.erb", "src/#{name}", "Signer.cpp", coin)

generate_file("newcoin/AddressTests.cpp.erb", "tests/chains/#{name}", "AddressTests.cpp", coin)
generate_file("newcoin/SignerTests.cpp.erb", "tests/chains/#{name}", "SignerTests.cpp", coin)
generate_file("newcoin/TransactionCompilerTests.cpp.erb", "tests/chains/#{name}", "TransactionCompilerTests.cpp", coin)
generate_file("newcoin/TWAddressTests.cpp.erb", "tests/chains/#{name}", "TWAnyAddressTests.cpp", coin)
generate_file("newcoin/TWSignerTests.cpp.erb", "tests/chains/#{name}", "TWAnySignerTests.cpp", coin)
generate_file("newcoin/AddressTests.kt.erb", "android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/#{format_name_lowercase(coin)}", "Test#{name}Address.kt", coin)
generate_file("newcoin/SignerTests.kt.erb", "android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/#{format_name_lowercase(coin)}", "Test#{name}Signer.kt", coin)
generate_file("newcoin/Tests.swift.erb", "swift/Tests/Blockchains", "#{name}Tests.swift", coin)
generate_blockchain_files(coin)
generate_mobile_tests(coin)
generate_coin_type_tests(coin)
elsif (mode == "evm")
insert_coin_type(coin, mode)
generate_coin_type_tests(coin)
elsif (mode == "mobile-tests")
generate_mobile_tests(coin)
end

coin_test_gen.generate_coin_test_file(coin, 'TWCoinTypeTests.cpp.erb', true)

puts "please tools/generate-files to generate Swift/Java/Protobuf files"
end

0 comments on commit d9a9694

Please sign in to comment.